From 374d8c590dd7bf849892db47cd455f147c588f53 Mon Sep 17 00:00:00 2001 From: darzu Date: Wed, 31 Aug 2016 21:53:48 -0700 Subject: [PATCH 1/3] adds spi and i2c pins --- docs/static/hardware/.gitignore | 3 +- sim/allocator.ts | 13 +++++- sim/definitions.ts | 74 ++++++++++++++++++++++++++++++--- 3 files changed, 82 insertions(+), 8 deletions(-) diff --git a/docs/static/hardware/.gitignore b/docs/static/hardware/.gitignore index 09ade3ad..a4abe543 100644 --- a/docs/static/hardware/.gitignore +++ b/docs/static/hardware/.gitignore @@ -1,4 +1,5 @@ # don't check in until OSS request is approved sparkfun-* raspberrypi-* -arduino-* \ No newline at end of file +arduino-* +max6675.svg \ No newline at end of file diff --git a/sim/allocator.ts b/sim/allocator.ts index de1b0cd4..ef35bc89 100644 --- a/sim/allocator.ts +++ b/sim/allocator.ts @@ -148,6 +148,16 @@ namespace pxsim { let idx = location[1]; let pin = opts.cmpGPIOPins[idx]; return {type: "dalboard", pin: pin}; + } else if (location === "MOSI" || location === "MISO" || location === "SCK") { + if (!this.opts.boardDef.spiPins) + console.debug("No SPI pin mappings found!"); + let pin = (this.opts.boardDef.spiPins)[location as string] as string; + return {type: "dalboard", pin: pin}; + } else if (location === "SDA" || location === "SCL") { + if (!this.opts.boardDef.i2cPins) + console.debug("No I2C pin mappings found!"); + let pin = (this.opts.boardDef.i2cPins)[location as string] as string; + return {type: "dalboard", pin: pin}; } else { //TODO U.assert(false); @@ -206,7 +216,7 @@ namespace pxsim { let l = this.allocateLocation(ends[idx], { nearestBBPin: locInst.rowCol, startColumn: opts.startColumn, - cmpGPIOPins: opts.cmpGPIOPins + cmpGPIOPins: opts.cmpGPIOPins, }); return l; }); @@ -260,6 +270,7 @@ namespace pxsim { }); } else { // failed to find pin allocation from callsites + debugger; console.debug("Failed to read pin(s) from callsite for: " + fnNm); let pinsNeeded = fnPinAlloc.pinArgPositions.length; partialCmps.push({ diff --git a/sim/definitions.ts b/sim/definitions.ts index 4a5531f8..93d900a2 100644 --- a/sim/definitions.ts +++ b/sim/definitions.ts @@ -28,6 +28,16 @@ namespace pxsim { onboardComponents?: string[] useCrocClips?: boolean, marginWhenBreadboarding?: [number, number, number, number], + spiPins?: { + MOSI: string, + MISO: string, + SCK: string, + }, + i2cPins?: { + SDA: string, + SCL: string, + }, + analogInPins?: string[], //TODO: implement allocation } export interface FactoryFunctionPinAlloc { type: "factoryfunction", @@ -65,8 +75,15 @@ namespace pxsim { color: string, assemblyStep: number }; - export type WireLocationDefinition = - ["breadboard", string, number] | ["GPIO", number] | "ground" | "threeVolt"; + export type SPIPin = "MOSI" | "MISO" | "SCK"; + export type I2CPin = "SDA" | "SCL"; + export type WireLocationDefinition = ( + ["breadboard", string, number] + | ["GPIO", number] + | SPIPin + | I2CPin + | "ground" + | "threeVolt"); export const MICROBIT_DEF: BoardDefinition = { visual: "microbit", @@ -75,8 +92,7 @@ namespace pxsim { ["P3"], ["P4", "P5", "P6", "P7"], ["P8", "P9", "P10", "P11", "P12"], - ["P13", "P14", "P15", "P16"], - ["P19", "P20"], + ["P16"], ], gpioPinMap: { "P0": "P0", @@ -99,6 +115,16 @@ namespace pxsim { "P19": "P19", "P20": "P20", }, + spiPins: { + MOSI: "P15", + MISO: "P14", + SCK: "P13", + }, + i2cPins: { + SDA: "P20", + SCL: "P19", + }, + analogInPins: ["P0", "P1", "P2", "P3", "P10"], groundPins: ["GND"], threeVoltPins: ["+3v3"], attachPowerOnRight: true, @@ -229,6 +255,18 @@ namespace pxsim { "P19": "~11", "P20": "~12", }, + //TODO: add SPI pins to Arduino board + // spiPins: { + // ChipSelect: "P16", + // MOSI: "P15", + // MISO: "P14", + // SCK: "P13", + // }, + // i2cPins: { + // SDA: "P20", + // SCL: "P19", + // }, + analogInPins: ["A0", "A1", "A2", "A3", "A4", "A5"], groundPins: ["GND0", "GND1", "GND2"], threeVoltPins: ["3.3V"], marginWhenBreadboarding: [20, 0, 40, 0], @@ -311,6 +349,31 @@ namespace pxsim { {start: ["breadboard", "j", 3], end: "ground", color: "blue", assemblyStep: 1}, ], }, + "max6675": { + visual: { + image: "/static/hardware/max6675.svg", + width: 58, + height: 64, + firstPin: [11, 5], + pinDist: 7.2, + extraColumnOffset: 2, + }, + breadboardColumnsNeeded: 10, + breadboardStartRow: "h", + pinAllocation: { + type: "factoryfunction", + functionName: "max6675.temperature", + pinArgPositions: [0] + }, + assemblyStep: 0, + wires: [ + {start: ["breadboard", "j", 2], end: "SCK", color: "green", assemblyStep: 1}, + {start: ["breadboard", "j", 3], end: ["GPIO", 0], color: "blue", assemblyStep: 1}, + {start: ["breadboard", "j", 4], end: "MISO", color: "orange", assemblyStep: 1}, + {start: ["breadboard", "j", 5], end: "ground", color: "blue", assemblyStep: 0}, + {start: ["breadboard", "j", 6], end: "threeVolt", color: "red", assemblyStep: 1}, + ], + }, } export const builtinComponentSimVisual: Map<() => visuals.IBoardComponent> = { @@ -337,6 +400,5 @@ namespace pxsim { }; //TODO: add multiple board support - //export const CURRENT_BOARD = MICROBIT_DEF; - export const CURRENT_BOARD = ARDUINO_ZERO; + export const CURRENT_BOARD = MICROBIT_DEF; } \ No newline at end of file From 232758805bf56604d947e07b72665eefcad17738 Mon Sep 17 00:00:00 2001 From: darzu Date: Wed, 31 Aug 2016 21:56:46 -0700 Subject: [PATCH 2/3] removes "debugger" statement --- sim/allocator.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/sim/allocator.ts b/sim/allocator.ts index ef35bc89..dd23e33b 100644 --- a/sim/allocator.ts +++ b/sim/allocator.ts @@ -270,7 +270,6 @@ namespace pxsim { }); } else { // failed to find pin allocation from callsites - debugger; console.debug("Failed to read pin(s) from callsite for: " + fnNm); let pinsNeeded = fnPinAlloc.pinArgPositions.length; partialCmps.push({ From 7048156b4630c36a53a59c195d750a5f30deeee3 Mon Sep 17 00:00:00 2001 From: darzu Date: Wed, 31 Aug 2016 22:41:30 -0700 Subject: [PATCH 3/3] draws small wires for small micro:bit pins --- sim/microbit.ts | 2 +- sim/visuals/wiring.ts | 51 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/sim/microbit.ts b/sim/microbit.ts index 1d5d2842..792907a5 100644 --- a/sim/microbit.ts +++ b/sim/microbit.ts @@ -147,7 +147,7 @@ namespace pxsim.visuals { const pin3Vmid = pins4onMids[13] + bigPinWidth / 2.0; const pinGNDmid = pins4onMids[pins4onMids.length - 1] + bigPinWidth / 2.0; const pinGND2mid = pinGNDmid + bigPinWidth / 2.0; - const pinMids = [pin0mid, pin1mid, pin2mid, pin3mid].concat(pins4onXs).concat([pinGNDmid, pin3Vmid, pinGND2mid]); + const pinMids = [pin0mid, pin1mid, pin2mid, pin3mid].concat(pins4onMids).concat([pinGNDmid, pin3Vmid, pinGND2mid]); const pinNames = [ "P0", "P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9", "P10", "P11", "P12", "P13", "P14", "P15", "P16", "P17", "P18", "P19", "P20", diff --git a/sim/visuals/wiring.ts b/sim/visuals/wiring.ts index 1f1248e0..d5a0b693 100644 --- a/sim/visuals/wiring.ts +++ b/sim/visuals/wiring.ts @@ -163,6 +163,41 @@ namespace pxsim.visuals { g.appendChild(el); return {el: g, x: x1 - strokeWidth, y: Math.min(y1, y2), w: w1 + strokeWidth * 2, h: h1 + h2}; } + function mkSmallMBPinEnd(p: [number, number], top: boolean, clr: string): visuals.SVGElAndSize { + //HACK + //TODO: merge with mkOpenJumperEnd() + let k = visuals.PIN_DIST * 0.24; + let plasticLength = k * 4; + let plasticWidth = k * 1.2; + let metalLength = k * 10; + let metalWidth = k; + const strokeWidth = visuals.PIN_DIST / 4.0; + let [cx, cy] = p; + let yOffset = 10; + let o = top ? -1 : 1; + let g = svg.elt("g") + + let el = svg.elt("rect"); + let h1 = plasticLength; + let w1 = plasticWidth; + let x1 = cx - w1 / 2; + let y1 = cy + yOffset - (h1 / 2); + svg.hydrate(el, {x: x1, y: y1, width: w1, height: h1, rx: 0.5, ry: 0.5, class: "sim-bb-wire-end"}); + (el).style["stroke-width"] = `${strokeWidth}px`; + + let el2 = svg.elt("rect"); + let h2 = metalLength; + let w2 = metalWidth; + let cy2 = cy + yOffset + o * (h1 / 2 + h2 / 2); + let x2 = cx - w2 / 2; + let y2 = cy2 - (h2 / 2); + svg.hydrate(el2, {x: x2, y: y2, width: w2, height: h2, class: "sim-bb-wire-bare-end"}); + (el2).style["fill"] = `#bbb`; + + g.appendChild(el2); + g.appendChild(el); + return {el: g, x: x1 - strokeWidth, y: Math.min(y1, y2), w: w1 + strokeWidth * 2, h: h1 + h2}; + } function mkCrocEnd(p: [number, number], top: boolean, clr: string): SVGElAndSize { //TODO: merge with mkOpenJumperEnd() let k = visuals.PIN_DIST * 0.24; @@ -325,7 +360,7 @@ namespace pxsim.visuals { return {endG: endG, end1: end1, end2: end2, wires: wires}; } - private drawWireWithCrocs(pin1: Coord, pin2: Coord, color: string): Wire { + private drawWireWithCrocs(pin1: Coord, pin2: Coord, color: string, smallPin: boolean = false): Wire { //TODO: merge with drawWire() const PIN_Y_OFF = 40; const CROC_Y_OFF = -17; @@ -349,7 +384,11 @@ namespace pxsim.visuals { pin2 = [x2, y2 + PIN_Y_OFF];//HACK [x2, y2] = pin2; let endCoord2: Coord = [x2, y2 + CROC_Y_OFF] - let end2AndSize = mkCrocEnd(endCoord2, true, color); + let end2AndSize: SVGElAndSize; + if (smallPin) + end2AndSize = mkSmallMBPinEnd(endCoord2, true, color); + else + end2AndSize = mkCrocEnd(endCoord2, true, color); let end2 = end2AndSize.el; let endG = svg.child(g, "g", {class: "sim-bb-wire-ends-g"}); endG.appendChild(end1); @@ -415,7 +454,13 @@ namespace pxsim.visuals { let endLoc = this.getLocCoord(end); let wireEls: Wire; if (withCrocs && end.type == "dalboard") { - wireEls = this.drawWireWithCrocs(startLoc, endLoc, color); + let boardPin = (end).pin; + if (boardPin == "P0" || boardPin == "P1" || boardPin == "P0" || boardPin == "GND" || boardPin == "+3v3" ) { + //HACK + wireEls = this.drawWireWithCrocs(startLoc, endLoc, color); + } else { + wireEls = this.drawWireWithCrocs(startLoc, endLoc, color, true); + } } else { wireEls = this.drawWire(startLoc, endLoc, color); }