001package com.pi4j.wiringpi;
002
003/*
004 * #%L
005 * **********************************************************************
006 * ORGANIZATION  :  Pi4J
007 * PROJECT       :  Pi4J :: Java Library (Core)
008 * FILENAME      :  Shift.java  
009 * 
010 * This file is part of the Pi4J project. More information about 
011 * this project can be found here:  http://www.pi4j.com/
012 * **********************************************************************
013 * %%
014 * Copyright (C) 2012 - 2013 Pi4J
015 * %%
016 * Licensed under the Apache License, Version 2.0 (the "License");
017 * you may not use this file except in compliance with the License.
018 * You may obtain a copy of the License at
019 * 
020 *      http://www.apache.org/licenses/LICENSE-2.0
021 * 
022 * Unless required by applicable law or agreed to in writing, software
023 * distributed under the License is distributed on an "AS IS" BASIS,
024 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
025 * See the License for the specific language governing permissions and
026 * limitations under the License.
027 * #L%
028 */
029
030
031import com.pi4j.util.NativeLibraryLoader;
032
033/**
034 * <h1>WiringPi Shift Library</h1>
035 * 
036 * <p>
037 * WiringPi includes a shift library which more or less mimics the one in the Arduino system. This
038 * allows you to shift 8-bit data values out of the Pi, or into the Pi from devices such as
039 * shift-registers (e.g. 74,595) and so-on, although it can also be used in some bit-banging
040 * scenarios.
041 * </p>
042 * 
043 * <p>
044 * Before using the Pi4J library, you need to ensure that the Java VM in configured with access to
045 * the following system libraries:
046 * <ul>
047 * <li>pi4j</li>
048 * <li>wiringPi</li>
049 * </ul>
050 * <blockquote> This library depends on the wiringPi native system library.</br> (developed by
051 * Gordon Henderson @ <a href="https://projects.drogon.net/">https://projects.drogon.net/</a>)
052 * </blockquote>
053 * </p>
054 * 
055 * @see <a href="http://www.pi4j.com/">http://www.pi4j.com/</a>
056 * @see <a
057 *      href="https://projects.drogon.net/raspberry-pi/wiringpi/shift-library/">https://projects.drogon.net/raspberry-pi/wiringpi/shift-library/</a>
058 * @author Robert Savage (<a
059 *         href="http://www.savagehomeautomation.com">http://www.savagehomeautomation.com</a>)
060 */
061public class Shift {
062
063    public static final int LSBFIRST = 0;
064    public static final int MSBFIRST = 1;
065
066    // private constructor 
067    private Shift() {
068        // forbid object construction 
069    }
070    
071    static {
072        // Load the platform library
073        NativeLibraryLoader.load("pi4j", "libpi4j.so");
074    }
075
076    /**
077     * <p>uint8_t shiftIn (uint8_t dPin, uint8_t cPin, uint8_t order);</p>
078     * 
079     * <p>
080     * This shifts an 8-bit data value in with the data appearing on the dPin and the clock being
081     * sent out on the cPin. Order is either LSBFIRST or MSBFIRST. The data is sampled after the
082     * cPin goes high. (So cPin high, sample data, cPin low, repeat for 8 bits) The 8-bit value is
083     * returned by the function.
084     * </p>
085     * 
086     * @see <a
087     *      href="https://projects.drogon.net/raspberry-pi/wiringpi/shift-library/">https://projects.drogon.net/raspberry-pi/wiringpi/shift-library/</a>
088     * 
089     * @param dPin
090     * @param cPin
091     * @param order
092     * @return <p>
093     *         The 8-bit shifted value is returned by the function.
094     *         </p>
095     */
096    public static native byte shiftIn(byte dPin, byte cPin, byte order);
097
098    /**
099     * <p>void shiftOut (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val);</p>
100     * 
101     * <p>
102     * The shifts an 8-bit data value val out with the data being sent out on dPin and the clock
103     * being sent out on the cPin. order is as above. Data is clocked out on the rising or falling
104     * edge; ie. dPin is set, then cPin is taken high then low and repeated for the 8 bits.
105     * </p>
106     * 
107     * @see <a
108     *      href="https://projects.drogon.net/raspberry-pi/wiringpi/shift-library/">https://projects.drogon.net/raspberry-pi/wiringpi/shift-library/</a>
109     * 
110     * @param dPin
111     * @param cPin
112     * @param order
113     * @param val
114     */
115    public static native void shiftOut(byte dPin, byte cPin, byte order, byte val);
116}