summaryrefslogtreecommitdiff
path: root/multiplexer.h
blob: 3fb1f874c96d04dd559be648f0fb9f6ca4a7704c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef MULTIPLEXER_H
#define MULTIPLEXER_H

//
//  How to access GPIO registers from C-code on the Raspberry-Pi
//  Example program
//  15-January-2012
//  Dom and Gert
//  Revised: 15-Feb-2013

# include <stdint.h>

#ifndef __arm__
#ifndef FORCE_GPIO
#define SKIP_GPIO
#endif // FORCE_GPIO
#endif // __arm__

// Access from ARM Running Linux

#define BCM2708_PERI_BASE        0x20000000
#define GPIO_BASE                (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */

/** stolen/cited from wiringPi's wiringPi/wiringPi.c lines 536-548 **/

// GPPUD:
//      GPIO Pin pull up/down register

#define GPPUD   37
// gpioToPUDCLK
//      (Word) offset to the Pull Up Down Clock regsiter

static uint8_t gpioToPUDCLK [] =
{
  38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,
  39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
};

/** cite end **/

#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

#define SCROLL_BUF_LEN 4096

static int tpic_settle_time_iterator = 1000;
#define wait_tpic_settle_time  for (int i=0; i<tpic_settle_time_iterator; i++) { asm volatile("" : : "r" (i)); }

int  mem_fd;
void *gpio_map;

typedef struct {
  char buf[3][40];
  int should_buf, is_buf, keep_running, should_be_on, is_on;
  pthread_t thread_id;
} t_display_data;

typedef struct {
  char buf[SCROLL_BUF_LEN];
  int start, len;
} t_scroll_buffer;

typedef struct {
  int update;
  char input[(SCROLL_BUF_LEN - 39) / 2];
  int input_len, keep_running;
  time_t shine_until;
  pthread_t thread_id;
} t_scroll_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

int multiplexer_setup_root();
void multiplexer_setup_non_root(t_display_data *display_data);
void multiplexer_setup_scroll(t_scroll_data *scroll_data);
void turn_off_display();
int got_input();

#endif // MULTIPLEXER_H