summaryrefslogtreecommitdiff
path: root/anzeige.c
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-10-22 14:19:25 +0200
committerErich Eckner <git@eckner.net>2018-10-22 14:19:25 +0200
commitae75b15e6241232c2adb3ae3b53819d3a4dd638d (patch)
tree4a4c738c2bfa8fff0ac2dbe0a90444120bb566c5 /anzeige.c
parent9cbc55a81c76dd3bfb480b9f280f9958ce6ef592 (diff)
downloadanzeige-ae75b15e6241232c2adb3ae3b53819d3a4dd638d.tar.xz
split of logical parts into separate files
Diffstat (limited to 'anzeige.c')
-rw-r--r--anzeige.c173
1 files changed, 8 insertions, 165 deletions
diff --git a/anzeige.c b/anzeige.c
index b08d4d6..0e6713c 100644
--- a/anzeige.c
+++ b/anzeige.c
@@ -1,18 +1,3 @@
-//
-// How to access GPIO registers from C-code on the Raspberry-Pi
-// Example program
-// 15-January-2012
-// 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>
@@ -25,67 +10,25 @@
#include <pthread.h>
#include "fonts.h"
+#include "input_gadgets.h"
+#include "multiplexer.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;
-
-typedef struct {
- char buf[3][40];
- int should_buf, is_buf, keep_running;
-} t_display_data;
-
-// I/O access
-volatile unsigned *gpio;
-
-
-// GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y)
-#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
-#define OUT_GPIO(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3))
-#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
-
-#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
-
-#define GPIO_PULL *(gpio+37) // Pull up/pull down
-#define GPIO_PULLCLK0 *(gpio+38) // Pull up/pull down clock
-
-void setup_io();
void drop_privileges();
-void *put_on_display(void *param);
-
-void printButton(int g)
-{
- if (GET_GPIO(g)) // !=0 <-> bit is 1 <- port is HIGH=3.3V
- printf("Button pressed!\n");
- else // port is LOW=0V
- printf("Button released!\n");
-}
int main(int argc, char **argv)
{
pthread_t thread_id;
t_display_data display_data;
-#ifndef SKIP_GPIO
// Set up gpi pointer for direct register access
- setup_io();
-#endif
+ multiplexer_setup_root();
// Drop root privileges
drop_privileges();
+ gadgets_retrieve_temperature();
+ return 0;
+
/************************************************************************\
* You are about to change the GPIO settings of your computer. *
* Mess this up and it will stop working! *
@@ -93,25 +36,8 @@ 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);
- 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);
-#endif
-
- for (int i=0; i<3; i++)
- memset(display_data.buf[i],0,40);
- display_data.is_buf = 0;
- display_data.should_buf = 0;
- display_data.keep_running = 1;
- pthread_create(&thread_id, NULL, put_on_display, &display_data);
+ // configure the gpio pins and start the multiplexer thread
+ thread_id = multiplexer_setup_non_root(&display_data);
for (int i=0; i<20; i++) {
usleep(2500000);
@@ -127,41 +53,6 @@ int main(int argc, char **argv)
} // main
-
-//
-// Set up a memory regions to access GPIO
-//
-void setup_io()
-{
- /* open /dev/mem */
- if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {
- perror("can't open /dev/mem");
- exit(-1);
- }
-
- /* mmap GPIO */
- gpio_map = mmap(
- NULL, //Any adddress in our space will do
- BLOCK_SIZE, //Map length
- PROT_READ|PROT_WRITE,// Enable reading & writting to mapped memory
- MAP_SHARED, //Shared with other processes
- mem_fd, //File to map
- GPIO_BASE //Offset to GPIO peripheral
- );
-
- close(mem_fd); //No need to keep mem_fd open after mmap
-
- if (gpio_map == MAP_FAILED) {
- perror("mmap error");
- exit(-1);
- }
-
- // Always use volatile pointer!
- gpio = (volatile unsigned *)gpio_map;
-
-
-} // setup_io
-
//
// Drop (root) privileges
//
@@ -178,51 +69,3 @@ void drop_privileges()
exit(-1);
}
} // drop_root
-
-//
-// Shift the bits provided in content into the display
-//
-void *put_on_display(void *param)
-{
- t_display_data *display_data = param;
- int line, column;
-
- while (display_data -> keep_running) {
-
-#ifdef SKIP_GPIO
- usleep(100000);
- printf("=\n");
-#endif
- display_data -> is_buf = display_data -> should_buf;
- for (line=0; line<7; line++) {
-#ifdef SKIP_GPIO
- for (column=0; column<40; column++) {
- if ((*(display_data -> buf[display_data -> is_buf] + column)>>line) & 0x01)
- printf("X");
- else
- printf(".");
-#else
- GPIO_CLR = 1<<GATE_PIN; // Licht an
- for (column=0; column<8; column++) {
- GPIO_CLR = 1<<SER_CLK_PIN;
- GPIO_ALTER(column == line) = 1<<SER_DAT_PIN;
- GPIO_SET = 1<<SER_CLK_PIN;
- }
- for (column=39; column>=0; column--) {
- GPIO_CLR = 1<<SER_CLK_PIN;
- GPIO_ALTER((*(display_data -> buf[display_data -> is_buf] + column)>>line) & 0x01) = 1<<SER_DAT_PIN;
- GPIO_SET = 1<<SER_CLK_PIN;
-#endif
- }
- usleep(1000);
-#ifdef SKIP_GPIO
- printf("\n");
-#else
- GPIO_SET = 1<<GATE_PIN; // Licht aus
- GPIO_CLR = 1<<PAR_CLK_PIN;
- GPIO_SET = 1<<PAR_CLK_PIN;
-#endif
- }
- }
- return NULL;
-} // put_on_screen