initial cleanup and mapping

This commit is contained in:
unknown
2016-08-18 21:52:18 +03:00
parent 1d89a05234
commit faf062af8b
155 changed files with 23233 additions and 0 deletions

81
examples/q2w/Makefile Normal file
View File

@ -0,0 +1,81 @@
#
# Makefile:
# wiringPi - Wiring Compatable library for the Raspberry Pi
# https://projects.drogon.net/wiring-pi
#
# Copyright (c) 2012-2013 Gordon Henderson
#################################################################################
# This file is part of wiringPi:
# Wiring Compatable library for the Raspberry Pi
#
# wiringPi is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wiringPi 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
#################################################################################
#DEBUG = -g -O0
DEBUG = -O3
CC = gcc
INCLUDE = -I/usr/local/include
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
LDFLAGS = -L/usr/local/lib
LDLIBS = -lwiringPi -lwiringPiDev -lpthread -lm
###############################################################################
SRC = blink.c button.c blink-io.c volts.c bright.c
OBJ = $(SRC:.c=.o)
BINS = $(SRC:.c=)
all: $(BINS)
blink: blink.o
@echo [link]
@$(CC) -o $@ blink.o $(LDFLAGS) $(LDLIBS)
blink-io: blink-io.o
@echo [link]
@$(CC) -o $@ blink-io.o $(LDFLAGS) $(LDLIBS)
button: button.o
@echo [link]
@$(CC) -o $@ button.o $(LDFLAGS) $(LDLIBS)
volts: volts.o
@echo [link]
@$(CC) -o $@ volts.o $(LDFLAGS) $(LDLIBS)
bright: bright.o
@echo [link]
@$(CC) -o $@ bright.o $(LDFLAGS) $(LDLIBS)
.c.o:
@echo [CC] $<
@$(CC) -c $(CFLAGS) $< -o $@
clean:
@echo "[Clean]"
@rm -f $(OBJ) *~ core tags $(BINS)
tags: $(SRC)
@echo [ctags]
@ctags $(SRC)
depend:
makedepend -Y $(SRC)
# DO NOT DELETE

79
examples/q2w/binary.c Normal file
View File

@ -0,0 +1,79 @@
/*
* binary.c:
* Using the Quick 2 wire 16-bit GPIO expansion board to output
* a binary counter.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <wiringPi.h>
#include <mcp23017.h>
#define Q2W_BASE 100
int main (void)
{
int i, bit ;
// Enable the on-goard GPIO
wiringPiSetup () ;
// Add in the mcp23017 on the q2w board
mcp23017Setup (Q2W_BASE, 0x20) ;
printf ("Raspberry Pi - quite2Wire MCP23017 Test\n") ;
// On-board button Input:
pinMode (0, INPUT) ;
// First 10 pins on q2w board as outputs:
for (i = 0 ; i < 10 ; ++i)
pinMode (Q2W_BASE + i, OUTPUT) ;
// Last pin as an input with the internal pull-up enabled
pinMode (Q2W_BASE + 15, INPUT) ;
pullUpDnControl (Q2W_BASE + 15, PUD_UP) ;
// Loop, outputting a binary number,
// Go faster with the button, or stop if the
// on-board button is pushed
for (;;)
{
for (i = 0 ; i < 1024 ; ++i)
{
for (bit = 0 ; bit < 10 ; ++bit)
digitalWrite (Q2W_BASE + bit, i & (1 << bit)) ;
while (digitalRead (0) == HIGH) // While pushed
delay (1) ;
if (digitalRead (Q2W_BASE + 15) == HIGH) // Not Pushed
delay (100) ;
}
}
return 0 ;
}

61
examples/q2w/blink-io.c Normal file
View File

@ -0,0 +1,61 @@
/*
* blink-io.c:
* Simple "blink" test for the Quick2Wire 16-pin IO board.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <wiringPi.h>
#include <mcp23017.h>
#define LED 1
#define Q2W_BASE 100
int main (void)
{
// Enable the on-goard GPIO
wiringPiSetup () ;
// Add in the mcp23017 on the q2w board
mcp23017Setup (Q2W_BASE, 0x20) ;
printf ("Raspberry Pi - Quick2Wire MCP23017 Blink Test\n") ;
// Blink the on-board LED as well as one on the mcp23017
pinMode (LED, OUTPUT) ;
pinMode (Q2W_BASE + 0, OUTPUT) ;
for (;;)
{
digitalWrite (LED, HIGH) ;
digitalWrite (Q2W_BASE + 0, HIGH) ;
delay (500) ;
digitalWrite (LED, LOW) ;
digitalWrite (Q2W_BASE + 0, LOW) ;
delay (500) ;
}
return 0 ;
}

50
examples/q2w/blink.c Normal file
View File

@ -0,0 +1,50 @@
/*
* blink.c:
* Simple "blink" test for the Quick2Wire interface board.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <wiringPi.h>
#define LED 1
int main (void)
{
// Enable the on-goard GPIO
wiringPiSetup () ;
printf ("Raspberry Pi - Quick2Wire Mainboard LED Blink Test\n") ;
pinMode (LED, OUTPUT) ;
for (;;)
{
digitalWrite (LED, HIGH) ;
delay (500) ;
digitalWrite (LED, LOW) ;
delay (500) ;
}
return 0 ;
}

37
examples/q2w/blink.sh Normal file
View File

@ -0,0 +1,37 @@
#!/bin/sh
#
# blink.sh:
# Standard "blink" program in wiringPi. Blinks an LED connected
# to the LED on the Quick2Wire board
#
# Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
#######################################################################
# This file is part of wiringPi:
# https://projects.drogon.net/raspberry-pi/wiringpi/
#
# wiringPi is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wiringPi 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
#######################################################################
# LED Pin - wiringPi pin 1 is BCM_GPIO 18.
LED=1
gpio mode $LED out
while true; do
gpio write $LED 1
sleep 0.5
gpio write $LED 0
sleep 0.5
done

59
examples/q2w/bright.c Normal file
View File

@ -0,0 +1,59 @@
/*
* bright.c:
* Vary the Q2W LED brightness with the analog card
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <wiringPi.h>
#include <pcf8591.h>
#define LED 1
#define Q2W_ABASE 120
int main (void)
{
int value ;
// Enable the on-goard GPIO
wiringPiSetup () ;
// Add in the pcf8591 on the q2w board
pcf8591Setup (Q2W_ABASE, 0x48) ;
printf ("Raspberry Pi - Quick2Wire Analog Test\n") ;
// Setup the LED
pinMode (LED, PWM_OUTPUT) ;
pwmWrite (LED, 0) ;
for (;;)
{
value = analogRead (Q2W_ABASE + 0) ;
pwmWrite (LED, value * 4) ;
delay (10) ;
}
return 0 ;
}

63
examples/q2w/button.c Normal file
View File

@ -0,0 +1,63 @@
/*
* button.c:
* Simple button test for the Quick2Wire interface board.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <wiringPi.h>
#define BUTTON 0
#define LED1 1
#define LED2 7
int main (void)
{
// Enable the on-goard GPIO
wiringPiSetup () ;
printf ("Raspberry Pi - Quick2Wire Mainboard Button & LED Test\n") ;
pinMode (BUTTON, INPUT) ;
pinMode (LED1, OUTPUT) ;
pinMode (LED2, OUTPUT) ;
digitalWrite (LED1, HIGH) ; // On-board LED on
digitalWrite (LED2, LOW) ; // 2nd LED off
for (;;)
{
if (digitalRead (BUTTON) == HIGH) // Swap LED states
{
digitalWrite (LED1, LOW) ;
digitalWrite (LED2, HIGH) ;
while (digitalRead (BUTTON) == HIGH)
delay (1) ;
digitalWrite (LED1, HIGH) ;
digitalWrite (LED2, LOW) ;
}
delay (1) ;
}
return 0 ;
}

62
examples/q2w/volts.c Normal file
View File

@ -0,0 +1,62 @@
/*
* volts.c:
* Read in all 4 analogs on the Q2W analog board.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <wiringPi.h>
#include <pcf8591.h>
#define LED 1
#define Q2W_ABASE 120
int main (void)
{
int value, pin ;
// Enable the on-goard GPIO
wiringPiSetup () ;
pinMode (LED, OUTPUT) ; // On-board LED
// Add in the pcf8591 on the q2w board
pcf8591Setup (Q2W_ABASE, 0x48) ;
printf ("Raspberry Pi - Quick2Wire Voltmeter\n") ;
for (;;)
{
for (pin = 0 ; pin < 4 ; ++pin)
{
value = analogRead (Q2W_ABASE + pin) ;
printf (" %5.2f", (double)value * 3.3 / 255.0) ;
}
printf ("\r") ; fflush (stdout) ;
delay (100) ;
digitalWrite (LED, !digitalRead (LED)) ; // Flicker the LED
}
return 0 ;
}