]>
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 | ||
88237f3f | 19 | static uint16_t pwmbuffer[chips][12]; |
20 | ||
88237f3f | 21 | static void lines(uint16_t data[chips][12]); |
22 | ||
864b81bd | 23 | static void getDelay(uint64_t *delay, uint64_t *last); |
88237f3f | 24 | |
864b81bd | 25 | extern void display(bool *go, const uint16_t lester[3][degreesIn][chips * 12], bool *swap) |
26 | { | |
88237f3f | 27 | GPIOInit(); |
864b81bd | 28 | GPIOPinmode(0, IN); |
88237f3f | 29 | tlc59711_init("/dev/spidev0.1"); |
864b81bd | 30 | uint64_t delay = 0, last = 0; |
88237f3f | 31 | bool went_back = true; |
864b81bd | 32 | int p = 0; |
88237f3f | 33 | while (*go) |
34 | { // main loop | |
35 | for (int deg = 0; deg < degreesIn; deg++) | |
36 | { // go thorugh degrees | |
37 | while (last + ((delay)*deg) > nanos()) | |
38 | { // sleep between lines | |
39 | if (readPin()) | |
40 | went_back = true; // we can now wait for the next edge | |
41 | if (!readPin() && went_back) // we are still in the loop but we need to exit | |
42 | goto end; | |
43 | } // sleep between lines | |
864b81bd | 44 | for (uint8_t i = 0; i < chips * 12; i++) |
88237f3f | 45 | { |
90013631 | 46 | pwmbuffer[i / 12][11 - (i % 12)] = lester[p][deg][i]; |
88237f3f | 47 | } |
48 | lines(pwmbuffer); | |
49 | } | |
50 | end: | |
864b81bd | 51 | while (readPin()) |
52 | ; // wait till it goes low if we exited the loop early | |
88237f3f | 53 | getDelay(&delay, &last); |
54 | went_back = false; //make shure we trigger on the rising edge | |
864b81bd | 55 | printf("%llu\n", delay); |
558dac45 | 56 | if (p == 2) |
57 | p = 0; | |
58 | else | |
59 | p++; | |
864b81bd | 60 | *swap = true; |
88237f3f | 61 | } |
62 | } | |
864b81bd | 63 | static void getDelay(uint64_t *delay, uint64_t *last) |
88237f3f | 64 | { |
65 | uint64_t tmp = *last; | |
66 | *last = nanos(); | |
864b81bd | 67 | *delay = (*last - tmp) / degreesIn; |
88237f3f | 68 | } |
69 | static void lines(uint16_t line[chips][12]) | |
70 | { | |
864b81bd | 71 | uint8_t *data = (uint8_t *)malloc(chips * 28); |
88237f3f | 72 | for (int i = 0; i < chips; i++) |
864b81bd | 73 | tlc59711_create(line[i], data + (28 * i)); |
74 | transfer(data, NULL, chips * 28); | |
88237f3f | 75 | } |