]>
Commit | Line | Data |
---|---|---|
88237f3f | 1 | #include "common.h" |
2 | #include "spi.h" | |
3 | #include "tlc59711.h" | |
4 | #include "GPIO.h" | |
5 | #include "display.h" | |
6 | #include <time.h> | |
7 | ||
88237f3f | 8 | inline static int readPin() |
9 | { | |
864b81bd | 10 | return GPIORead(0); |
88237f3f | 11 | } |
12 | static uint64_t nanos() | |
13 | { | |
14 | struct timespec now; | |
15 | timespec_get(&now, TIME_UTC); | |
864b81bd | 16 | return ((uint64_t)now.tv_sec) * 1000000000 + ((uint64_t)now.tv_nsec); |
88237f3f | 17 | } |
18 | ||
4376c3f4 | 19 | static void lines(const uint16_t line[chips*12]); |
88237f3f | 20 | |
864b81bd | 21 | static void getDelay(uint64_t *delay, uint64_t *last); |
88237f3f | 22 | |
864b81bd | 23 | extern void display(bool *go, const uint16_t lester[3][degreesIn][chips * 12], bool *swap) |
24 | { | |
88237f3f | 25 | GPIOInit(); |
864b81bd | 26 | GPIOPinmode(0, IN); |
88237f3f | 27 | tlc59711_init("/dev/spidev0.1"); |
864b81bd | 28 | uint64_t delay = 0, last = 0; |
88237f3f | 29 | bool went_back = true; |
864b81bd | 30 | int p = 0; |
88237f3f | 31 | while (*go) |
32 | { // main loop | |
33 | for (int deg = 0; deg < degreesIn; deg++) | |
34 | { // go thorugh degrees | |
35 | while (last + ((delay)*deg) > nanos()) | |
36 | { // sleep between lines | |
37 | if (readPin()) | |
38 | went_back = true; // we can now wait for the next edge | |
39 | if (!readPin() && went_back) // we are still in the loop but we need to exit | |
40 | goto end; | |
41 | } // sleep between lines | |
c114cfe8 | 42 | |
43 | lines(lester[p][deg]); | |
88237f3f | 44 | } |
45 | end: | |
864b81bd | 46 | while (readPin()) |
47 | ; // wait till it goes low if we exited the loop early | |
88237f3f | 48 | getDelay(&delay, &last); |
49 | went_back = false; //make shure we trigger on the rising edge | |
864b81bd | 50 | printf("%llu\n", delay); |
558dac45 | 51 | if (p == 2) |
52 | p = 0; | |
53 | else | |
54 | p++; | |
864b81bd | 55 | *swap = true; |
88237f3f | 56 | } |
57 | } | |
864b81bd | 58 | static void getDelay(uint64_t *delay, uint64_t *last) |
88237f3f | 59 | { |
60 | uint64_t tmp = *last; | |
61 | *last = nanos(); | |
864b81bd | 62 | *delay = (*last - tmp) / degreesIn; |
88237f3f | 63 | } |
4376c3f4 | 64 | static void lines(const uint16_t line[chips*12]) |
88237f3f | 65 | { |
c114cfe8 | 66 | uint8_t data[chips*28]; |
4376c3f4 | 67 | uint16_t tmp[12]; |
c114cfe8 | 68 | for (int i = 0; i < chips; i++){ |
69 | for(int b = 0; b < 12;b++) | |
48eed265 | 70 | tmp[11 - b] = line[(i*12)+b]; |
c114cfe8 | 71 | |
72 | tlc59711_create(tmp, data + (28 * i)); | |
73 | } | |
864b81bd | 74 | transfer(data, NULL, chips * 28); |
88237f3f | 75 | } |