Merge pull request #227 from Microsoft/max6675

adds MAX6675; adds general SPI & I2C support to sim
This commit is contained in:
Peli de Halleux 2016-09-01 22:48:33 -07:00 committed by GitHub
commit 8351ed0513
5 changed files with 72 additions and 8 deletions

View File

@ -148,6 +148,16 @@ namespace pxsim {
let idx = <number>location[1]; let idx = <number>location[1];
let pin = opts.cmpGPIOPins[idx]; let pin = opts.cmpGPIOPins[idx];
return {type: "dalboard", pin: pin}; 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 = (<any>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 = (<any>this.opts.boardDef.i2cPins)[location as string] as string;
return {type: "dalboard", pin: pin};
} else { } else {
//TODO //TODO
U.assert(false); U.assert(false);
@ -206,7 +216,7 @@ namespace pxsim {
let l = this.allocateLocation(ends[idx], { let l = this.allocateLocation(ends[idx], {
nearestBBPin: locInst.rowCol, nearestBBPin: locInst.rowCol,
startColumn: opts.startColumn, startColumn: opts.startColumn,
cmpGPIOPins: opts.cmpGPIOPins cmpGPIOPins: opts.cmpGPIOPins,
}); });
return l; return l;
}); });

View File

@ -12,8 +12,7 @@ namespace pxsim {
["P3"], ["P3"],
["P4", "P5", "P6", "P7"], ["P4", "P5", "P6", "P7"],
["P8", "P9", "P10", "P11", "P12"], ["P8", "P9", "P10", "P11", "P12"],
["P13", "P14", "P15", "P16"], ["P16"],
["P19", "P20"],
], ],
gpioPinMap: { gpioPinMap: {
"P0": "P0", "P0": "P0",
@ -36,6 +35,16 @@ namespace pxsim {
"P19": "P19", "P19": "P19",
"P20": "P20", "P20": "P20",
}, },
spiPins: {
MOSI: "P15",
MISO: "P14",
SCK: "P13",
},
i2cPins: {
SDA: "P20",
SCL: "P19",
},
analogInPins: ["P0", "P1", "P2", "P3", "P10"],
groundPins: ["GND"], groundPins: ["GND"],
threeVoltPins: ["+3v3"], threeVoltPins: ["+3v3"],
attachPowerOnRight: true, attachPowerOnRight: true,

View File

@ -147,7 +147,7 @@ namespace pxsim.visuals {
const pin3Vmid = pins4onMids[13] + bigPinWidth / 2.0; const pin3Vmid = pins4onMids[13] + bigPinWidth / 2.0;
const pinGNDmid = pins4onMids[pins4onMids.length - 1] + bigPinWidth / 2.0; const pinGNDmid = pins4onMids[pins4onMids.length - 1] + bigPinWidth / 2.0;
const pinGND2mid = pinGNDmid + 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 = [ const pinNames = [
"P0", "P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9", "P10", "P0", "P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9", "P10",
"P11", "P12", "P13", "P14", "P15", "P16", "P17", "P18", "P19", "P20", "P11", "P12", "P13", "P14", "P15", "P16", "P17", "P18", "P19", "P20",

View File

@ -163,6 +163,41 @@ namespace pxsim.visuals {
g.appendChild(el); g.appendChild(el);
return {el: g, x: x1 - strokeWidth, y: Math.min(y1, y2), w: w1 + strokeWidth * 2, h: h1 + h2}; 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"});
(<any>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"});
(<any>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 { function mkCrocEnd(p: [number, number], top: boolean, clr: string): SVGElAndSize {
//TODO: merge with mkOpenJumperEnd() //TODO: merge with mkOpenJumperEnd()
let k = visuals.PIN_DIST * 0.24; let k = visuals.PIN_DIST * 0.24;
@ -325,7 +360,7 @@ namespace pxsim.visuals {
return {endG: endG, end1: end1, end2: end2, wires: wires}; 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() //TODO: merge with drawWire()
const PIN_Y_OFF = 40; const PIN_Y_OFF = 40;
const CROC_Y_OFF = -17; const CROC_Y_OFF = -17;
@ -349,7 +384,11 @@ namespace pxsim.visuals {
pin2 = [x2, y2 + PIN_Y_OFF];//HACK pin2 = [x2, y2 + PIN_Y_OFF];//HACK
[x2, y2] = pin2; [x2, y2] = pin2;
let endCoord2: Coord = [x2, y2 + CROC_Y_OFF] 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 end2 = end2AndSize.el;
let endG = <SVGGElement>svg.child(g, "g", {class: "sim-bb-wire-ends-g"}); let endG = <SVGGElement>svg.child(g, "g", {class: "sim-bb-wire-ends-g"});
endG.appendChild(end1); endG.appendChild(end1);
@ -415,7 +454,13 @@ namespace pxsim.visuals {
let endLoc = this.getLocCoord(end); let endLoc = this.getLocCoord(end);
let wireEls: Wire; let wireEls: Wire;
if (withCrocs && end.type == "dalboard") { if (withCrocs && end.type == "dalboard") {
wireEls = this.drawWireWithCrocs(startLoc, endLoc, color); let boardPin = (<BoardLoc>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 { } else {
wireEls = this.drawWire(startLoc, endLoc, color); wireEls = this.drawWire(startLoc, endLoc, color);
} }