-
Notifications
You must be signed in to change notification settings - Fork 0
/
PiGpio.c
124 lines (106 loc) · 2.46 KB
/
PiGpio.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*****************************************************************************
**
** blueberryMSX
** https://github.com/pokebyte/blueberryMSX
**
** An MSX Emulator for Raspberry Pi based on blueMSX
**
** Copyright (C) 2014 Akop Karapetyan
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
******************************************************************************
*/
#include <stdlib.h>
#include <stdio.h>
#include <wiringPi.h>
#include <wiringShift.h>
#include "Led.h"
#define CLOCK 3
#define LATCH 4
#define DATA 25
#define CAPS 0x05
#define HANS 0x0A
#define IOLD 0x10
#define SLT1 0x20
#define SLT2 0x40
#define POWER 0x80
#define FDD0 0xFF
#define FDD1 0xFF
static int ledBitMap = 0;
static void gpioShiftLeds();
void gpioInit()
{
wiringPiSetup();
pinMode(CLOCK, OUTPUT) ;
pinMode(LATCH, OUTPUT) ;
pinMode(DATA, OUTPUT) ;
printf("Ligting up Power led");
ledBitMap = POWER;
gpioShiftLeds();
getchar();
printf("Ligting up Caps led");
ledBitMap = CAPS;
gpioShiftLeds();
getchar();
printf("Ligting up HAN led");
ledBitMap = HANS;
gpioShiftLeds();
getchar();
printf("Ligting up I/O led");
ledBitMap = IOLD;
gpioShiftLeds();
getchar();
printf("Ligting up Slot1 led");
ledBitMap = SLT1;
gpioShiftLeds();
getchar();
printf("Ligting up Slot2 led");
ledBitMap = SLT2;
gpioShiftLeds();
getchar();
}
void gpioShutdown()
{
ledBitMap = 0;
gpioShiftLeds();
}
/*int ledGetSlt1(){
ledBitMap = SLT1;
gpioShiftLeds();
}*/
void gpioUpdateLeds()
{
int oldBitMap = ledBitMap;
if (ledGetFdd1()) {
ledBitMap |= FDD0;
} else {
ledBitMap &= ~FDD0;
}
if (ledGetFdd2()) {
ledBitMap |= FDD1;
} else {
ledBitMap &= ~FDD1;
}
if (oldBitMap != ledBitMap) {
gpioShiftLeds();
}
}
static void gpioShiftLeds()
{
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLOCK, LSBFIRST, ledBitMap);
digitalWrite(LATCH, HIGH);
}