From 374d8c590dd7bf849892db47cd455f147c588f53 Mon Sep 17 00:00:00 2001 From: darzu Date: Wed, 31 Aug 2016 21:53:48 -0700 Subject: [PATCH] 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