summaryrefslogtreecommitdiff
path: root/multiplexer.h
blob: 0b6cdceda27bf3310909b221c486bde8f7f398dd (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
//
//  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 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

int  mem_fd;
void *gpio_map;

typedef struct {
  char buf[3][40];
  int should_buf, is_buf, keep_running;
  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;
  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);