Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: SPIDriver/SPIDriver.cpp
- Revision:
- 3:da30c350c339
- Parent:
- 2:f2700008c9d9
- Child:
- 4:a091b8f8216d
diff -r f2700008c9d9 -r da30c350c339 SPIDriver/SPIDriver.cpp
--- a/SPIDriver/SPIDriver.cpp Thu May 01 20:58:59 2014 +0000
+++ b/SPIDriver/SPIDriver.cpp Fri May 02 18:26:40 2014 +0000
@@ -12,13 +12,69 @@
*cs = 1;
}
+SPIDriver::~SPIDriver(){
+}
+
void SPIDriver::write(uint8_t ledcolor){
*cs = 0;
spi.write(ledcolor);
*cs = 1;
}
+void SPIDriver::reversedwrite(uint8_t ledcolor){
+ *cs = 0;
+ spi.write(reverse_byte(ledcolor));
+ *cs = 1;
+}
+
void SPIDriver::pulseLatch(){
*latch = 1;
*latch = 0;
+}
+
+void SPIDriver::sendFrame(LedCube* ledc){
+ for(int i = 0; i < 8; i++) { //eerst laag selecteren, SPI zendt normaalgezien MSB first
+ write(ledc->getNextValue());
+ for(int j = 0; j < 24; j++) {
+ write(ledc->getNextValue()); //ledwaarden zelf nog altijd apart, omdat ze mogelijk gespiegeld moeten doorgestuurd worden
+ } //(LSB first)
+ wait(0.00125); //voor 100 Hz
+ pulseLatch();
+ }//end outer for loop
+}
+
+void SPIDriver::sendTest(LedCube* ledc, int frames){
+ printf("Testing...\n\r");
+ for(int i = 0; i < frames; i++) {
+ sendFrame(ledc);
+ }
+}
+
+void SPIDriver::testPhase(int xframes){
+ printf("Initiating Test phase\n\r");
+
+ LedCube* testledcube1 = new LedCube();
+ LedCube* testledcube2 = new LedCube();
+
+ testledcube1->testMode(LedCube::firsthalfwhite);
+ testledcube2->testMode(LedCube::secondhalfwhite);
+
+ sendTest(testledcube1, xframes);
+ sendTest(testledcube2, xframes);
+
+ printf("Test phase terminated!\n\r");
+}
+
+void SPIDriver::stream(LedCube* ledc){
+ printf("Initiating stream from following matrices\n\r");
+ ledc->printAll();
+ printf("Streaming...\n\r");
+ while(true){
+ sendFrame(ledc);
+ }
+}
+
+uint8_t SPIDriver::reverse_byte(uint8_t byte)
+{
+ return (__rbit(byte) >> 24) & 0xFF; // reverse a byte in a 32-bit value, and extract the byte
}
\ No newline at end of file