summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--anzeige.c95
1 files changed, 71 insertions, 24 deletions
diff --git a/anzeige.c b/anzeige.c
index cf83f25..cddc0a8 100644
--- a/anzeige.c
+++ b/anzeige.c
@@ -5,12 +5,15 @@
// Dom and Gert
// Revised: 15-Feb-2013
+#ifndef __arm__
+#define SKIP_GPIO
+#endif
// Access from ARM Running Linux
#define BCM2708_PERI_BASE 0x20000000
#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */
-
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
@@ -33,6 +36,11 @@
int mem_fd;
void *gpio_map;
+typedef struct {
+ char buf[2][35];
+ int should_buf, is_buf, keep_running;
+} t_display_data;
+
// I/O access
volatile unsigned *gpio;
@@ -53,7 +61,7 @@ volatile unsigned *gpio;
void setup_io();
void drop_privileges();
-void *put_on_display(void *content);
+void *put_on_display(void *param);
void printButton(int g)
{
@@ -66,10 +74,18 @@ void printButton(int g)
int main(int argc, char **argv)
{
pthread_t thread_id;
- char *content;
-
+ t_display_data display_data = {
+ "abcdefghijklmnopqrstuvwxyzabcdefghi",
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI",
+ 0,
+ 0,
+ 1
+ };
+
+#ifndef SKIP_GPIO
// Set up gpi pointer for direct register access
-// setup_io();
+ setup_io();
+#endif
// Drop root privileges
drop_privileges();
@@ -81,6 +97,7 @@ int main(int argc, char **argv)
* so at least you still have your code changes written to the SD-card! *
\************************************************************************/
+#ifndef SKIP_GPIO
// must use INP_GPIO before we can use OUT_GPIO
INP_GPIO(SER_DAT_PIN);
OUT_GPIO(SER_DAT_PIN);
@@ -91,9 +108,20 @@ int main(int argc, char **argv)
INP_GPIO(PAR_CLK_PIN);
OUT_GPIO(PAR_CLK_PIN);
INP_GPIO(SENSE_PIN);
+#endif
- content = "0123456789abcdefghijklmnopqrstuvwxy";
- pthread_create(&thread_id, NULL, put_on_display, content);
+ pthread_create(&thread_id, NULL, put_on_display, &display_data);
+
+ for (int i=0; i<20; i++) {
+ usleep(500000);
+ if (display_data.should_buf == display_data.is_buf) {
+ for (int j=0; j<35; j++)
+ display_data.buf[1-display_data.is_buf][j] -= 1;
+ }
+ display_data.should_buf ^= 0x01;
+ }
+
+ display_data.keep_running = 0;
pthread_join(thread_id, NULL);
return 0;
@@ -155,8 +183,9 @@ void drop_privileges()
//
// Shift the bits provided in content into the display
//
-void *put_on_display(void *content)
+void *put_on_display(void *param)
{
+ t_display_data *display_data = param;
char *raw_output;
int line;
@@ -165,25 +194,43 @@ void *put_on_display(void *content)
perror("malloc failed");
exit(-1);
}
- for (line=0; line<7; line++) {
- raw_output[line*6] = 1<<line;
- memmove(raw_output+1+6*line,((char*)content)+5*line,5);
- }
- while (1)
+
+ while (display_data -> keep_running) {
+
+#ifdef SKIP_GPIO
+ printf("\n");
+#endif
+ display_data -> is_buf = display_data -> should_buf;
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;
+ raw_output[line*6] = 1<<line;
+ memmove(raw_output+1+6*line,&(display_data -> buf[display_data -> is_buf][5*line]),5);
+ }
+ for (line=0; line<7; line++) {
+#ifndef SKIP_GPIO
+ GPIO_CLR = 1<<GATE_PIN; // Licht an
+#endif
+ for (int byte=0; byte<6; byte++) {
+#ifndef SKIP_GPIO
+ 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;
+ }
+#else
+ if (byte==0)
+ printf(" %02x ", *(raw_output+6*line+byte));
+ else
+ printf("%c", *(raw_output+6*line+byte));
+#endif
}
+ usleep(1000);
+#ifndef SKIP_GPIO
+ GPIO_SET = 1<<GATE_PIN; // Licht aus
+ GPIO_CLR = 1<<PAR_CLK_PIN;
+ GPIO_SET = 1<<PAR_CLK_PIN;
+#endif
}
- usleep(1000);
- GPIO_SET = 1<<GATE_PIN; // Licht aus
- GPIO_CLR = 1<<PAR_CLK_PIN;
- GPIO_SET = 1<<PAR_CLK_PIN;
- }
+ }
free(raw_output);
return NULL;
} // put_on_screen