diff --git a/docs/reference/pins/i2c-read-number.md b/docs/reference/pins/i2c-read-number.md index bbd7df7b..973db55e 100644 --- a/docs/reference/pins/i2c-read-number.md +++ b/docs/reference/pins/i2c-read-number.md @@ -4,7 +4,7 @@ Read one number from the specified 7-bit I2C address, in the specified number format. ```sig -pins.i2cReadNumber(0, NumberFormat.Int8LE); +pins.i2cReadNumber(0, NumberFormat.Int8LE, false); ``` ### Parameters @@ -17,6 +17,7 @@ pins.i2cReadNumber(0, NumberFormat.Int8LE); * **Int** stands for "integer", and **UInt** stands for "unsigned integer". * **LE** stands for "little-endian" and **BE** stands for "big-endian". * The number in each format name stands for the number of bits in the format. +* ``repeated`` repeated start, true - don't send stop at end ### Example @@ -24,7 +25,7 @@ The following example reads a number in big-endian, 16-bit, unsigned integer format from the 7-bit I2C address `32`. ```blocks -pins.i2cReadNumber(32, NumberFormat.UInt16BE); +pins.i2cReadNumber(32, NumberFormat.UInt16BE, false); ``` #### ~hint diff --git a/docs/reference/pins/i2c-write-number.md b/docs/reference/pins/i2c-write-number.md index b386b257..6158fc9e 100644 --- a/docs/reference/pins/i2c-write-number.md +++ b/docs/reference/pins/i2c-write-number.md @@ -4,7 +4,7 @@ Write the specified number to the specified 7-bit I2C address in the specified number format. ```sig -pins.i2cWriteNumber(0, 0, NumberFormat.Int8LE); +pins.i2cWriteNumber(0, 0, NumberFormat.Int8LE, true); ``` ### Parameters @@ -18,6 +18,7 @@ pins.i2cWriteNumber(0, 0, NumberFormat.Int8LE); * **Int** stands for "integer", and **UInt** stands for "unsigned integer". * **LE** stands for "little-endian" and **BE** stands for "big-endian". * The number in each format name stands for the number of bits in the format. +* ``repeated`` repeated start, true - don't send stop at end ### Example diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index b254d3e7..cb5f38ea 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -250,8 +250,8 @@ "pins.analogWritePin|block": "analog write|pin %name|to %value", "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=i2c_sizeof", - "pins.i2cWriteNumber|block": "i2c write number|at address %address|with value %value|of format %format=i2c_sizeof", + "pins.i2cReadNumber|block": "i2c read number|at address %address|of format %format=i2c_sizeof|repeated %repeat", + "pins.i2cWriteNumber|block": "i2c write number|at address %address|with value %value|of format %format=i2c_sizeof|repeated %repeat", "pins.map|block": "map %value|from low %fromLow|from high %fromHigh|to low %toLow|to high %toHigh", "pins.onPulsed|block": "on|pin %pin|pulsed %pulse", "pins.pulseDuration|block": "pulse duration (µs)", diff --git a/libs/core/pins.ts b/libs/core/pins.ts index a4027824..aee682d4 100644 --- a/libs/core/pins.ts +++ b/libs/core/pins.ts @@ -22,9 +22,9 @@ namespace pins { * Read one number from 7-bit I2C address. */ //% help=pins/i2c-read-number blockGap=8 advanced=true - //% blockId=pins_i2c_readnumber block="i2c read number|at address %address|of format %format=i2c_sizeof" weight=7 - export function i2cReadNumber(address: number, format: NumberFormat): number { - let buf = pins.i2cReadBuffer(address, pins.sizeOf(format)) + //% blockId=pins_i2c_readnumber block="i2c read number|at address %address|of format %format=i2c_sizeof|repeated %repeat" weight=7 + export function i2cReadNumber(address: number, format: NumberFormat, repeated?: boolean): number { + let buf = pins.i2cReadBuffer(address, pins.sizeOf(format), repeated) return buf.getNumber(format, 0) } @@ -32,11 +32,11 @@ namespace pins { * Write one number to a 7-bit I2C address. */ //% help=pins/i2c-write-number blockGap=8 advanced=true - //% blockId=i2c_writenumber block="i2c write number|at address %address|with value %value|of format %format=i2c_sizeof" weight=6 - export function i2cWriteNumber(address: number, value: number, format: NumberFormat): void { + //% blockId=i2c_writenumber block="i2c write number|at address %address|with value %value|of format %format=i2c_sizeof|repeated %repeat" weight=6 + export function i2cWriteNumber(address: number, value: number, format: NumberFormat, repeated?: boolean): void { let buf = createBuffer(pins.sizeOf(format)) buf.setNumber(format, 0, value) - pins.i2cWriteBuffer(address, buf) + pins.i2cWriteBuffer(address, buf, repeated) } /** diff --git a/tests/i2c.ts b/tests/i2c.ts new file mode 100644 index 00000000..f106621f --- /dev/null +++ b/tests/i2c.ts @@ -0,0 +1,6 @@ + +let item = pins.i2cReadNumber(123, NumberFormat.Int8LE) +pins.i2cWriteNumber(123, 0, NumberFormat.Int8LE) + +let item2 = pins.i2cReadNumber(123, NumberFormat.Int8LE, true) +pins.i2cWriteNumber(123, 0, NumberFormat.Int8LE, true)