wiringpi 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/wiringpi/WiringPi/devLib/ds1302.c +240 -0
- data/ext/wiringpi/WiringPi/devLib/ds1302.h +44 -0
- data/ext/wiringpi/WiringPi/devLib/font.h +2577 -0
- data/ext/wiringpi/WiringPi/devLib/gertboard.c +164 -0
- data/ext/wiringpi/WiringPi/devLib/gertboard.h +45 -0
- data/ext/wiringpi/WiringPi/devLib/lcd.c +495 -0
- data/ext/wiringpi/WiringPi/devLib/lcd.h +52 -0
- data/ext/wiringpi/WiringPi/devLib/lcd128x64.c +673 -0
- data/ext/wiringpi/WiringPi/devLib/lcd128x64.h +39 -0
- data/ext/wiringpi/WiringPi/devLib/maxdetect.c +165 -0
- data/ext/wiringpi/{serial.h → WiringPi/devLib/maxdetect.h} +14 -15
- data/ext/wiringpi/WiringPi/devLib/piFace.c +112 -0
- data/ext/wiringpi/WiringPi/devLib/piFace.h +32 -0
- data/ext/wiringpi/WiringPi/devLib/piFaceOld.c +178 -0
- data/ext/wiringpi/WiringPi/devLib/piGlow.c +118 -0
- data/ext/wiringpi/WiringPi/devLib/piGlow.h +45 -0
- data/ext/wiringpi/WiringPi/devLib/piNes.c +113 -0
- data/ext/wiringpi/WiringPi/devLib/piNes.h +45 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/7segments.c +221 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/buttons.c +83 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/gertboard.c +96 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/record.c +60 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/temperature.c +78 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/voltmeter.c +73 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/vumeter.c +152 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/blink.c +59 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/buttons.c +103 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/ladder.c +337 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/metro.c +111 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/motor.c +120 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/reaction.c +194 -0
- data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow0.c +51 -0
- data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow1.c +258 -0
- data/ext/wiringpi/WiringPi/examples/PiGlow/piglow.c +176 -0
- data/ext/wiringpi/WiringPi/examples/blink.c +48 -0
- data/ext/wiringpi/WiringPi/examples/blink12.c +111 -0
- data/ext/wiringpi/WiringPi/examples/blink12drcs.c +125 -0
- data/ext/wiringpi/WiringPi/examples/blink6drcs.c +115 -0
- data/ext/wiringpi/WiringPi/examples/blink8.c +57 -0
- data/ext/wiringpi/WiringPi/examples/clock.c +201 -0
- data/ext/wiringpi/WiringPi/examples/delayTest.c +107 -0
- data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -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 +110 -0
- data/ext/wiringpi/WiringPi/examples/lcd-adafruit.c +347 -0
- data/ext/wiringpi/WiringPi/examples/lcd.c +286 -0
- data/ext/wiringpi/WiringPi/examples/lowPower.c +68 -0
- data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
- data/ext/wiringpi/WiringPi/examples/okLed.c +82 -0
- data/ext/wiringpi/WiringPi/examples/pwm.c +58 -0
- data/ext/wiringpi/WiringPi/examples/q2w/binary.c +79 -0
- data/ext/wiringpi/WiringPi/examples/q2w/blink-io.c +61 -0
- data/ext/wiringpi/WiringPi/examples/q2w/blink.c +50 -0
- data/ext/wiringpi/WiringPi/examples/q2w/bright.c +59 -0
- data/ext/wiringpi/WiringPi/examples/q2w/button.c +63 -0
- data/ext/wiringpi/WiringPi/examples/q2w/volts.c +62 -0
- data/ext/wiringpi/WiringPi/examples/rht03.c +69 -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/softPwm.c +89 -0
- data/ext/wiringpi/WiringPi/examples/softTone.c +54 -0
- data/ext/wiringpi/WiringPi/examples/speed.c +95 -0
- data/ext/wiringpi/WiringPi/examples/spiSpeed.c +118 -0
- data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
- data/ext/wiringpi/WiringPi/gpio/gpio.c +1351 -0
- data/ext/wiringpi/WiringPi/gpio/pins.c +33 -0
- data/ext/wiringpi/WiringPi/gpio/readall.c +334 -0
- data/ext/wiringpi/WiringPi/gpio/version.h +1 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +201 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/max31855.c +81 -0
- data/ext/wiringpi/WiringPi/wiringPi/max31855.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/max5322.c +84 -0
- data/ext/wiringpi/WiringPi/wiringPi/max5322.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +149 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016.c +164 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016reg.h +48 -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 +189 -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/mcp3002.c +76 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3002.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3004.c +76 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3004.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3422.c +110 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3422.h +43 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp4802.c +76 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp4802.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8574.c +126 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8574.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8591.c +90 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8591.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +51 -0
- data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
- data/ext/wiringpi/WiringPi/wiringPi/sn3218.c +75 -0
- data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +166 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +35 -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 +150 -0
- data/ext/wiringpi/WiringPi/wiringPi/softTone.h +39 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.c +109 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +2007 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +224 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +232 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +136 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +36 -0
- data/ext/wiringpi/{serial.c → WiringPi/wiringPi/wiringSerial.c} +38 -29
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
- data/ext/wiringpi/{wiringShift.c → WiringPi/wiringPi/wiringShift.c} +3 -4
- data/ext/wiringpi/{wiringShift.h → WiringPi/wiringPi/wiringShift.h} +5 -5
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +731 -0
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.h +26 -0
- data/ext/wiringpi/extconf.rb +7 -1
- data/ext/wiringpi/wiringpi_wrap.c +1741 -218
- data/lib/wiringpi.rb +24 -222
- data/lib/wiringpi/event.rb +21 -0
- data/lib/wiringpi/gpio.rb +139 -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
- metadata +146 -22
- data/ext/wiringpi/wiringPi.c +0 -729
- data/ext/wiringpi/wiringPi.h +0 -69
@@ -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,23 @@
|
|
1
|
+
/*
|
2
|
+
* file.c:
|
3
|
+
*
|
4
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
5
|
+
***********************************************************************
|
6
|
+
* This file is part of wiringPi:
|
7
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
8
|
+
*
|
9
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
10
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
11
|
+
* the Free Software Foundation, either version 3 of the License, or
|
12
|
+
* (at your option) any later version.
|
13
|
+
*
|
14
|
+
* wiringPi is distributed in the hope that it will be useful,
|
15
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
* GNU Lesser General Public License for more details.
|
18
|
+
*
|
19
|
+
* You should have received a copy of the GNU Lesser General Public License
|
20
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
***********************************************************************
|
22
|
+
*/
|
23
|
+
|
@@ -0,0 +1,118 @@
|
|
1
|
+
/*
|
2
|
+
* isr-osc.c:
|
3
|
+
* Wait for Interrupt test program - ISR method - interrupt oscillator
|
4
|
+
*
|
5
|
+
* How to test:
|
6
|
+
*
|
7
|
+
* IMPORTANT: To run this test we connect 2 GPIO pins together, but
|
8
|
+
* before we do that YOU must make sure that they are both setup
|
9
|
+
* the right way. If they are set to outputs and one is high and one low,
|
10
|
+
* then you connect the wire, you'll create a short and that won't be good.
|
11
|
+
*
|
12
|
+
* Before making the connection, type:
|
13
|
+
* gpio mode 0 output
|
14
|
+
* gpio write 0 0
|
15
|
+
* gpio mode 1 input
|
16
|
+
* then you can connect them together.
|
17
|
+
*
|
18
|
+
* Run the program, then:
|
19
|
+
* gpio write 0 1
|
20
|
+
* gpio write 0 0
|
21
|
+
*
|
22
|
+
* at which point it will trigger an interrupt and the program will
|
23
|
+
* then do the up/down toggling for itself and run at full speed, and
|
24
|
+
* it will report the number of interrupts recieved every second.
|
25
|
+
*
|
26
|
+
* Copyright (c) 2013 Gordon Henderson. projects@drogon.net
|
27
|
+
***********************************************************************
|
28
|
+
* This file is part of wiringPi:
|
29
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
30
|
+
*
|
31
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
32
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
33
|
+
* the Free Software Foundation, either version 3 of the License, or
|
34
|
+
* (at your option) any later version.
|
35
|
+
*
|
36
|
+
* wiringPi is distributed in the hope that it will be useful,
|
37
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
38
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
39
|
+
* GNU Lesser General Public License for more details.
|
40
|
+
*
|
41
|
+
* You should have received a copy of the GNU Lesser General Public License
|
42
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
43
|
+
***********************************************************************
|
44
|
+
*/
|
45
|
+
|
46
|
+
#include <stdio.h>
|
47
|
+
#include <string.h>
|
48
|
+
#include <errno.h>
|
49
|
+
#include <stdlib.h>
|
50
|
+
#include <wiringPi.h>
|
51
|
+
|
52
|
+
|
53
|
+
// What GPIO input are we using?
|
54
|
+
// This is a wiringPi pin number
|
55
|
+
|
56
|
+
#define OUT_PIN 0
|
57
|
+
#define IN_PIN 1
|
58
|
+
|
59
|
+
// globalCounter:
|
60
|
+
// Global variable to count interrupts
|
61
|
+
// Should be declared volatile to make sure the compiler doesn't cache it.
|
62
|
+
|
63
|
+
static volatile int globalCounter = 0 ;
|
64
|
+
|
65
|
+
/*
|
66
|
+
* myInterrupt:
|
67
|
+
*********************************************************************************
|
68
|
+
*/
|
69
|
+
|
70
|
+
void myInterrupt (void)
|
71
|
+
{
|
72
|
+
digitalWrite (OUT_PIN, 1) ;
|
73
|
+
++globalCounter ;
|
74
|
+
digitalWrite (OUT_PIN, 0) ;
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
/*
|
79
|
+
*********************************************************************************
|
80
|
+
* main
|
81
|
+
*********************************************************************************
|
82
|
+
*/
|
83
|
+
|
84
|
+
int main (void)
|
85
|
+
{
|
86
|
+
int myCounter = 0 ;
|
87
|
+
int lastCounter = 0 ;
|
88
|
+
|
89
|
+
if (wiringPiSetup () < 0)
|
90
|
+
{
|
91
|
+
fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno)) ;
|
92
|
+
return 1 ;
|
93
|
+
}
|
94
|
+
|
95
|
+
pinMode (OUT_PIN, OUTPUT) ;
|
96
|
+
pinMode (IN_PIN, INPUT) ;
|
97
|
+
|
98
|
+
if (wiringPiISR (IN_PIN, INT_EDGE_FALLING, &myInterrupt) < 0)
|
99
|
+
{
|
100
|
+
fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
|
101
|
+
return 1 ;
|
102
|
+
}
|
103
|
+
|
104
|
+
for (;;)
|
105
|
+
{
|
106
|
+
printf ("Waiting ... ") ; fflush (stdout) ;
|
107
|
+
|
108
|
+
while (myCounter == globalCounter)
|
109
|
+
delay (1000) ;
|
110
|
+
|
111
|
+
printf (" Done. counter: %6d: %6d\n",
|
112
|
+
globalCounter, myCounter - lastCounter) ;
|
113
|
+
lastCounter = myCounter ;
|
114
|
+
myCounter = globalCounter ;
|
115
|
+
}
|
116
|
+
|
117
|
+
return 0 ;
|
118
|
+
}
|