mbed-os
Fork of mbed-os by
features/unsupported/tests/libs/SPIHalfDuplex/SPIHalfDuplex.cpp@1:3deb71413561, 2017-07-20 (annotated)
- Committer:
- xuaner
- Date:
- Thu Jul 20 14:26:57 2017 +0000
- Revision:
- 1:3deb71413561
- Parent:
- 0:f269e3021894
mbed_os
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | /* mbed Microcontroller Library - SPIHalfDuplex |
elessair | 0:f269e3021894 | 2 | * Copyright (c) 2010-2011 ARM Limited. All rights reserved. |
elessair | 0:f269e3021894 | 3 | */ |
elessair | 0:f269e3021894 | 4 | #include "SPIHalfDuplex.h" |
elessair | 0:f269e3021894 | 5 | |
elessair | 0:f269e3021894 | 6 | #if DEVICE_SPI |
elessair | 0:f269e3021894 | 7 | |
elessair | 0:f269e3021894 | 8 | #include "spi_api.h" |
elessair | 0:f269e3021894 | 9 | #include "pinmap.h" |
elessair | 0:f269e3021894 | 10 | |
elessair | 0:f269e3021894 | 11 | #define GPIO_MODE 0 |
elessair | 0:f269e3021894 | 12 | #define SPI_MODE 2 |
elessair | 0:f269e3021894 | 13 | |
elessair | 0:f269e3021894 | 14 | namespace mbed { |
elessair | 0:f269e3021894 | 15 | |
elessair | 0:f269e3021894 | 16 | SPIHalfDuplex::SPIHalfDuplex(PinName mosi, PinName miso, PinName sclk) : SPI(mosi, miso, sclk) { |
elessair | 0:f269e3021894 | 17 | _mosi = mosi; |
elessair | 0:f269e3021894 | 18 | _miso = miso; |
elessair | 0:f269e3021894 | 19 | _sbits = _bits; |
elessair | 0:f269e3021894 | 20 | } |
elessair | 0:f269e3021894 | 21 | |
elessair | 0:f269e3021894 | 22 | void SPIHalfDuplex::slave_format(int sbits) { |
elessair | 0:f269e3021894 | 23 | _sbits = sbits; |
elessair | 0:f269e3021894 | 24 | } |
elessair | 0:f269e3021894 | 25 | |
elessair | 0:f269e3021894 | 26 | int SPIHalfDuplex::write(int value) { |
elessair | 0:f269e3021894 | 27 | int t_bits = _bits; |
elessair | 0:f269e3021894 | 28 | pin_function(_mosi, SPI_MODE); |
elessair | 0:f269e3021894 | 29 | int ret_val = SPI::write(value); |
elessair | 0:f269e3021894 | 30 | if (ret_val != value) { |
elessair | 0:f269e3021894 | 31 | return -1; |
elessair | 0:f269e3021894 | 32 | } |
elessair | 0:f269e3021894 | 33 | format(_sbits, _mode); |
elessair | 0:f269e3021894 | 34 | pin_function(_mosi, GPIO_MODE); |
elessair | 0:f269e3021894 | 35 | ret_val = SPI::write(0x55); |
elessair | 0:f269e3021894 | 36 | format(t_bits, _mode); |
elessair | 0:f269e3021894 | 37 | pin_function(_mosi, SPI_MODE); |
elessair | 0:f269e3021894 | 38 | return ret_val; |
elessair | 0:f269e3021894 | 39 | } |
elessair | 0:f269e3021894 | 40 | |
elessair | 0:f269e3021894 | 41 | } // end namespace mbed |
elessair | 0:f269e3021894 | 42 | |
elessair | 0:f269e3021894 | 43 | #endif |