SakuraIO
Fork of SakuraIO by
SakuraIO_SPI.cpp@0:8d34375d954c, 2016-11-19 (annotated)
- Committer:
- spiralray
- Date:
- Sat Nov 19 03:20:17 2016 +0000
- Revision:
- 0:8d34375d954c
- Child:
- 3:c54a1eba22c4
First commit(This only works with SPI)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
spiralray | 0:8d34375d954c | 1 | #include "mbed.h" |
spiralray | 0:8d34375d954c | 2 | #include "SakuraIO.h" |
spiralray | 0:8d34375d954c | 3 | #include "SakuraIO/debug.h" |
spiralray | 0:8d34375d954c | 4 | |
spiralray | 0:8d34375d954c | 5 | |
spiralray | 0:8d34375d954c | 6 | void SakuraIO_SPI::begin(){ |
spiralray | 0:8d34375d954c | 7 | dbgln("CS=0"); |
spiralray | 0:8d34375d954c | 8 | cs = 0; |
spiralray | 0:8d34375d954c | 9 | } |
spiralray | 0:8d34375d954c | 10 | |
spiralray | 0:8d34375d954c | 11 | void SakuraIO_SPI::end(){ |
spiralray | 0:8d34375d954c | 12 | dbgln("CS=1"); |
spiralray | 0:8d34375d954c | 13 | cs = 1; |
spiralray | 0:8d34375d954c | 14 | wait_us(20); |
spiralray | 0:8d34375d954c | 15 | } |
spiralray | 0:8d34375d954c | 16 | |
spiralray | 0:8d34375d954c | 17 | void SakuraIO_SPI::sendByte(uint8_t data){ |
spiralray | 0:8d34375d954c | 18 | wait_us(20); |
spiralray | 0:8d34375d954c | 19 | dbg("Send="); |
spiralray | 0:8d34375d954c | 20 | dbgln(data); |
spiralray | 0:8d34375d954c | 21 | wait_us(10); |
spiralray | 0:8d34375d954c | 22 | spi.write(data); |
spiralray | 0:8d34375d954c | 23 | } |
spiralray | 0:8d34375d954c | 24 | |
spiralray | 0:8d34375d954c | 25 | |
spiralray | 0:8d34375d954c | 26 | uint8_t SakuraIO_SPI::receiveByte(bool stop){ |
spiralray | 0:8d34375d954c | 27 | return receiveByte(); |
spiralray | 0:8d34375d954c | 28 | } |
spiralray | 0:8d34375d954c | 29 | |
spiralray | 0:8d34375d954c | 30 | uint8_t SakuraIO_SPI::receiveByte(){ |
spiralray | 0:8d34375d954c | 31 | uint8_t ret; |
spiralray | 0:8d34375d954c | 32 | wait_us(10); |
spiralray | 0:8d34375d954c | 33 | ret = spi.write(0x00); |
spiralray | 0:8d34375d954c | 34 | dbg("Recv="); |
spiralray | 0:8d34375d954c | 35 | dbgln(ret); |
spiralray | 0:8d34375d954c | 36 | return ret; |
spiralray | 0:8d34375d954c | 37 | } |
spiralray | 0:8d34375d954c | 38 | |
spiralray | 0:8d34375d954c | 39 | SakuraIO_SPI::SakuraIO_SPI(SPI &_spi, DigitalOut &_cs): spi(_spi), cs(_cs){ |
spiralray | 0:8d34375d954c | 40 | cs = 1; |
spiralray | 0:8d34375d954c | 41 | } |