-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshifter.c
68 lines (51 loc) · 1.62 KB
/
shifter.c
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
#include "shifter.h"
#include <StellarisWare/inc/hw_ints.h>
#include <StellarisWare/inc/hw_memmap.h>
#include <StellarisWare/inc/hw_gpio.h>
#include <StellarisWare/driverlib/interrupt.h>
#include <StellarisWare/driverlib/gpio.h>
#include <StellarisWare/driverlib/sysctl.h>
static void ShiftSelect(tShifter *sh, int n) {
int i;
for (i = 0; i < sh->height; i++) {
if ((i == n) == (!sh->invert))
SetPinZ(sh->rows[i]);
else
SetPin(sh->rows[i], false);
}
}
void InitShift(tShifter *sh) {
int i;
sh->active = -1;
for (i = 0; i < sh->height; i++) {
GPIOPadConfigSet(PORT_VAL(sh->rows[i]), PIN_VAL(sh->rows[i]),
GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
}
ShiftSelect(sh, -1);
SetPin(sh->dline, false);
SetPin(sh->clk, false);
SetPin(sh->strobe, false);
}
void ShiftUpdate(tShifter *sh) {
int i;
const unsigned char *d = sh->data;
// Clear things here to keep artifacts from appearing
ShiftSelect(sh, -1);
sh->active = (sh->active + 1) % sh->height;
for (i = 0; i < sh->width; i++) {
SetPin(sh->dline, (*d++) & (1 << sh->active));
SetPin(sh->clk, true);
SetPin(sh->clk, false);
}
SetPin(sh->strobe, true);
SetPin(sh->strobe, false);
ShiftSelect(sh, sh->active);
if (sh->cb && sh->active == sh->height-1)
sh->cb(sh->cb_data);
}
void ShiftRunUS(tShifter *sh, tTime us) {
CallEveryUS(ShiftUpdate, sh, us/sh->height*1.4); //mess with the constant to change scroll speed
}
void ShiftRun(tShifter *sh, float s) {
ShiftRunUS(sh, US(s));
}