adding SPI support
This commit is contained in:
parent
64d584681a
commit
c99138b02e
@ -17,6 +17,7 @@ pins.servoWritePin(AnalogPin.P0, 180);
|
||||
pins.servoSetPulse(AnalogPin.P0, 1500);
|
||||
pins.i2cReadNumber(0, NumberFormat.Int8LE);
|
||||
pins.i2cWriteNumber(0, 0, NumberFormat.Int8LE);
|
||||
pins.spiWrite(0);
|
||||
pins.setPull(DigitalPin.P0, PinPullMode.PullDown);
|
||||
pins.analogPitch(0, 0);
|
||||
pins.analogSetPitchPin(AnalogPin.P0);
|
||||
@ -24,4 +25,4 @@ pins.analogSetPitchPin(AnalogPin.P0);
|
||||
|
||||
### See Also
|
||||
|
||||
[digitalReadPin](/reference/pins/digital-read-pin), [digitalWritePin](/reference/pins/digital-write-pin), [analogReadPin](/reference/pins/analog-read-pin), [analogWritePin](/reference/pins/analog-write-pin), [analogSetPeriod](/reference/pins/analog-set-period), [map](/reference/pins/map), [onPulsed](/reference/pins/on-pulsed), [pulseDuration](/reference/pins/pulse-duration), [servoWritePin](/reference/pins/servo-write-pin), [servoSetPulse](/reference/pins/servo-set-pulse), [i2cReadNumber](/reference/pins/i2c-read-number), [i2cWriteNumber](/reference/pins/i2c-write-number), [setPull](/reference/pins/set-pull), [analogPitch](/reference/pins/analog-pitch), [analogSetPitchPin](/reference/pins/analog-set-pitch)
|
||||
[digitalReadPin](/reference/pins/digital-read-pin), [digitalWritePin](/reference/pins/digital-write-pin), [analogReadPin](/reference/pins/analog-read-pin), [analogWritePin](/reference/pins/analog-write-pin), [analogSetPeriod](/reference/pins/analog-set-period), [map](/reference/pins/map), [onPulsed](/reference/pins/on-pulsed), [pulseDuration](/reference/pins/pulse-duration), [servoWritePin](/reference/pins/servo-write-pin), [servoSetPulse](/reference/pins/servo-set-pulse), [i2cReadNumber](/reference/pins/i2c-read-number), [i2cWriteNumber](/reference/pins/i2c-write-number), [setPull](/reference/pins/set-pull), [analogPitch](/reference/pins/analog-pitch), [analogSetPitchPin](/reference/pins/analog-set-pitch), [spiWrite](/reference/pins/spi-write)
|
||||
|
19
docs/reference/pins/spi-write.md
Normal file
19
docs/reference/pins/spi-write.md
Normal file
@ -0,0 +1,19 @@
|
||||
# SPI Write
|
||||
|
||||
Write to the SPI Slave and return the response.
|
||||
|
||||
```sig
|
||||
pins.spiWrite(0);
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``value``: value Data to be sent to the SPI slave
|
||||
|
||||
### Returns
|
||||
|
||||
* a [number](/reference/types/number) Response from the SPI slave
|
||||
|
||||
### See also
|
||||
|
||||
[SPI](https://developer.mbed.org/handbook/SPI)
|
2
libs/microbit/enums.d.ts
vendored
2
libs/microbit/enums.d.ts
vendored
@ -288,8 +288,6 @@ declare namespace led {
|
||||
//% block="none"
|
||||
PullNone = 2,
|
||||
}
|
||||
declare namespace pins {
|
||||
}
|
||||
|
||||
|
||||
declare enum SerialPin {
|
||||
|
@ -71,7 +71,6 @@ MicroBitPin *getPin(int id) {
|
||||
}
|
||||
|
||||
|
||||
//% color=351 weight=30
|
||||
namespace pins {
|
||||
#define PINOP(op) \
|
||||
MicroBitPin *pin = getPin((int)name); \
|
||||
@ -268,4 +267,23 @@ namespace pins {
|
||||
{
|
||||
uBit.i2c.write(address << 1, (char*)buf->payload, buf->length, repeat);
|
||||
}
|
||||
|
||||
SPI* spi = NULL;
|
||||
SPI* allocSPI() {
|
||||
if (spi == NULL)
|
||||
spi = new SPI(MOSI, MISO, SCK);
|
||||
return spi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to the SPI slave and return the response
|
||||
* @param value Data to be sent to the SPI slave
|
||||
*/
|
||||
//% help=pins/spi-write weight=5
|
||||
//% blockId=spi_write block="spi write %value"
|
||||
int spiWrite(int value) {
|
||||
auto p = allocSPI();
|
||||
return p->write(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ namespace pins {
|
||||
/**
|
||||
* Write one number to a 7-bit I2C address.
|
||||
*/
|
||||
//% help=pins/i2c-write-number
|
||||
//% help=pins/i2c-write-number blockGap=8
|
||||
//% 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 {
|
||||
let buf = createBuffer(pins.sizeOf(format))
|
||||
|
12
libs/microbit/shims.d.ts
vendored
12
libs/microbit/shims.d.ts
vendored
@ -448,10 +448,6 @@ declare namespace led {
|
||||
//% help=led/screenshot shim=led::screenshot
|
||||
function screenshot(): Image;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//% color=351 weight=30
|
||||
declare namespace pins {
|
||||
|
||||
/**
|
||||
@ -573,6 +569,14 @@ declare namespace pins {
|
||||
*/
|
||||
//% repeat.defl=0 shim=pins::i2cWriteBuffer
|
||||
function i2cWriteBuffer(address: number, buf: Buffer, repeat?: boolean): void;
|
||||
|
||||
/**
|
||||
* Write to the SPI slave and return the response
|
||||
* @param value Data to be sent to the SPI slave
|
||||
*/
|
||||
//% help=pins/spi-write weight=5
|
||||
//% blockId=spi_write block="spi write %value" shim=pins::spiWrite
|
||||
function spiWrite(value: number): number;
|
||||
}
|
||||
|
||||
|
||||
|
@ -588,6 +588,11 @@ namespace pxsim.pins {
|
||||
// TODO
|
||||
}
|
||||
|
||||
export function spiWrite(value: number): number {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function i2cReadBuffer(address: number, size: number, repeat?: boolean): RefBuffer {
|
||||
// fake reading zeros
|
||||
return createBuffer(size)
|
||||
|
Loading…
Reference in New Issue
Block a user