def chip(size, A, B, C, D, E, F, G): result = KiCad.Module() linewidth = 0.2 result.fields[0].text = "CHIP-{0}".format(size) result.fields[0].y = -mm( G/2 + 0.5 ) # Draw the component outline result.addDrawing( KiCad.DrawRectangle( size = ( mm(F), mm(G) ), lwidth = mm(linewidth), layer = KiCad.Const.LAYER_TOP_SILK ) ) p1 = KiCad.Pad( position = ( -mm( (A-C)/2 ), 0 ), size = ( mm(C), mm(D) ), number = 1, orientation = KiCad.Const.ORIENTATION_0DEG, shape = KiCad.Const.SHAPE_RECTANGLE, padtype = KiCad.Const.PADTYPE_SMD ) p2 = KiCad.Pad( position = ( mm( (A-C)/2 ), 0 ), size = ( mm(C), mm(D) ), number = 2, orientation = KiCad.Const.ORIENTATION_0DEG, shape = KiCad.Const.SHAPE_RECTANGLE, padtype = KiCad.Const.PADTYPE_SMD ) result.addPad(p1) result.addPad(p2) return result
def soic(pins, bodysize, pitch): """ @param bodysize is a tuple! """ result = KiCad.Module() result.fields[0].text = "SOIC{0}-{1}x{2}-{3}".format(str(pins), str(bodysize[0]), str(bodysize[1]), str(pitch)) result.fields[0].y = -mm(2) result.fields[0].visible = KiCad.Const.FIELDVIS_INVISIBLE # A line width (in mm) linewidth = 0.2 # Mark the body outline (centred at 0,0) result.addDrawing( KiCad.DrawRectangle( size=(mm(bodysize[0]), mm(bodysize[1])), lwidth=mm(linewidth), layer=KiCad.Const.LAYER_TOP_SILK ) ) # Generate a pad size suitable for this device. Limit the maximum pad size # vertically padsizex = mm(1) padsizey = mm(pitch - 0.2) if padsizey > 0.65: padsizey = 0.65 pin_number = 1 # Side one starty = 0 - mm((((pins / 2) - 1) * pitch) / 2) startx = 0 - mm((bodysize[0] / 2) + 1) while pin_number <= ((pins / 2) * 1): p = KiCad.Pad( position=(startx, starty + mm((pin_number - 1) * pitch)), size=(padsizex, padsizey), number=pin_number, orientation=KiCad.Const.ORIENTATION_0DEG, shape=KiCad.Const.SHAPE_RECTANGLE, padtype=KiCad.Const.PADTYPE_SMD, ) result.addPad(p) pin_number += 1 # Mark Pin 1 with a rectangle (would be better to be small arrow head) result.addDrawing( KiCad.DrawRectangle( centre=(0 - mm((bodysize[0] / 2) - 0.35), starty), size=(mm(0.2), mm(0.2)), lwidth=mm(linewidth), layer=KiCad.Const.LAYER_TOP_SILK, ) ) # Side two startx = mm((bodysize[0] / 2) + 1) starty = mm((((pins / 2) - 1) * pitch) / 2) while pin_number <= ((pins / 2) * 2): p = KiCad.Pad( position=(startx, starty - mm(((pin_number - ((pins / 2) * 1)) - 1) * pitch)), size=(padsizex, padsizey), number=pin_number, orientation=KiCad.Const.ORIENTATION_90DEG, shape=KiCad.Const.SHAPE_RECTANGLE, padtype=KiCad.Const.PADTYPE_SMD, ) result.addPad(p) pin_number += 1 return result
def qfp(pins_in, bodysize, pitch): """ Pass a simple int to pins if all sides are equal. If sides are not equal, pass a tuple of length two for pins listing the number of pins on each side of the device. Bodysize should be a tuple of length 2, in the form (x, y) The pitch is a float giving the pitch of the pins in mm """ # Test to see if all sides are the same size, or if there are different # pin counts for the x and y sides if isinstance(pins_in, tuple): pins = pins_in else: pins = (pins_in / 4, pins_in / 4) # Work out the total package pincount from the four sides (2x and 2y) pincount = (pins[0] * 2) + (pins[1] * 2) # Insantiate a module and set it's name according to the current naming # convention result = KiCad.Module() result.fields[0].text = "QFP{0}-{1}x{2}-{3}".format(str(pincount), str(bodysize[0]), str(bodysize[1]), str(pitch)) result.fields[0].y = -mm(2) result.fields[0].visible = KiCad.Const.FIELDVIS_INVISIBLE # A line width (in mm) which can be used to draw on the silk screen layer linewidth = 0.2 # Mark the body outline (centred at 0,0) result.addDrawing( KiCad.DrawRectangle( size=(mm(bodysize[0]), mm(bodysize[1])), lwidth=mm(linewidth), layer=KiCad.Const.LAYER_TOP_SILK ) ) # Setup the pad sizes padsizex = mm(pitch - 0.2) padsizey = mm(1) # Limit the width of a pad... if padsizex > mm(0.6): padsizex = mm(0.6) # Add pins for the bottom row (starting at pin 1) pin_number = 1 # Side one startx = 0 - mm(((pins[0] - 1) * pitch) / 2) starty = mm((bodysize[1] / 2) + 0.75) while pin_number <= (pins[0]): p = KiCad.Pad( position=(startx + mm((pin_number - 1) * pitch), starty), size=(padsizex, padsizey), number=pin_number, orientation=KiCad.Const.ORIENTATION_0DEG, shape=KiCad.Const.SHAPE_RECTANGLE, padtype=KiCad.Const.PADTYPE_SMD, ) result.addPad(p) pin_number += 1 # Mark Pin 1 with a rectangle (would be better to be small arrow head) result.addDrawing( KiCad.DrawRectangle( centre=(startx, mm((bodysize[1] / 2) - 0.35)), size=(mm(0.2), mm(0.2)), lwidth=mm(linewidth), layer=KiCad.Const.LAYER_TOP_SILK, ) ) # Side two startx = mm((bodysize[0] / 2) + 0.75) starty = mm(((pins[1] - 1) * pitch) / 2) while pin_number <= (pins[0] + pins[1]): p = KiCad.Pad( position=(startx, starty - mm(((pin_number - pins[0]) - 1) * pitch)), size=(padsizex, padsizey), number=pin_number, orientation=KiCad.Const.ORIENTATION_90DEG, shape=KiCad.Const.SHAPE_RECTANGLE, padtype=KiCad.Const.PADTYPE_SMD, ) result.addPad(p) pin_number += 1 # Side three startx = mm(((pins[0] - 1) * pitch) / 2) starty = 0 - mm((bodysize[1] / 2) + 0.75) while pin_number <= (pins[0] + pins[1] + pins[0]): p = KiCad.Pad( position=(startx - mm(((pin_number - (pins[0] + pins[1])) - 1) * pitch), starty), size=(padsizex, padsizey), number=pin_number, orientation=KiCad.Const.ORIENTATION_0DEG, shape=KiCad.Const.SHAPE_RECTANGLE, padtype=KiCad.Const.PADTYPE_SMD, ) result.addPad(p) pin_number += 1 # Side four startx = 0 - mm((bodysize[0] / 2) + 0.75) starty = 0 - mm(((pins[1] - 1) * pitch) / 2) while pin_number <= (pins[0] + pins[1] + pins[0] + pins[1]): p = KiCad.Pad( position=(startx, starty + mm(((pin_number - (pins[0] + pins[1] + pins[0])) - 1) * pitch)), size=(padsizex, padsizey), number=pin_number, orientation=KiCad.Const.ORIENTATION_90DEG, shape=KiCad.Const.SHAPE_RECTANGLE, padtype=KiCad.Const.PADTYPE_SMD, ) result.addPad(p) pin_number += 1 return result
import kicad_pcb as KiCad from kicad_pcb import mm as mm l = KiCad.ModuleLibrary() # DPAK # from http://www.diodes.com/zetex/_pdfs/3.0/pack/DPAK.pdf dpak3 = KiCad.Module() pincount = 3 linewidth = 0.2 # in mm # Set the module name dpak3.fields[0].text = "DPAK{0}".format(str(pincount)) dpak3.fields[0].y = -mm(2.5) dpak3.fields[0].visible = KiCad.Const.FIELDVIS_INVISIBLE # Move the reference default location away from the pads dpak3.fields[1].y = -mm(12) # Mark the body outline which is the dpak3.addDrawing( KiCad.DrawRectangle( size=(mm(6.2 + 0.5), mm(12.4 + 0.5)), centre=(mm(0), mm(-4.4)), lwidth=mm(linewidth), layer=KiCad.Const.LAYER_TOP_SILK, ) )
def dtypera( name, pincount, socket=True, A=0, B=0, C=0, D=0, E=0, F=0 ): """ The variables A through F are used to specify dimensions from the datasheet included under /connectors/dtype. Most D-Type RA implementations are the same. """ result = KiCad.Module("dtype") result.fields[0].text = "name" result.fields[0].y = mm(2) result.fields[0].visible = KiCad.Const.FIELDVIS_INVISIBLE # A line width (in mm) which can be used to draw on the silk screen layer linewidth = 0.2 #Place the mounting holes p = KiCad.Pad( position = (mm(-A/2), mm(8.93)), size = (mm(5), mm(5)), number = 0, orientation = KiCad.Const.ORIENTATION_0DEG, shape = KiCad.Const.SHAPE_CIRCLE, padtype = KiCad.Const.PADTYPE_STANDARD, drillsize = mm(3.5) ) result.addPad(p) p = KiCad.Pad( position = (mm(A/2), mm(8.93)), size = (mm(5), mm(5)), number = 0, orientation = KiCad.Const.ORIENTATION_0DEG, shape = KiCad.Const.SHAPE_CIRCLE, padtype = KiCad.Const.PADTYPE_STANDARD, drillsize = mm(3.5) ) result.addPad(p) # Place the top row of pins # Row 1 if socket == True: startx = mm(-C/2) else: startx = mm(C/2) starty = mm(10.2+(2.54/2)) pin_number = 1 padsizex = mm(2) padsizey = mm(2) drill = mm(1.2) padshape = KiCad.Const.SHAPE_RECTANGLE while pin_number <= ((pincount/2)+1): if socket == True: padx = startx + (mm((pin_number-1) * F)) else: padx = startx - (mm((pin_number-1) * F)) if pin_number != 1: padshape = KiCad.Const.SHAPE_CIRCLE p = KiCad.Pad( position = (padx, starty), size = (padsizex, padsizey), number = pin_number, orientation = KiCad.Const.ORIENTATION_0DEG, shape = padshape, padtype = KiCad.Const.PADTYPE_STANDARD, drillsize = drill ) result.addPad(p) pin_number += 1 # Row 2 if socket == True: startx = mm(-D/2) else: startx = mm(D/2) starty = mm(10.2-(2.54/2)) pinrow = pin_number while pin_number <= (pincount): if socket == True: padx = startx + (mm((pin_number - pinrow) * F)) else: padx = startx - (mm((pin_number - pinrow) * F)) p = KiCad.Pad( position = (padx, starty), size = (padsizex, padsizey), number = pin_number, orientation = KiCad.Const.ORIENTATION_0DEG, shape = KiCad.Const.SHAPE_CIRCLE, padtype = KiCad.Const.PADTYPE_STANDARD, drillsize = drill ) result.addPad(p) pin_number += 1 # Draw some silk screen information for the part # Show the outline result.addDrawing( KiCad.DrawRectangle( size = ( mm(A+10), mm(13.5) ), centre = ( 0, mm(6.75) ), lwidth = mm(linewidth), layer = KiCad.Const.LAYER_TOP_SILK ) ) # Show the protusion (through panel) result.addDrawing( KiCad.DrawRectangle( size = ( mm(B+1), mm(5) ), centre = ( 0, mm(-2.5) ), lwidth = mm(linewidth), layer = KiCad.Const.LAYER_TOP_SILK ) ) return result