Add support for KL46Z
Fork of BurstSPI by
BurstSPI.cpp@0:600eecd89a78, 2013-01-03 (annotated)
- Committer:
- Sissors
- Date:
- Thu Jan 03 09:14:10 2013 +0000
- Revision:
- 0:600eecd89a78
v1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sissors | 0:600eecd89a78 | 1 | #include "BurstSPI.h" |
Sissors | 0:600eecd89a78 | 2 | |
Sissors | 0:600eecd89a78 | 3 | BurstSPI::BurstSPI(PinName mosi, PinName miso, PinName sclk) : SPI(mosi, miso, sclk){ |
Sissors | 0:600eecd89a78 | 4 | |
Sissors | 0:600eecd89a78 | 5 | } |
Sissors | 0:600eecd89a78 | 6 | |
Sissors | 0:600eecd89a78 | 7 | |
Sissors | 0:600eecd89a78 | 8 | void BurstSPI::fastWrite(int data) { |
Sissors | 0:600eecd89a78 | 9 | //Wait until FIFO has space |
Sissors | 0:600eecd89a78 | 10 | while(((_spi.spi->SR) & 0x02) == 0); |
Sissors | 0:600eecd89a78 | 11 | |
Sissors | 0:600eecd89a78 | 12 | //transmit data |
Sissors | 0:600eecd89a78 | 13 | _spi.spi->DR = data; |
Sissors | 0:600eecd89a78 | 14 | } |
Sissors | 0:600eecd89a78 | 15 | |
Sissors | 0:600eecd89a78 | 16 | void BurstSPI::setFormat( void ) { |
Sissors | 0:600eecd89a78 | 17 | format(_bits, _mode); |
Sissors | 0:600eecd89a78 | 18 | frequency(_hz); |
Sissors | 0:600eecd89a78 | 19 | } |
Sissors | 0:600eecd89a78 | 20 | |
Sissors | 0:600eecd89a78 | 21 | void BurstSPI::clearRX( void ) { |
Sissors | 0:600eecd89a78 | 22 | //Do it while either data in RX buffer, or while it is busy |
Sissors | 0:600eecd89a78 | 23 | while(((_spi.spi->SR) & ((1<<4) + (1<<2))) != 0) { |
Sissors | 0:600eecd89a78 | 24 | //Wait until data in RX buffer |
Sissors | 0:600eecd89a78 | 25 | while(((_spi.spi->SR) & (1<<2)) == 0); |
Sissors | 0:600eecd89a78 | 26 | int dummy = _spi.spi->DR; |
Sissors | 0:600eecd89a78 | 27 | } |
Sissors | 0:600eecd89a78 | 28 | } |