From dd55349cd41a7a95480764c0a83ec85cfb6c4663 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Wed, 2 Dec 2020 18:26:18 +0100 Subject: [PATCH 1/2] Try to make the brain sim work with neopixels --- libs/brain-nrf52840/board.json | 133 +++++++++++++++++++++++++++++--- libs/brain-nrf52840/board.svg | 2 +- libs/brain-nrf52840/boardhd.svg | 120 +++++++++++++++++----------- sim/dalboard.ts | 22 +++--- 4 files changed, 209 insertions(+), 68 deletions(-) diff --git a/libs/brain-nrf52840/board.json b/libs/brain-nrf52840/board.json index 90a1a6d6c..ec9e3fc0e 100644 --- a/libs/brain-nrf52840/board.json +++ b/libs/brain-nrf52840/board.json @@ -3,16 +3,96 @@ "visual": { "image": "pkg://board.svg", "useCrocClips": false, - "width": 210, - "height": 151, + "width": 343, + "height": 172, "pinDist": 15, - "pinBlocks": [], + "pinBlocks": [ + { + "x": 85.19873566204326, + "y": 103.12977654517205, + "labels": [ + "MISO" + ] + }, + { + "x": 97.11066907933298, + "y": 103.12977654517205, + "labels": [ + "MOSI" + ] + }, + { + "x": 109.0226216503817, + "y": 103.12977654517205, + "labels": [ + "SCK" + ] + }, + { + "x": 132.84646933120212, + "y": 103.12977654517205, + "labels": [ + "GND" + ] + }, + { + "x": 144.7583261334558, + "y": 103.12977654517205, + "labels": [ + "_3V" + ] + }, + { + "x": 156.67031701202254, + "y": 103.12977654517205, + "labels": [ + "_5V" + ] + }, + { + "x": 168.58228873683026, + "y": 103.12977654517205, + "labels": [ + "LIGHT_FAULT" + ] + }, + { + "x": 180.49414553908395, + "y": 103.12977654517205, + "labels": [ + "LIGHT_PWR" + ] + }, + { + "x": 192.40642372403576, + "y": 103.12977654517205, + "labels": [ + "VBAT" + ] + } + , + { + "x": 205.40642372403576, + "y": 103.12977654517205, + "labels": [ + "LED" + ] + } + ], "leds": [ { - "x": 36.3439176372727, - "y": 27.592803376252533, - "w": 5.463899017361905, - "h": 4.714000572214601, + "x": 120.93449760639439, + "y": 103.12977654517205, + "w": 5.9999150086845265, + "h": 5.996997231091599, + "color": "neopixel", + "label": "NEOPIXEL" + }, + { + "x": 98.93901029902648, + "y": 38.202999828947746, + "w": 5.463839601619682, + "h": 4.714004636228868, "color": "#ff0000", "label": "LED" } @@ -21,20 +101,49 @@ "buttons": [] }, "gpioPinMap": { + "MISO": "MISO", + "MOSI": "MOSI", + "SCK": "SCK", + "NEOPIXEL": "NEOPIXEL", + "GND": "GND", + "_3V": "_3V", + "": "_5V", + "3V": "_3V", + "_5V": "_5V", + "5V": "_5V", + "LIGHT_FAULT": "LIGHT_FAULT", + "LIGHT": "LIGHT_PWR", + "FAULT": "LIGHT_FAULT", + "LIGHT_PWR": "LIGHT_PWR", + "PWR": "LIGHT_PWR", + "VBAT": "VBAT", "LED": "LED" }, - "groundPins": [], - "threeVoltPins": [], - "fiveVoltPins": [], + "groundPins": [ + "GND" + ], + "threeVoltPins": [ + "_3V" + ], + "fiveVoltPins": [ + "_5V" + ], "i2cPins": { "SDA": "SDA", "SCL": "SCL" }, - "onboardComponents": [], + "onboardComponents": [ + "pixel" + ], "marginWhenBreadboarding": [ 0, 0, 80, 0 - ] + ], + "spiPins": { + "MOSI": "MOSI", + "MISO": "MISO", + "SCK": "SCK" + } } \ No newline at end of file diff --git a/libs/brain-nrf52840/board.svg b/libs/brain-nrf52840/board.svg index f41ea9c1f..ddfd2def5 100644 --- a/libs/brain-nrf52840/board.svg +++ b/libs/brain-nrf52840/board.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/libs/brain-nrf52840/boardhd.svg b/libs/brain-nrf52840/boardhd.svg index c8148eb2c..15d5f198a 100644 --- a/libs/brain-nrf52840/boardhd.svg +++ b/libs/brain-nrf52840/boardhd.svg @@ -1,51 +1,79 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sim/dalboard.ts b/sim/dalboard.ts index a958b116e..926154e74 100644 --- a/sim/dalboard.ts +++ b/sim/dalboard.ts @@ -56,6 +56,7 @@ namespace pxsim { const pinList: number[] = [] const servos: Map = {} + const syntheticPins: Map = {} function pinId(name: string) { let key = getConfigKey("PIN_" + name) @@ -65,7 +66,10 @@ namespace pxsim { let m = /^P(\d+)$/.exec(name) if (m) return parseInt(m[1]) - return null + // this happens when pins are defined in the bootloader + if (!syntheticPins[name]) + syntheticPins[name] = 100 + Object.keys(syntheticPins).length + return syntheticPins[name] } pinIds = {} @@ -144,7 +148,7 @@ namespace pxsim { this.builtinVisuals["dotstar"] = () => new visuals.NeoPixelView(parsePinString); this.builtinPartVisuals["dotstar"] = (xy: visuals.Coord) => visuals.mkNeoPixelPart(xy); - this.builtinParts["lcd"] = this.lcdState; + this.builtinParts["lcd"] = this.lcdState; this.builtinVisuals["lcd"] = () => new visuals.LCDView(); this.builtinPartVisuals["lcd"] = (xy: visuals.Coord) => visuals.mkLCDPart(xy); @@ -166,15 +170,15 @@ namespace pxsim { this.builtinVisuals["screen"] = () => new visuals.ScreenView(); this.builtinPartVisuals["screen"] = (xy: visuals.Coord) => visuals.mkScreenPart(xy); - - this.neopixelPin = this.edgeConnectorState.getPin(getConfig(DAL.CFG_PIN_ONBOARD_DOTSTAR_DATA)) - || this.edgeConnectorState.getPin(getConfig(DAL.CFG_PIN_ONBOARD_NEOPIXEL)) - || this.edgeConnectorState.getPin(getConfig(DAL.CFG_PIN_DOTSTAR_DATA)) - || this.edgeConnectorState.getPin(getConfig(DAL.CFG_PIN_NEOPIXEL)); - + + this.neopixelPin = this.edgeConnectorState.getPin(getConfig(DAL.CFG_PIN_ONBOARD_DOTSTAR_DATA)) + || this.edgeConnectorState.getPin(getConfig(DAL.CFG_PIN_ONBOARD_NEOPIXEL)) + || this.edgeConnectorState.getPin(getConfig(DAL.CFG_PIN_DOTSTAR_DATA)) + || this.edgeConnectorState.getPin(getConfig(DAL.CFG_PIN_NEOPIXEL)); + this.builtinParts["pixels"] = (pin: Pin) => { return this.neopixelState(!!this.neopixelPin && this.neopixelPin.id); }; this.builtinVisuals["pixels"] = () => new visuals.NeoPixelView(parsePinString); - this.builtinPartVisuals["pixels"] = (xy: visuals.Coord) => visuals.mkNeoPixelPart(xy); + this.builtinPartVisuals["pixels"] = (xy: visuals.Coord) => visuals.mkNeoPixelPart(xy); } receiveMessage(msg: SimulatorMessage) { From bddd199508c3caf22ff22cfe35e0367dfa2e51e4 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 2 Dec 2020 22:37:02 +0100 Subject: [PATCH 2/2] refactor parse pin string --- sim/dalboard.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sim/dalboard.ts b/sim/dalboard.ts index 926154e74..08da4cb54 100644 --- a/sim/dalboard.ts +++ b/sim/dalboard.ts @@ -58,7 +58,7 @@ namespace pxsim { const servos: Map = {} const syntheticPins: Map = {} - function pinId(name: string) { + function pinId(name: string): number { let key = getConfigKey("PIN_" + name) if (key != null) return getConfig(key) @@ -72,6 +72,12 @@ namespace pxsim { return syntheticPins[name] } + + function parsePinString(pinString: string): Pin { + const pinName = pinString && pxsim.readPin(pinString); + return pinName && pxtcore.getPin(pinId(pinName)); + } + pinIds = {} for (let block of (boardDefinition.visual as BoardImageDefinition).pinBlocks) { @@ -280,9 +286,4 @@ namespace pxsim { if (!pxsim.initCurrentRuntime) { pxsim.initCurrentRuntime = initRuntimeWithDalBoard; } - - export function parsePinString(pinString: string): Pin { - const pinName = pinString && pxsim.readPin(pinString); - return pinName && pxtcore.getPin(pinIds[pinName]); - } } \ No newline at end of file