summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-10-19 10:16:36 +0200
committerErich Eckner <git@eckner.net>2018-10-19 10:16:36 +0200
commitbab55b41a5aee1a3a0e7320cc06c7444ffcfbf7d (patch)
tree9cf72976fcc6d6bc9452a46484da0ad8bedcdb6a
parentfd61d383a2853bae3f18fecf0c4a02f20693bfee (diff)
downloadanzeige-bab55b41a5aee1a3a0e7320cc06c7444ffcfbf7d.tar.xz
test.c: sollte erstmal was machen
-rw-r--r--test.c66
1 files changed, 56 insertions, 10 deletions
diff --git a/test.c b/test.c
index b24a2b7..24d6011 100644
--- a/test.c
+++ b/test.c
@@ -18,10 +18,17 @@
#include <sys/mman.h>
#include <unistd.h>
#include <errno.h>
+#include <string.h>
#define PAGE_SIZE (4*1024)
#define BLOCK_SIZE (4*1024)
+#define SER_DAT_PIN 26
+#define SER_CLK_PIN 19
+#define GATE_PIN 13
+#define PAR_CLK_PIN 6
+#define SENSE_PIN 5
+
int mem_fd;
void *gpio_map;
@@ -36,6 +43,7 @@ volatile unsigned *gpio;
#define GPIO_SET *(gpio+7) // sets bits which are 1 ignores bits which are 0
#define GPIO_CLR *(gpio+10) // clears bits which are 1 ignores bits which are 0
+#define GPIO_ALTER(a) *(gpio+(a==0?10:7)) // alters (a==0: clear, else: set) bits which are 1 ignores bits which are 0
#define GET_GPIO(g) (*(gpio+13)&(1<<g)) // 0 if LOW, (1<<g) if HIGH
@@ -44,6 +52,7 @@ volatile unsigned *gpio;
void setup_io();
void drop_privileges();
+void put_on_display(char *content);
void printButton(int g)
{
@@ -58,7 +67,7 @@ int main(int argc, char **argv)
int rep;
// Set up gpi pointer for direct register access
- setup_io();
+// setup_io();
// Drop root privileges
drop_privileges();
@@ -70,16 +79,18 @@ int main(int argc, char **argv)
* so at least you still have your code changes written to the SD-card! *
\************************************************************************/
-return 0;
-
- INP_GPIO(21); // must use INP_GPIO before we can use OUT_GPIO
- OUT_GPIO(21);
+ // must use INP_GPIO before we can use OUT_GPIO
+ INP_GPIO(SER_DAT_PIN);
+ OUT_GPIO(SER_DAT_PIN);
+ INP_GPIO(SER_CLK_PIN);
+ OUT_GPIO(SER_CLK_PIN);
+ INP_GPIO(GATE_PIN);
+ OUT_GPIO(GATE_PIN);
+ INP_GPIO(PAR_CLK_PIN);
+ OUT_GPIO(PAR_CLK_PIN);
+ INP_GPIO(SENSE_PIN);
- for (rep=0; rep<2000000*60; rep++)
- {
- GPIO_SET = 1<<21;
- GPIO_CLR = 1<<21;
- }
+ put_on_display("0123456789abcdefghijklmnopqrstuvwxy");
return 0;
@@ -136,3 +147,38 @@ void drop_privileges()
exit(-1);
}
} // drop_root
+
+//
+// Shift the bits provided in content into the display
+//
+void put_on_display(char *content)
+{
+ char *raw_output;
+ int line;
+
+ raw_output = malloc(7*(5+1));
+ if (raw_output == NULL) {
+ perror("malloc failed");
+ exit(-1);
+ }
+ for (line=0; line<7; line++) {
+ raw_output[line*6] = 1<<line;
+ memmove(raw_output+1+6*line,content+5*line,5);
+ }
+ while (1);
+ for (line=0; line<7; line++) {
+ GPIO_CLR = 1<<GATE_PIN; // Licht an
+ for (int byte=0; byte<6; byte++) {
+ for (int bit=0; bit<8; bit++) {
+ GPIO_CLR = 1<<SER_CLK_PIN;
+ GPIO_ALTER((*(raw_output+6*line+byte)>>bit) & 0x01) = 1<<SER_DAT_PIN;
+ GPIO_SET = 1<<SER_CLK_PIN;
+ }
+ }
+ usleep(1000);
+ GPIO_SET = 1<<GATE_PIN; // Licht aus
+ GPIO_CLR = 1<<PAR_CLK_PIN;
+ GPIO_SET = 1<<PAR_CLK_PIN;
+ }
+ free(raw_output);
+} // put_on_screen