wiringpi2 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/wiringpi/WiringPi/examples/blink.c +50 -0
- data/ext/wiringpi/WiringPi/examples/delayTest.c +107 -0
- data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -0
- data/ext/wiringpi/WiringPi/examples/gertboard.c +94 -0
- data/ext/wiringpi/WiringPi/examples/header.h +23 -0
- data/ext/wiringpi/WiringPi/examples/isr-osc.c +118 -0
- data/ext/wiringpi/WiringPi/examples/isr.c +99 -0
- data/ext/wiringpi/WiringPi/examples/lcd.c +129 -0
- data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
- data/ext/wiringpi/WiringPi/examples/okLed.c +83 -0
- data/ext/wiringpi/WiringPi/examples/piface.c +74 -0
- data/ext/wiringpi/WiringPi/examples/pwm.c +93 -0
- data/ext/wiringpi/WiringPi/examples/serialRead.c +48 -0
- data/ext/wiringpi/WiringPi/examples/serialTest.c +75 -0
- data/ext/wiringpi/WiringPi/examples/servo.c +57 -0
- data/ext/wiringpi/WiringPi/examples/speed.c +123 -0
- data/ext/wiringpi/WiringPi/examples/test1.c +111 -0
- data/ext/wiringpi/WiringPi/examples/test2.c +58 -0
- data/ext/wiringpi/WiringPi/examples/tone.c +59 -0
- data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
- data/ext/wiringpi/WiringPi/gpio/gpio.c +1371 -0
- data/ext/wiringpi/WiringPi/wiringPi/ds1302.c +239 -0
- data/ext/wiringpi/WiringPi/wiringPi/ds1302.h +44 -0
- data/ext/wiringpi/WiringPi/wiringPi/gertboard.c +166 -0
- data/ext/wiringpi/WiringPi/wiringPi/gertboard.h +40 -0
- data/ext/wiringpi/WiringPi/wiringPi/lcd.c +380 -0
- data/ext/wiringpi/WiringPi/wiringPi/lcd.h +46 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +155 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +195 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +236 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
- data/ext/wiringpi/WiringPi/wiringPi/piFace.c +179 -0
- data/ext/wiringpi/WiringPi/wiringPi/piFace.h +32 -0
- data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +50 -0
- data/ext/wiringpi/WiringPi/wiringPi/piNes.c +113 -0
- data/ext/wiringpi/WiringPi/wiringPi/piNes.h +45 -0
- data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +130 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/softServo.c +211 -0
- data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/softTone.c +121 -0
- data/ext/wiringpi/WiringPi/wiringPi/softTone.h +38 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.c +108 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +1664 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +168 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +227 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +119 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.c +213 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringShift.c +83 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringShift.h +41 -0
- data/ext/wiringpi/extconf.rb +8 -0
- data/ext/wiringpi/wiringpi_wrap.c +4378 -0
- data/lib/wiringpi/event.rb +21 -0
- data/lib/wiringpi/gpio.rb +131 -0
- data/lib/wiringpi/i2c.rb +26 -0
- data/lib/wiringpi/mcp23x17.rb +31 -0
- data/lib/wiringpi/serial.rb +49 -0
- data/lib/wiringpi/spi.rb +15 -0
- data/lib/wiringpi2.rb +42 -0
- metadata +122 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* blink.c:
|
|
3
|
+
* Standard "blink" program in wiringPi. Blinks an LED connected
|
|
4
|
+
* to the first GPIO pin.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
|
7
|
+
***********************************************************************
|
|
8
|
+
* This file is part of wiringPi:
|
|
9
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
10
|
+
*
|
|
11
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
14
|
+
* (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU Lesser General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
22
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
***********************************************************************
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include <stdio.h>
|
|
27
|
+
#include <wiringPi.h>
|
|
28
|
+
|
|
29
|
+
// LED Pin - wiringPi pin 0 is BCM_GPIO 17.
|
|
30
|
+
|
|
31
|
+
#define LED 0
|
|
32
|
+
|
|
33
|
+
int main (void)
|
|
34
|
+
{
|
|
35
|
+
printf ("Raspberry Pi blink\n") ;
|
|
36
|
+
|
|
37
|
+
if (wiringPiSetup () == -1)
|
|
38
|
+
return 1 ;
|
|
39
|
+
|
|
40
|
+
pinMode (LED, OUTPUT) ;
|
|
41
|
+
|
|
42
|
+
for (;;)
|
|
43
|
+
{
|
|
44
|
+
digitalWrite (LED, 1) ; // On
|
|
45
|
+
delay (500) ; // mS
|
|
46
|
+
digitalWrite (LED, 0) ; // Off
|
|
47
|
+
delay (500) ;
|
|
48
|
+
}
|
|
49
|
+
return 0 ;
|
|
50
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* delayTest.c:
|
|
3
|
+
* Just a little test program I'm using to experiment with
|
|
4
|
+
* various timings and latency, etc.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
|
7
|
+
***********************************************************************
|
|
8
|
+
* This file is part of wiringPi:
|
|
9
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
10
|
+
*
|
|
11
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
14
|
+
* (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU Lesser General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
22
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
***********************************************************************
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include <stdio.h>
|
|
27
|
+
#include <unistd.h>
|
|
28
|
+
#include <wiringPi.h>
|
|
29
|
+
|
|
30
|
+
#include <sys/time.h>
|
|
31
|
+
|
|
32
|
+
#define CYCLES 1000
|
|
33
|
+
|
|
34
|
+
int main()
|
|
35
|
+
{
|
|
36
|
+
int x ;
|
|
37
|
+
struct timeval t1, t2 ;
|
|
38
|
+
int t ;
|
|
39
|
+
int max, min ;
|
|
40
|
+
int del ;
|
|
41
|
+
int underRuns, overRuns, exactRuns, total ;
|
|
42
|
+
int descheds ;
|
|
43
|
+
|
|
44
|
+
if (wiringPiSetup () == -1)
|
|
45
|
+
return 1 ;
|
|
46
|
+
|
|
47
|
+
piHiPri (10) ; sleep (1) ;
|
|
48
|
+
|
|
49
|
+
// Baseline test
|
|
50
|
+
|
|
51
|
+
gettimeofday (&t1, NULL) ;
|
|
52
|
+
gettimeofday (&t2, NULL) ;
|
|
53
|
+
|
|
54
|
+
t = t2.tv_usec - t1.tv_usec ;
|
|
55
|
+
printf ("Baseline test: %d\n", t);
|
|
56
|
+
|
|
57
|
+
for (del = 1 ; del < 200 ; ++del)
|
|
58
|
+
{
|
|
59
|
+
underRuns = overRuns = exactRuns = total = 0 ;
|
|
60
|
+
descheds = 0 ;
|
|
61
|
+
max = del ;
|
|
62
|
+
min = del ;
|
|
63
|
+
|
|
64
|
+
for (x = 0 ; x < CYCLES ; ++x)
|
|
65
|
+
{
|
|
66
|
+
for (;;) // Repeat this if we get a delay over 999uS
|
|
67
|
+
{ // -> High probability Linux has deschedulled us
|
|
68
|
+
gettimeofday (&t1, NULL) ;
|
|
69
|
+
delayMicroseconds (del) ;
|
|
70
|
+
gettimeofday (&t2, NULL) ;
|
|
71
|
+
|
|
72
|
+
if (t2.tv_usec < t1.tv_usec) // Counter wrapped
|
|
73
|
+
t = (1000000 + t2.tv_usec) - t1.tv_usec;
|
|
74
|
+
else
|
|
75
|
+
t = t2.tv_usec - t1.tv_usec ;
|
|
76
|
+
if (t > 999)
|
|
77
|
+
{
|
|
78
|
+
++descheds ;
|
|
79
|
+
continue ;
|
|
80
|
+
}
|
|
81
|
+
else
|
|
82
|
+
break ;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (t > max)
|
|
86
|
+
{
|
|
87
|
+
max = t ;
|
|
88
|
+
++overRuns ;
|
|
89
|
+
}
|
|
90
|
+
else if (t < min)
|
|
91
|
+
{
|
|
92
|
+
min = t ;
|
|
93
|
+
++underRuns ;
|
|
94
|
+
}
|
|
95
|
+
else
|
|
96
|
+
++exactRuns ;
|
|
97
|
+
|
|
98
|
+
total += t ;
|
|
99
|
+
}
|
|
100
|
+
printf ("Delay: %3d. Min: %3d, Max: %3d, Unders: %3d, Overs: %3d, Exacts: %3d, Average: %3d, Descheds: %2d\n",
|
|
101
|
+
del, min, max, underRuns, overRuns, exactRuns, total / CYCLES, descheds) ;
|
|
102
|
+
fflush (stdout) ;
|
|
103
|
+
delay (1) ;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return 0 ;
|
|
107
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ds1302.c:
|
|
3
|
+
* Real Time clock
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2013 Gordon Henderson.
|
|
6
|
+
***********************************************************************
|
|
7
|
+
* This file is part of wiringPi:
|
|
8
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
9
|
+
*
|
|
10
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
11
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
12
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
13
|
+
* (at your option) any later version.
|
|
14
|
+
*
|
|
15
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
16
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18
|
+
* GNU Lesser General Public License for more details.
|
|
19
|
+
*
|
|
20
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
21
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
22
|
+
***********************************************************************
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
#include <stdio.h>
|
|
26
|
+
#include <stdlib.h>
|
|
27
|
+
#include <stdint.h>
|
|
28
|
+
#include <string.h>
|
|
29
|
+
#include <time.h>
|
|
30
|
+
|
|
31
|
+
#include <wiringPi.h>
|
|
32
|
+
#include <ds1302.h>
|
|
33
|
+
|
|
34
|
+
// Register defines
|
|
35
|
+
|
|
36
|
+
#define RTC_SECS 0
|
|
37
|
+
#define RTC_MINS 1
|
|
38
|
+
#define RTC_HOURS 2
|
|
39
|
+
#define RTC_DATE 3
|
|
40
|
+
#define RTC_MONTH 4
|
|
41
|
+
#define RTC_DAY 5
|
|
42
|
+
#define RTC_YEAR 6
|
|
43
|
+
#define RTC_WP 7
|
|
44
|
+
#define RTC_TC 8
|
|
45
|
+
#define RTC_BM 31
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
static unsigned int masks [] = { 0x7F, 0x7F, 0x3F, 0x3F, 0x1F, 0x07, 0xFF } ;
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
/*
|
|
52
|
+
* bcdToD: dToBCD:
|
|
53
|
+
* BCD decode/encode
|
|
54
|
+
*********************************************************************************
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
static int bcdToD (unsigned int byte, unsigned int mask)
|
|
58
|
+
{
|
|
59
|
+
unsigned int b1, b2 ;
|
|
60
|
+
byte &= mask ;
|
|
61
|
+
b1 = byte & 0x0F ;
|
|
62
|
+
b2 = ((byte >> 4) & 0x0F) * 10 ;
|
|
63
|
+
return b1 + b2 ;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static unsigned int dToBcd (unsigned int byte)
|
|
67
|
+
{
|
|
68
|
+
return ((byte / 10) << 4) + (byte % 10) ;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
/*
|
|
73
|
+
* ramTest:
|
|
74
|
+
* Simple test of the 31 bytes of RAM inside the DS1302 chip
|
|
75
|
+
*********************************************************************************
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
static int ramTestValues [] =
|
|
79
|
+
{ 0x00, 0xFF, 0xAA, 0x55, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0xF0, 0x0F, -1 } ;
|
|
80
|
+
|
|
81
|
+
static int ramTest (void)
|
|
82
|
+
{
|
|
83
|
+
int addr ;
|
|
84
|
+
int got ;
|
|
85
|
+
int i = 0 ;
|
|
86
|
+
int errors = 0 ;
|
|
87
|
+
int testVal ;
|
|
88
|
+
|
|
89
|
+
printf ("DS1302 RAM TEST\n") ;
|
|
90
|
+
|
|
91
|
+
testVal = ramTestValues [i] ;
|
|
92
|
+
|
|
93
|
+
while (testVal != -1)
|
|
94
|
+
{
|
|
95
|
+
for (addr = 0 ; addr < 31 ; ++addr)
|
|
96
|
+
ds1302ramWrite (addr, testVal) ;
|
|
97
|
+
|
|
98
|
+
for (addr = 0 ; addr < 31 ; ++addr)
|
|
99
|
+
if ((got = ds1302ramRead (addr)) != testVal)
|
|
100
|
+
{
|
|
101
|
+
printf ("DS1302 RAM Failure: Address: %2d, Expected: 0x%02X, Got: 0x%02X\n",
|
|
102
|
+
addr, testVal, got) ;
|
|
103
|
+
++errors ;
|
|
104
|
+
}
|
|
105
|
+
testVal = ramTestValues [++i] ;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
for (addr = 0 ; addr < 31 ; ++addr)
|
|
109
|
+
ds1302ramWrite (addr, addr) ;
|
|
110
|
+
|
|
111
|
+
for (addr = 0 ; addr < 31 ; ++addr)
|
|
112
|
+
if ((got = ds1302ramRead (addr)) != addr)
|
|
113
|
+
{
|
|
114
|
+
printf ("DS1302 RAM Failure: Address: %2d, Expected: 0x%02X, Got: 0x%02X\n",
|
|
115
|
+
addr, addr, got) ;
|
|
116
|
+
++errors ;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (errors == 0)
|
|
120
|
+
printf ("-- DS1302 RAM TEST: OK\n") ;
|
|
121
|
+
else
|
|
122
|
+
printf ("-- DS1302 RAM TEST FAILURE. %d errors.\n", errors) ;
|
|
123
|
+
|
|
124
|
+
return 0 ;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/*
|
|
128
|
+
* setLinuxClock:
|
|
129
|
+
* Set the Linux clock from the hardware
|
|
130
|
+
*********************************************************************************
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
static int setLinuxClock (void)
|
|
134
|
+
{
|
|
135
|
+
char dateTime [20] ;
|
|
136
|
+
char command [64] ;
|
|
137
|
+
int clock [8] ;
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
printf ("Setting the Linux Clock from the DS1302... ") ; fflush (stdout) ;
|
|
141
|
+
|
|
142
|
+
ds1302clockRead (clock) ;
|
|
143
|
+
|
|
144
|
+
// [MMDDhhmm[[CC]YY][.ss]]
|
|
145
|
+
|
|
146
|
+
sprintf (dateTime, "%02d%02d%02d%02d%02d%02d.%02d",
|
|
147
|
+
bcdToD (clock [RTC_MONTH], masks [RTC_MONTH]),
|
|
148
|
+
bcdToD (clock [RTC_DATE], masks [RTC_DATE]),
|
|
149
|
+
bcdToD (clock [RTC_HOURS], masks [RTC_HOURS]),
|
|
150
|
+
bcdToD (clock [RTC_MINS], masks [RTC_MINS]),
|
|
151
|
+
20,
|
|
152
|
+
bcdToD (clock [RTC_YEAR], masks [RTC_YEAR]),
|
|
153
|
+
bcdToD (clock [RTC_SECS], masks [RTC_SECS])) ;
|
|
154
|
+
|
|
155
|
+
sprintf (command, "/bin/date %s", dateTime) ;
|
|
156
|
+
system (command) ;
|
|
157
|
+
|
|
158
|
+
return 0 ;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
/*
|
|
163
|
+
* setDSclock:
|
|
164
|
+
* Set the DS1302 block from Linux time
|
|
165
|
+
*********************************************************************************
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
static int setDSclock (void)
|
|
169
|
+
{
|
|
170
|
+
struct tm t ;
|
|
171
|
+
time_t now ;
|
|
172
|
+
int clock [8] ;
|
|
173
|
+
|
|
174
|
+
printf ("Setting the clock in the DS1302 from Linux time... ") ;
|
|
175
|
+
|
|
176
|
+
now = time (NULL) ;
|
|
177
|
+
gmtime_r (&now, &t) ;
|
|
178
|
+
|
|
179
|
+
clock [ 0] = dToBcd (t.tm_sec) ; // seconds
|
|
180
|
+
clock [ 1] = dToBcd (t.tm_min) ; // mins
|
|
181
|
+
clock [ 2] = dToBcd (t.tm_hour) ; // hours
|
|
182
|
+
clock [ 3] = dToBcd (t.tm_mday) ; // date
|
|
183
|
+
clock [ 4] = dToBcd (t.tm_mon + 1) ; // months 0-11 --> 1-12
|
|
184
|
+
clock [ 5] = dToBcd (t.tm_wday + 1) ; // weekdays (sun 0)
|
|
185
|
+
clock [ 6] = dToBcd (t.tm_year - 100) ; // years
|
|
186
|
+
clock [ 7] = 0 ; // W-Protect off
|
|
187
|
+
|
|
188
|
+
ds1302clockWrite (clock) ;
|
|
189
|
+
|
|
190
|
+
printf ("OK\n") ;
|
|
191
|
+
|
|
192
|
+
return 0 ;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
int main (int argc, char *argv [])
|
|
199
|
+
{
|
|
200
|
+
int i ;
|
|
201
|
+
int clock [8] ;
|
|
202
|
+
|
|
203
|
+
wiringPiSetup () ;
|
|
204
|
+
ds1302setup (0, 1, 2) ;
|
|
205
|
+
|
|
206
|
+
if (argc == 2)
|
|
207
|
+
{
|
|
208
|
+
/**/ if (strcmp (argv [1], "-slc") == 0)
|
|
209
|
+
return setLinuxClock () ;
|
|
210
|
+
else if (strcmp (argv [1], "-sdsc") == 0)
|
|
211
|
+
return setDSclock () ;
|
|
212
|
+
else if (strcmp (argv [1], "-rtest") == 0)
|
|
213
|
+
return ramTest () ;
|
|
214
|
+
else
|
|
215
|
+
{
|
|
216
|
+
printf ("Usage: ds1302 [-slc | -sdsc | -rtest]\n") ;
|
|
217
|
+
return EXIT_FAILURE ;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
for (i = 0 ;; ++i)
|
|
222
|
+
{
|
|
223
|
+
printf ("%5d: ", i) ;
|
|
224
|
+
|
|
225
|
+
ds1302clockRead (clock) ;
|
|
226
|
+
printf (" %2d:%02d:%02d",
|
|
227
|
+
bcdToD (clock [2], masks [2]), bcdToD (clock [1], masks [1]), bcdToD (clock [0], masks [0])) ;
|
|
228
|
+
|
|
229
|
+
printf (" %2d/%02d/%04d",
|
|
230
|
+
bcdToD (clock [3], masks [3]), bcdToD (clock [4], masks [4]), bcdToD (clock [6], masks [6]) + 2000) ;
|
|
231
|
+
|
|
232
|
+
printf ("\n") ;
|
|
233
|
+
|
|
234
|
+
delay (200) ;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return 0 ;
|
|
238
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* gertboard.c:
|
|
3
|
+
* Simple test for the SPI bus on the Gertboard
|
|
4
|
+
*
|
|
5
|
+
* Hardware setup:
|
|
6
|
+
* D/A port 0 jumpered to A/D port 0.
|
|
7
|
+
*
|
|
8
|
+
* We output a sine wave on D/A port 0 and sample A/D port 0. We then
|
|
9
|
+
* copy this value to D/A port 1 and use a 'scope on both D/A ports
|
|
10
|
+
* to check all's well.
|
|
11
|
+
*
|
|
12
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
|
13
|
+
***********************************************************************
|
|
14
|
+
* This file is part of wiringPi:
|
|
15
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
16
|
+
*
|
|
17
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
18
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
19
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
20
|
+
* (at your option) any later version.
|
|
21
|
+
*
|
|
22
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
23
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
24
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
25
|
+
* GNU Lesser General Public License for more details.
|
|
26
|
+
*
|
|
27
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
28
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
29
|
+
***********************************************************************
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
#include <stdio.h>
|
|
33
|
+
#include <stdint.h>
|
|
34
|
+
#include <math.h>
|
|
35
|
+
|
|
36
|
+
#define B_SIZE 200
|
|
37
|
+
#undef DO_TIMING
|
|
38
|
+
|
|
39
|
+
#include <wiringPi.h>
|
|
40
|
+
#include <gertboard.h>
|
|
41
|
+
|
|
42
|
+
int main (void)
|
|
43
|
+
{
|
|
44
|
+
double angle ;
|
|
45
|
+
int i ;
|
|
46
|
+
uint32_t x1 ;
|
|
47
|
+
int buffer [B_SIZE] ;
|
|
48
|
+
|
|
49
|
+
#ifdef DO_TIMING
|
|
50
|
+
unsigned int now, then ;
|
|
51
|
+
#endif
|
|
52
|
+
|
|
53
|
+
printf ("Raspberry Pi Gertboard SPI test program\n") ;
|
|
54
|
+
|
|
55
|
+
if (wiringPiSetupSys () < 0)
|
|
56
|
+
return -1 ;
|
|
57
|
+
|
|
58
|
+
if (gertboardSPISetup () < 0)
|
|
59
|
+
return 1 ;
|
|
60
|
+
|
|
61
|
+
// Generate a Sine Wave
|
|
62
|
+
|
|
63
|
+
for (i = 0 ; i < B_SIZE ; ++i)
|
|
64
|
+
{
|
|
65
|
+
angle = ((double)i / (double)B_SIZE) * M_PI * 2.0 ;
|
|
66
|
+
buffer [i] = (int)rint ((sin (angle)) * 127.0 + 128.0) ;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
for (;;)
|
|
71
|
+
{
|
|
72
|
+
#ifdef DO_TIMING
|
|
73
|
+
then = millis () ;
|
|
74
|
+
#endif
|
|
75
|
+
|
|
76
|
+
for (i = 0 ; i < B_SIZE ; ++i)
|
|
77
|
+
{
|
|
78
|
+
gertboardAnalogWrite (0, buffer [i]) ;
|
|
79
|
+
|
|
80
|
+
#ifndef DO_TIMING
|
|
81
|
+
x1 = gertboardAnalogRead (0) ;
|
|
82
|
+
gertboardAnalogWrite (1, x1 >> 2) ; // 10-bit A/D, 8-bit D/A
|
|
83
|
+
#endif
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
#ifdef DO_TIMING
|
|
87
|
+
now = millis () ;
|
|
88
|
+
printf ("%4d mS, %9.7f S/sample", now - then, ((double)(now - then) / 1000.0) / (double)B_SIZE) ;
|
|
89
|
+
printf (" -> %9.4f samples/sec \n", 1 / (((double)(now - then) / 1000.0) / (double)B_SIZE)) ;
|
|
90
|
+
#endif
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return 0 ;
|
|
94
|
+
}
|