Fork of RTOS_SPI that removes SimpleDMA from direct include to correct linker issues when using SimpleDMA twice Note that this library is still required!
Fork of RTOS_SPI by
RTOS_SPI_KL46.cpp@5:f6a414f1f342, 2014-08-19 (annotated)
- Committer:
- Tomo2k
- Date:
- Tue Aug 19 16:47:40 2014 +0000
- Revision:
- 5:f6a414f1f342
- Parent:
- 2:d052724e2ad6
Removed SimpleDMA due to linker trouble; This library is still required but not directly included
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Tomo2k | 2:d052724e2ad6 | 1 | #ifdef TARGET_KL46Z |
Tomo2k | 2:d052724e2ad6 | 2 | #include "RTOS_SPI.h" |
Tomo2k | 2:d052724e2ad6 | 3 | |
Tomo2k | 2:d052724e2ad6 | 4 | RTOS_SPI::RTOS_SPI(PinName mosi, PinName miso, PinName sclk, PinName _unused) : SPI(mosi, miso, sclk) { |
Tomo2k | 2:d052724e2ad6 | 5 | if (_spi.spi == SPI0) { |
Tomo2k | 2:d052724e2ad6 | 6 | read_dma.trigger(Trigger_SPI0_RX); |
Tomo2k | 2:d052724e2ad6 | 7 | write_dma.trigger(Trigger_SPI0_TX); |
Tomo2k | 2:d052724e2ad6 | 8 | } else { |
Tomo2k | 2:d052724e2ad6 | 9 | read_dma.trigger(Trigger_SPI1_RX); |
Tomo2k | 2:d052724e2ad6 | 10 | write_dma.trigger(Trigger_SPI1_TX); |
Tomo2k | 2:d052724e2ad6 | 11 | } |
Tomo2k | 2:d052724e2ad6 | 12 | |
Tomo2k | 2:d052724e2ad6 | 13 | read_dma.source(&_spi.spi->DL, false); // 8-bit SPI only uses the LSB |
Tomo2k | 2:d052724e2ad6 | 14 | write_dma.destination(&_spi.spi->DL, false); // 8-bit SPI only uses the LSB |
Tomo2k | 2:d052724e2ad6 | 15 | }; |
Tomo2k | 2:d052724e2ad6 | 16 | |
Tomo2k | 2:d052724e2ad6 | 17 | void RTOS_SPI::bulkInternal(uint8_t *read_data, const uint8_t *write_data, int length, bool read_inc, bool write_inc) { |
Tomo2k | 2:d052724e2ad6 | 18 | aquire(); |
Tomo2k | 2:d052724e2ad6 | 19 | _spi.spi->C2 |= SPI_C2_TXDMAE_MASK | SPI_C2_RXDMAE_MASK; |
Tomo2k | 2:d052724e2ad6 | 20 | |
Tomo2k | 2:d052724e2ad6 | 21 | read_dma.destination(read_data, read_inc); |
Tomo2k | 2:d052724e2ad6 | 22 | if (write_inc) |
Tomo2k | 2:d052724e2ad6 | 23 | write_dma.source(write_data+1, write_inc); |
Tomo2k | 2:d052724e2ad6 | 24 | else |
Tomo2k | 2:d052724e2ad6 | 25 | write_dma.source(write_data, write_inc); |
Tomo2k | 2:d052724e2ad6 | 26 | |
Tomo2k | 2:d052724e2ad6 | 27 | //simply start the read_dma |
Tomo2k | 2:d052724e2ad6 | 28 | read_dma.start(length); |
Tomo2k | 2:d052724e2ad6 | 29 | |
Tomo2k | 2:d052724e2ad6 | 30 | //Write the first byte manually, since this is recommended method (and the normal method sends the first byte twice) |
Tomo2k | 2:d052724e2ad6 | 31 | while((_spi.spi->S & SPI_S_SPTEF_MASK) == 0); |
Tomo2k | 2:d052724e2ad6 | 32 | _spi.spi->DL = write_data[0]; // 8-bit SPI only uses the LSB |
Tomo2k | 2:d052724e2ad6 | 33 | |
Tomo2k | 2:d052724e2ad6 | 34 | write_dma.wait(length-1); |
Tomo2k | 2:d052724e2ad6 | 35 | while(read_dma.isBusy()); |
Tomo2k | 2:d052724e2ad6 | 36 | |
Tomo2k | 2:d052724e2ad6 | 37 | _spi.spi->C2 &= ~(SPI_C2_TXDMAE_MASK | SPI_C2_RXDMAE_MASK); |
Tomo2k | 2:d052724e2ad6 | 38 | } |
Tomo2k | 2:d052724e2ad6 | 39 | #endif |