diff --git a/libs/core/_locales/core-jsdoc-strings.json b/libs/core/_locales/core-jsdoc-strings.json index 5f69e72acbe..d63e3c8fc80 100644 --- a/libs/core/_locales/core-jsdoc-strings.json +++ b/libs/core/_locales/core-jsdoc-strings.json @@ -615,6 +615,7 @@ "pins.P7": "Pin P7", "pins.P8": "Pin P8", "pins.P9": "Pin P9", + "pins.analogPin": "Returns the value of a C++ runtime constant", "pins.analogPitch": "Send a pulse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.", "pins.analogPitchVolume": "Gets the volume the pitch pin from 0..255", "pins.analogPitch|param|frequency": "frequency to modulate in Hz.", @@ -633,6 +634,7 @@ "pins.analogWritePin|param|value": "value to write to the pin between ``0`` and ``1023``. eg:1023,0", "pins.createBuffer": "Create a new zero-initialized buffer.", "pins.createBuffer|param|size": "number of bytes in the buffer", + "pins.digitalPin": "Returns the value of a C++ runtime constant", "pins.digitalReadPin": "Read the specified pin or connector as either 0 or 1", "pins.digitalReadPin|param|name": "pin to read from, eg: DigitalPin.P0", "pins.digitalWritePin": "Set a pin or connector value to either 0 or 1.", diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index ca570e17f32..571864cada1 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -407,6 +407,7 @@ "music|block": "music", "parseFloat|block": "parse to number %text", "parseInt|block": "parse to integer %text", + "pins.analogPin|block": "analog pin %pin", "pins.analogPitchVolume|block": "analog pitch volume", "pins.analogPitch|block": "analog pitch %frequency|for (ms) %ms", "pins.analogReadPin|block": "analog read|pin %name", @@ -414,6 +415,7 @@ "pins.analogSetPitchPin|block": "analog set pitch pin %name", "pins.analogSetPitchVolume|block": "analog set pitch volume $volume", "pins.analogWritePin|block": "analog write|pin %name|to %value", + "pins.digitalPin|block": "digital pin %pin", "pins.digitalReadPin|block": "digital read|pin %name", "pins.digitalWritePin|block": "digital write|pin %name|to %value", "pins.i2cReadNumber|block": "i2c read number|at address %address|of format %format|repeated %repeat", diff --git a/libs/core/blocks-test/pins.blocks b/libs/core/blocks-test/pins.blocks old mode 100644 new mode 100755 index 9e01d01cd86..294ec6edfd8 --- a/libs/core/blocks-test/pins.blocks +++ b/libs/core/blocks-test/pins.blocks @@ -1,209 +1,269 @@ - - - DigitalPin.P5 - PulseValue.Low - - - AnalogPin.P9 - - - 5 - - - - - AnalogPin.P10 - - - 20000 - - - - - DigitalPin.P6 - - - 5 - - - - - AnalogPin.P13 - - - 5 - - - - - AnalogPin.P8 - - - 1500 - - - - - 0 - - - NumberFormat.Int8BE - - - 0 - - - - - FALSE - - - - - - - 0 - - - DigitalPin.P9 - PulseValue.Low - - - - - 1023 - - - - - - 0 - - - - - 0 - - - - - - - 4 - - - - - - - NumberFormat.Int16BE - - - 0 - - - DigitalPin.P9 - - - - - 0 - - - AnalogPin.P9 - - - - - FALSE - - - - - DigitalPin.P11 - DigitalPin.P9 - DigitalPin.P10 - - - DigitalPin.P9 - PinPullMode.PullDown - - - - - 0 - - - - - 0 - - - - - DigitalPin.P8 - PinEventType.Touch - - - AnalogPin.P9 - - - - - 8 - - - - - 3 - - - - - - - 8 - - - - - 3 - - - - - - - 1000000 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + DigitalPin.P5 + + + PulseValue.Low + + + + + AnalogPin.P9 + + + + + 5 + + + + + + + AnalogPin.P10 + + + + + 20000 + + + + + + + DigitalPin.P6 + + + + + 5 + + + + + + + AnalogPin.P13 + + + + + 5 + + + + + + + AnalogPin.P8 + + + + + 1500 + + + + + 0 + + + NumberFormat.Int8BE + + + 0 + + + + + FALSE + + + + + + + 0 + + + + + DigitalPin.P9 + + + PulseValue.Low + + + + + 1023 + + + + + + 0 + + + + + 0 + + + + + + + 4 + + + + + + + NumberFormat.Int16BE + + + 0 + + + + + DigitalPin.P9 + + + + + + + 0 + + + + + AnalogPin.P9 + + + + + + + FALSE + + + + + + + DigitalPin.P11 + + + + + DigitalPin.P9 + + + + + DigitalPin.P10 + + + + + + + DigitalPin.P9 + + + PinPullMode.PullDown + + + + + 0 + + + + + 0 + + + + + + + DigitalPin.P8 + + + PinEventType.Touch + + + + + AnalogPin.P9 + + + + + + + 8 + + + + + 3 + + + + + + + 8 + + + + + 3 + + + + + + + 1000000 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/libs/core/blocks-test/test.blocks b/libs/core/blocks-test/test.blocks old mode 100644 new mode 100755 index 3136093e4fb..d812a4350a7 --- a/libs/core/blocks-test/test.blocks +++ b/libs/core/blocks-test/test.blocks @@ -150,31 +150,51 @@ DisplayMode.Greyscale - AnalogPin.P4 + + + AnalogPin.P4 + + 1023 - AnalogPin.P13 + + + AnalogPin.P13 + + - DigitalPin.P10 + + + DigitalPin.P10 + + 0 - DigitalPin.P15 + + + DigitalPin.P15 + + + + AnalogPin.P9 + + 1234 @@ -218,7 +238,11 @@ - AnalogPin.P20 + + + AnalogPin.P20 + + @@ -230,7 +254,11 @@ - AnalogPin.P14 + + + AnalogPin.P14 + + 1500 @@ -510,7 +538,11 @@ - DigitalPin.P10 + + + DigitalPin.P10 + + PulseValue.Low @@ -544,7 +576,11 @@ - DigitalPin.P0 + + + DigitalPin.P0 + + PinEventType.Touch @@ -555,10 +591,18 @@ - AnalogPin.P2 + + + AnalogPin.P2 + + - DigitalPin.P2 + + + DigitalPin.P2 + + PinPullMode.PullDown @@ -574,9 +618,21 @@ - DigitalPin.P9 - DigitalPin.P14 - DigitalPin.P16 + + + DigitalPin.P9 + + + + + DigitalPin.P14 + + + + + DigitalPin.P16 + + diff --git a/libs/core/enums.d.ts b/libs/core/enums.d.ts index 9086e011805..5d7d5c33a0a 100644 --- a/libs/core/enums.d.ts +++ b/libs/core/enums.d.ts @@ -428,62 +428,100 @@ declare namespace led { declare const enum DigitalPin { + //% blockIdentity="pins.digitalPin" P0 = 100, // MICROBIT_ID_IO_P0 + //% blockIdentity="pins.digitalPin" P1 = 101, // MICROBIT_ID_IO_P1 + //% blockIdentity="pins.digitalPin" P2 = 102, // MICROBIT_ID_IO_P2 + //% blockIdentity="pins.digitalPin" P3 = 103, // MICROBIT_ID_IO_P3 + //% blockIdentity="pins.digitalPin" P4 = 104, // MICROBIT_ID_IO_P4 + //% blockIdentity="pins.digitalPin" P5 = 105, // MICROBIT_ID_IO_P5 + //% blockIdentity="pins.digitalPin" P6 = 106, // MICROBIT_ID_IO_P6 + //% blockIdentity="pins.digitalPin" P7 = 107, // MICROBIT_ID_IO_P7 + //% blockIdentity="pins.digitalPin" P8 = 108, // MICROBIT_ID_IO_P8 + //% blockIdentity="pins.digitalPin" P9 = 109, // MICROBIT_ID_IO_P9 + //% blockIdentity="pins.digitalPin" P10 = 110, // MICROBIT_ID_IO_P10 + //% blockIdentity="pins.digitalPin" P11 = 111, // MICROBIT_ID_IO_P11 + //% blockIdentity="pins.digitalPin" P12 = 112, // MICROBIT_ID_IO_P12 + //% blockIdentity="pins.digitalPin" P13 = 113, // MICROBIT_ID_IO_P13 + //% blockIdentity="pins.digitalPin" P14 = 114, // MICROBIT_ID_IO_P14 + //% blockIdentity="pins.digitalPin" P15 = 115, // MICROBIT_ID_IO_P15 + //% blockIdentity="pins.digitalPin" P16 = 116, // MICROBIT_ID_IO_P16 + //% blockIdentity="pins.digitalPin" //% blockHidden=1 P19 = 119, // MICROBIT_ID_IO_P19 + //% blockIdentity="pins.digitalPin" //% blockHidden=1 P20 = 120, // MICROBIT_ID_IO_P20 } declare const enum AnalogPin { + //% blockIdentity="pins.analogPin" P0 = 100, // MICROBIT_ID_IO_P0 + //% blockIdentity="pins.analogPin" P1 = 101, // MICROBIT_ID_IO_P1 + //% blockIdentity="pins.analogPin" P2 = 102, // MICROBIT_ID_IO_P2 + //% blockIdentity="pins.analogPin" P3 = 103, // MICROBIT_ID_IO_P3 + //% blockIdentity="pins.analogPin" P4 = 104, // MICROBIT_ID_IO_P4 + //% blockIdentity="pins.analogPin" P10 = 110, // MICROBIT_ID_IO_P10 + //% blockIdentity="pins.analogPin" //% block="P5 (write only)" P5 = 105, // MICROBIT_ID_IO_P5 + //% blockIdentity="pins.analogPin" //% block="P6 (write only)" P6 = 106, // MICROBIT_ID_IO_P6 + //% blockIdentity="pins.analogPin" //% block="P7 (write only)" P7 = 107, // MICROBIT_ID_IO_P7 + //% blockIdentity="pins.analogPin" //% block="P8 (write only)" P8 = 108, // MICROBIT_ID_IO_P8 + //% blockIdentity="pins.analogPin" //% block="P9 (write only)" P9 = 109, // MICROBIT_ID_IO_P9 + //% blockIdentity="pins.analogPin" //% block="P11 (write only)" P11 = 111, // MICROBIT_ID_IO_P11 + //% blockIdentity="pins.analogPin" //% block="P12 (write only)" P12 = 112, // MICROBIT_ID_IO_P12 + //% blockIdentity="pins.analogPin" //% block="P13 (write only)" P13 = 113, // MICROBIT_ID_IO_P13 + //% blockIdentity="pins.analogPin" //% block="P14 (write only)" P14 = 114, // MICROBIT_ID_IO_P14 + //% blockIdentity="pins.analogPin" //% block="P15 (write only)" P15 = 115, // MICROBIT_ID_IO_P15 + //% blockIdentity="pins.analogPin" //% block="P16 (write only)" P16 = 116, // MICROBIT_ID_IO_P16 + //% blockIdentity="pins.analogPin" //% block="P19 (write only)" //% blockHidden=1 P19 = 119, // MICROBIT_ID_IO_P19 + //% blockIdentity="pins.analogPin" //% block="P20 (write only)" //% blockHidden=1 P20 = 120, // MICROBIT_ID_IO_P20 diff --git a/libs/core/pins.cpp b/libs/core/pins.cpp index 6691c6ed87f..e374b7a5485 100644 --- a/libs/core/pins.cpp +++ b/libs/core/pins.cpp @@ -10,61 +10,99 @@ #endif enum class DigitalPin { + //% blockIdentity="pins.digitalPin" P0 = MICROBIT_ID_IO_P0, + //% blockIdentity="pins.digitalPin" P1 = MICROBIT_ID_IO_P1, + //% blockIdentity="pins.digitalPin" P2 = MICROBIT_ID_IO_P2, + //% blockIdentity="pins.digitalPin" P3 = MICROBIT_ID_IO_P3, + //% blockIdentity="pins.digitalPin" P4 = MICROBIT_ID_IO_P4, + //% blockIdentity="pins.digitalPin" P5 = MICROBIT_ID_IO_P5, + //% blockIdentity="pins.digitalPin" P6 = MICROBIT_ID_IO_P6, + //% blockIdentity="pins.digitalPin" P7 = MICROBIT_ID_IO_P7, + //% blockIdentity="pins.digitalPin" P8 = MICROBIT_ID_IO_P8, + //% blockIdentity="pins.digitalPin" P9 = MICROBIT_ID_IO_P9, + //% blockIdentity="pins.digitalPin" P10 = MICROBIT_ID_IO_P10, + //% blockIdentity="pins.digitalPin" P11 = MICROBIT_ID_IO_P11, + //% blockIdentity="pins.digitalPin" P12 = MICROBIT_ID_IO_P12, + //% blockIdentity="pins.digitalPin" P13 = MICROBIT_ID_IO_P13, + //% blockIdentity="pins.digitalPin" P14 = MICROBIT_ID_IO_P14, + //% blockIdentity="pins.digitalPin" P15 = MICROBIT_ID_IO_P15, + //% blockIdentity="pins.digitalPin" P16 = MICROBIT_ID_IO_P16, + //% blockIdentity="pins.digitalPin" //% blockHidden=1 P19 = MICROBIT_ID_IO_P19, + //% blockIdentity="pins.digitalPin" //% blockHidden=1 P20 = MICROBIT_ID_IO_P20, }; enum class AnalogPin { + //% blockIdentity="pins.analogPin" P0 = MICROBIT_ID_IO_P0, + //% blockIdentity="pins.analogPin" P1 = MICROBIT_ID_IO_P1, + //% blockIdentity="pins.analogPin" P2 = MICROBIT_ID_IO_P2, + //% blockIdentity="pins.analogPin" P3 = MICROBIT_ID_IO_P3, + //% blockIdentity="pins.analogPin" P4 = MICROBIT_ID_IO_P4, + //% blockIdentity="pins.analogPin" P10 = MICROBIT_ID_IO_P10, + //% blockIdentity="pins.analogPin" //% block="P5 (write only)" P5 = MICROBIT_ID_IO_P5, + //% blockIdentity="pins.analogPin" //% block="P6 (write only)" P6 = MICROBIT_ID_IO_P6, + //% blockIdentity="pins.analogPin" //% block="P7 (write only)" P7 = MICROBIT_ID_IO_P7, + //% blockIdentity="pins.analogPin" //% block="P8 (write only)" P8 = MICROBIT_ID_IO_P8, + //% blockIdentity="pins.analogPin" //% block="P9 (write only)" P9 = MICROBIT_ID_IO_P9, + //% blockIdentity="pins.analogPin" //% block="P11 (write only)" P11 = MICROBIT_ID_IO_P11, + //% blockIdentity="pins.analogPin" //% block="P12 (write only)" P12 = MICROBIT_ID_IO_P12, + //% blockIdentity="pins.analogPin" //% block="P13 (write only)" P13 = MICROBIT_ID_IO_P13, + //% blockIdentity="pins.analogPin" //% block="P14 (write only)" P14 = MICROBIT_ID_IO_P14, + //% blockIdentity="pins.analogPin" //% block="P15 (write only)" P15 = MICROBIT_ID_IO_P15, + //% blockIdentity="pins.analogPin" //% block="P16 (write only)" P16 = MICROBIT_ID_IO_P16, + //% blockIdentity="pins.analogPin" //% block="P19 (write only)" //% blockHidden=1 P19 = MICROBIT_ID_IO_P19, + //% blockIdentity="pins.analogPin" //% block="P20 (write only)" //% blockHidden=1 P20 = MICROBIT_ID_IO_P20 @@ -154,9 +192,8 @@ namespace pins { */ //% help=pins/digital-read-pin weight=30 //% blockId=device_get_digital_pin block="digital read|pin %name" blockGap=8 - //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" - int digitalReadPin(DigitalPin name) { + //% name.shadow=digital_pin + int digitalReadPin(int name) { PINREAD(getDigitalValue()); } @@ -168,9 +205,8 @@ namespace pins { //% help=pins/digital-write-pin weight=29 //% blockId=device_set_digital_pin block="digital write|pin %name|to %value" //% value.min=0 value.max=1 - //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" - void digitalWritePin(DigitalPin name, int value) { + //% name.shadow=digital_pin + void digitalWritePin(int name, int value) { PINOP(setDigitalValue(value)); } @@ -180,9 +216,8 @@ namespace pins { */ //% help=pins/analog-read-pin weight=25 //% blockId=device_get_analog_pin block="analog read|pin %name" blockGap="8" - //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" - int analogReadPin(AnalogPin name) { + //% name.shadow=analog_pin + int analogReadPin(int name) { PINREAD(getAnalogValue()); } @@ -194,9 +229,8 @@ namespace pins { //% help=pins/analog-write-pin weight=24 //% blockId=device_set_analog_pin block="analog write|pin %name|to %value" blockGap=8 //% value.min=0 value.max=1023 - //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" - void analogWritePin(AnalogPin name, int value) { + //% name.shadow=analog_pin + void analogWritePin(int name, int value) { PINOP(setAnalogValue(value)); } @@ -208,9 +242,8 @@ namespace pins { */ //% help=pins/analog-set-period weight=23 blockGap=8 //% blockId=device_set_analog_period block="analog set period|pin %pin|to (µs)%micros" - //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 - //% pin.fieldOptions.tooltips="false" - void analogSetPeriod(AnalogPin name, int micros) { + //% pin.shadow=analog_pin + void analogSetPeriod(int name, int micros) { PINOP(setAnalogPeriodUs(micros)); } @@ -221,12 +254,11 @@ namespace pins { */ //% help=pins/on-pulsed advanced=true //% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse" - //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 - //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" + //% pin.shadow=digital_pin //% group="Pulse" //% weight=25 //% blockGap=8 - void onPulsed(DigitalPin name, PulseValue pulse, Action body) { + void onPulsed(int name, PulseValue pulse, Action body) { MicroBitPin* pin = getPin((int)name); if (!pin) return; @@ -255,12 +287,11 @@ namespace pins { //% blockId="pins_pulse_in" block="pulse in (µs)|pin %name|pulsed %value" //% advanced=true //% help=pins/pulse-in - //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% name.shadow=digital_pin //% group="Pulse" //% weight=23 //% blockGap=8 - int pulseIn(DigitalPin name, PulseValue value, int maxDuration = 2000000) { + int pulseIn(int name, PulseValue value, int maxDuration = 2000000) { MicroBitPin* pin = getPin((int)name); if (!pin) return 0; @@ -302,10 +333,9 @@ namespace pins { //% blockId=device_set_servo_pin block="servo write|pin %name|to %value" blockGap=8 //% parts=microservo trackArgs=0 //% value.min=0 value.max=180 - //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% name.shadow=analog_pin //% group="Servo" - void servoWritePin(AnalogPin name, int value) { + void servoWritePin(int name, int value) { PINOP(setServoValue(value)); } @@ -313,7 +343,7 @@ namespace pins { * Specifies that a continuous servo is connected. */ //% - void servoSetContinuous(AnalogPin name, bool value) { + void servoSetContinuous(int name, bool value) { // handled in simulator } @@ -324,10 +354,9 @@ namespace pins { */ //% help=pins/servo-set-pulse weight=19 //% blockId=device_set_servo_pulse block="servo set pulse|pin %value|to (µs) %micros" - //% value.fieldEditor="gridpicker" value.fieldOptions.columns=4 - //% value.fieldOptions.tooltips="false" value.fieldOptions.width="250" + //% value.shadow=analog_pin //% group="Servo" - void servoSetPulse(AnalogPin name, int micros) { + void servoSetPulse(int name, int micros) { PINOP(setServoPulseUs(micros)); } @@ -343,12 +372,11 @@ namespace pins { */ //% blockId=device_analog_set_pitch_pin block="analog set pitch pin %name" //% help=pins/analog-set-pitch-pin advanced=true - //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% name.shadow=analog_pin //% group="Pins" //% weight=12 //% blockGap=8 - void analogSetPitchPin(AnalogPin name) { + void analogSetPitchPin(int name) { pitchPin = getPin((int)name); } @@ -447,12 +475,11 @@ namespace pins { */ //% help=pins/set-pull advanced=true //% blockId=device_set_pull block="set pull|pin %pin|to %pull" - //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 - //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" + //% pin.shadow=digital_pin //% group="Pins" //% weight=15 //% blockGap=8 - void setPull(DigitalPin name, PinPullMode pull) { + void setPull(int name, PinPullMode pull) { #if MICROBIT_CODAL codal::PullMode m = pull == PinPullMode::PullDown ? codal::PullMode::Down @@ -476,12 +503,11 @@ namespace pins { */ //% help=pins/set-events advanced=true //% blockId=device_set_pin_events block="set pin %pin|to emit %type|events" - //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 - //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" + //% pin.shadow=digital_pin //% group="Pins" //% weight=13 //% blockGap=8 - void setEvents(DigitalPin name, PinEventType type) { + void setEvents(int name, PinEventType type) { getPin((int)name)->eventOn((int)type); } @@ -504,13 +530,12 @@ namespace pins { */ //% help=pins/neopixel-matrix-width advanced=true //% blockId=pin_neopixel_matrix_width block="neopixel matrix width|pin %pin %width" - //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 - //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" + //% pin.shadow=digital_pin //% width.defl=5 width.min=2 //% group="Pins" //% weight=11 //% blockGap=8 - void setMatrixWidth(DigitalPin pin, int width) {} + void setMatrixWidth(int pin, int width) {} #if MICROBIT_CODAL #define BUFFER_TYPE uint8_t* @@ -624,16 +649,13 @@ namespace pins { */ //% help=pins/spi-pins advanced=true //% blockId=spi_pins block="spi set pins|MOSI %mosi|MISO %miso|SCK %sck" - //% mosi.fieldEditor="gridpicker" mosi.fieldOptions.columns=4 - //% mosi.fieldOptions.tooltips="false" mosi.fieldOptions.width="250" - //% miso.fieldEditor="gridpicker" miso.fieldOptions.columns=4 - //% miso.fieldOptions.tooltips="false" miso.fieldOptions.width="250" - //% sck.fieldEditor="gridpicker" sck.fieldOptions.columns=4 - //% sck.fieldOptions.tooltips="false" sck.fieldOptions.width="250" + //% mosi.shadow=digital_pin + //% miso.shadow=digital_pin + //% sck.shadow=digital_pin //% group="SPI" //% blockGap=8 //% weight=51 - void spiPins(DigitalPin mosi, DigitalPin miso, DigitalPin sck) { + void spiPins(int mosi, int miso, int sck) { if (NULL != spi) { delete spi; spi = NULL; @@ -645,7 +667,7 @@ namespace pins { * Mounts a push button on the given pin */ //% help=pins/push-button advanced=true - void pushButton(DigitalPin pin) { + void pushButton(int pin) { new MicroBitButton((PinName)getPin((int)(pin))->name, (int)pin, MICROBIT_BUTTON_ALL_EVENTS, PinMode::PullUp); } @@ -655,11 +677,10 @@ namespace pins { */ //% blockId=pin_set_audio_pin block="set audio pin $name" //% help=pins/set-audio-pin - //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% name.shadow=digital_pin //% weight=1 //% blockGap=8 - void setAudioPin(AnalogPin name) { + void setAudioPin(int name) { #if MICROBIT_CODAL uBit.audio.setPin(*getPin((int)name)); uBit.audio.setPinEnabled(!edgeConnectorSoundDisabled); diff --git a/libs/core/pins.ts b/libs/core/pins.ts index cfe96ddcdfc..6ab60cb0c11 100644 --- a/libs/core/pins.ts +++ b/libs/core/pins.ts @@ -5,6 +5,32 @@ //% advanced=true //% groups='["Pins", "Pulse", "I2C", "SPI", "micro:bit (V2)"]' namespace pins { + /** + * Returns the value of a C++ runtime constant + */ + //% help=pins/digital-pin blockGap=8 advanced=true shim=TD_ID + //% blockId="digital_pin" block="digital pin %pin" + //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 + //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" + //% group="Pins" + //% weight=17 + export function digitalPin(pin: DigitalPin): number { + return pin; + } + + /** + * Returns the value of a C++ runtime constant + */ + //% help=pins/analog-pin blockGap=8 advanced=true shim=TD_ID + //% blockId="analog_pin" block="analog pin %pin" + //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 + //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" + //% group="Pins" + //% weight=16 + export function analogPin(pin: AnalogPin): number { + return pin; + } + /** * Map a number from one range to another. That is, a value of ``from low`` would get mapped to ``to low``, a value of ``from high`` to ``to high``, values in-between to values in-between, etc. * @param value value to map in ranges diff --git a/libs/core/shims.d.ts b/libs/core/shims.d.ts index 40214d5ed4e..6a7e7ec2163 100644 --- a/libs/core/shims.d.ts +++ b/libs/core/shims.d.ts @@ -705,9 +705,8 @@ declare namespace pins { */ //% help=pins/digital-read-pin weight=30 //% blockId=device_get_digital_pin block="digital read|pin %name" blockGap=8 - //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" shim=pins::digitalReadPin - function digitalReadPin(name: DigitalPin): int32; + //% name.shadow=digital_pin shim=pins::digitalReadPin + function digitalReadPin(name: int32): int32; /** * Set a pin or connector value to either 0 or 1. @@ -717,9 +716,8 @@ declare namespace pins { //% help=pins/digital-write-pin weight=29 //% blockId=device_set_digital_pin block="digital write|pin %name|to %value" //% value.min=0 value.max=1 - //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" shim=pins::digitalWritePin - function digitalWritePin(name: DigitalPin, value: int32): void; + //% name.shadow=digital_pin shim=pins::digitalWritePin + function digitalWritePin(name: int32, value: int32): void; /** * Read the connector value as analog, that is, as a value comprised between 0 and 1023. @@ -727,9 +725,8 @@ declare namespace pins { */ //% help=pins/analog-read-pin weight=25 //% blockId=device_get_analog_pin block="analog read|pin %name" blockGap="8" - //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" shim=pins::analogReadPin - function analogReadPin(name: AnalogPin): int32; + //% name.shadow=analog_pin shim=pins::analogReadPin + function analogReadPin(name: int32): int32; /** * Set the connector value as analog. Value must be comprised between 0 and 1023. @@ -739,9 +736,8 @@ declare namespace pins { //% help=pins/analog-write-pin weight=24 //% blockId=device_set_analog_pin block="analog write|pin %name|to %value" blockGap=8 //% value.min=0 value.max=1023 - //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" shim=pins::analogWritePin - function analogWritePin(name: AnalogPin, value: int32): void; + //% name.shadow=analog_pin shim=pins::analogWritePin + function analogWritePin(name: int32, value: int32): void; /** * Configure the pulse-width modulation (PWM) period of the analog output in microseconds. @@ -751,9 +747,8 @@ declare namespace pins { */ //% help=pins/analog-set-period weight=23 blockGap=8 //% blockId=device_set_analog_period block="analog set period|pin %pin|to (µs)%micros" - //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 - //% pin.fieldOptions.tooltips="false" shim=pins::analogSetPeriod - function analogSetPeriod(name: AnalogPin, micros: int32): void; + //% pin.shadow=analog_pin shim=pins::analogSetPeriod + function analogSetPeriod(name: int32, micros: int32): void; /** * Configure the pin as a digital input and generate an event when the pin is pulsed either high or low. @@ -762,12 +757,11 @@ declare namespace pins { */ //% help=pins/on-pulsed advanced=true //% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse" - //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 - //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" + //% pin.shadow=digital_pin //% group="Pulse" //% weight=25 //% blockGap=8 shim=pins::onPulsed - function onPulsed(name: DigitalPin, pulse: PulseValue, body: () => void): void; + function onPulsed(name: int32, pulse: PulseValue, body: () => void): void; /** * Get the duration of the last pulse in microseconds. This function should be called from a ``onPulsed`` handler. @@ -788,12 +782,11 @@ declare namespace pins { //% blockId="pins_pulse_in" block="pulse in (µs)|pin %name|pulsed %value" //% advanced=true //% help=pins/pulse-in - //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% name.shadow=digital_pin //% group="Pulse" //% weight=23 //% blockGap=8 maxDuration.defl=2000000 shim=pins::pulseIn - function pulseIn(name: DigitalPin, value: PulseValue, maxDuration?: int32): int32; + function pulseIn(name: int32, value: PulseValue, maxDuration?: int32): int32; /** * Write a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement). @@ -804,16 +797,15 @@ declare namespace pins { //% blockId=device_set_servo_pin block="servo write|pin %name|to %value" blockGap=8 //% parts=microservo trackArgs=0 //% value.min=0 value.max=180 - //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% name.shadow=analog_pin //% group="Servo" shim=pins::servoWritePin - function servoWritePin(name: AnalogPin, value: int32): void; + function servoWritePin(name: int32, value: int32): void; /** * Specifies that a continuous servo is connected. */ //% shim=pins::servoSetContinuous - function servoSetContinuous(name: AnalogPin, value: boolean): void; + function servoSetContinuous(name: int32, value: boolean): void; /** * Configure the IO pin as an analog/pwm output and set a pulse width. The period is 20 ms period and the pulse width is set based on the value given in **microseconds** or `1/1000` milliseconds. @@ -822,10 +814,9 @@ declare namespace pins { */ //% help=pins/servo-set-pulse weight=19 //% blockId=device_set_servo_pulse block="servo set pulse|pin %value|to (µs) %micros" - //% value.fieldEditor="gridpicker" value.fieldOptions.columns=4 - //% value.fieldOptions.tooltips="false" value.fieldOptions.width="250" + //% value.shadow=analog_pin //% group="Servo" shim=pins::servoSetPulse - function servoSetPulse(name: AnalogPin, micros: int32): void; + function servoSetPulse(name: int32, micros: int32): void; /** * Set the pin used when using analog pitch or music. @@ -833,12 +824,11 @@ declare namespace pins { */ //% blockId=device_analog_set_pitch_pin block="analog set pitch pin %name" //% help=pins/analog-set-pitch-pin advanced=true - //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% name.shadow=analog_pin //% group="Pins" //% weight=12 //% blockGap=8 shim=pins::analogSetPitchPin - function analogSetPitchPin(name: AnalogPin): void; + function analogSetPitchPin(name: int32): void; /** * Sets the volume on the pitch pin @@ -877,12 +867,11 @@ declare namespace pins { */ //% help=pins/set-pull advanced=true //% blockId=device_set_pull block="set pull|pin %pin|to %pull" - //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 - //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" + //% pin.shadow=digital_pin //% group="Pins" //% weight=15 //% blockGap=8 shim=pins::setPull - function setPull(name: DigitalPin, pull: PinPullMode): void; + function setPull(name: int32, pull: PinPullMode): void; /** * Configure the events emitted by this pin. Events can be subscribed to @@ -892,12 +881,11 @@ declare namespace pins { */ //% help=pins/set-events advanced=true //% blockId=device_set_pin_events block="set pin %pin|to emit %type|events" - //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 - //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" + //% pin.shadow=digital_pin //% group="Pins" //% weight=13 //% blockGap=8 shim=pins::setEvents - function setEvents(name: DigitalPin, type: PinEventType): void; + function setEvents(name: int32, type: PinEventType): void; /** * Create a new zero-initialized buffer. @@ -914,13 +902,12 @@ declare namespace pins { */ //% help=pins/neopixel-matrix-width advanced=true //% blockId=pin_neopixel_matrix_width block="neopixel matrix width|pin %pin %width" - //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 - //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" + //% pin.shadow=digital_pin //% width.min=2 //% group="Pins" //% weight=11 //% blockGap=8 width.defl=5 shim=pins::setMatrixWidth - function setMatrixWidth(pin: DigitalPin, width?: int32): void; + function setMatrixWidth(pin: int32, width?: int32): void; /** * Read `size` bytes from a 7-bit I2C `address`. @@ -982,22 +969,19 @@ declare namespace pins { */ //% help=pins/spi-pins advanced=true //% blockId=spi_pins block="spi set pins|MOSI %mosi|MISO %miso|SCK %sck" - //% mosi.fieldEditor="gridpicker" mosi.fieldOptions.columns=4 - //% mosi.fieldOptions.tooltips="false" mosi.fieldOptions.width="250" - //% miso.fieldEditor="gridpicker" miso.fieldOptions.columns=4 - //% miso.fieldOptions.tooltips="false" miso.fieldOptions.width="250" - //% sck.fieldEditor="gridpicker" sck.fieldOptions.columns=4 - //% sck.fieldOptions.tooltips="false" sck.fieldOptions.width="250" + //% mosi.shadow=digital_pin + //% miso.shadow=digital_pin + //% sck.shadow=digital_pin //% group="SPI" //% blockGap=8 //% weight=51 shim=pins::spiPins - function spiPins(mosi: DigitalPin, miso: DigitalPin, sck: DigitalPin): void; + function spiPins(mosi: int32, miso: int32, sck: int32): void; /** * Mounts a push button on the given pin */ //% help=pins/push-button advanced=true shim=pins::pushButton - function pushButton(pin: DigitalPin): void; + function pushButton(pin: int32): void; /** * Set the pin used when producing sounds and melodies. Default is P0. @@ -1005,11 +989,10 @@ declare namespace pins { */ //% blockId=pin_set_audio_pin block="set audio pin $name" //% help=pins/set-audio-pin - //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4 - //% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" + //% name.shadow=digital_pin //% weight=1 //% blockGap=8 shim=pins::setAudioPin - function setAudioPin(name: AnalogPin): void; + function setAudioPin(name: int32): void; /** * Sets whether or not audio will be output using a pin on the edge