/*
 * Copyright 2016, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.androidthings.button;

import android.os.Build;

import com.google.android.things.pio.PeripheralManagerService;

import java.util.List;

@SuppressWarnings("WeakerAccess")
public class BoardDefaults {
    private static final String DEVICE_EDISON_ARDUINO = "edison_arduino";
    private static final String DEVICE_EDISON = "edison";
    private static final String DEVICE_RPI3 = "rpi3";
    private static final String DEVICE_NXP = "imx6ul";
    private static String sBoardVariant = "";

    /**
     * Return the GPIO pin that the LED is connected on.
     * For example, on Intel Edison Arduino breakout, pin "IO13" is connected to an onboard LED
     * that turns on when the GPIO pin is HIGH, and off when low.
     */
    public static String getGPIOForLED() {
        switch (getBoardVariant()) {
            case DEVICE_EDISON_ARDUINO:
                return "IO13";
            case DEVICE_EDISON:
                return "GP45";
            case DEVICE_RPI3:
                return "BCM6";
            case DEVICE_NXP:
                return "GPIO4_IO21";
            default:
                throw new IllegalStateException("Unknown Build.DEVICE " + Build.DEVICE);
        }
    }

    /**
     * Return the GPIO pin that the Button is connected on.
     */
    public static String getGPIOForButton() {
        switch (getBoardVariant()) {
            case DEVICE_EDISON_ARDUINO:
                return "IO12";
            case DEVICE_EDISON:
                return "GP44";
            case DEVICE_RPI3:
                return "BCM21";
            case DEVICE_NXP:
                return "GPIO4_IO20";
            default:
                throw new IllegalStateException("Unknown Build.DEVICE " + Build.DEVICE);
        }
    }

    private static String getBoardVariant() {
        if (!sBoardVariant.isEmpty()) {
            return sBoardVariant;
        }
        sBoardVariant = Build.DEVICE;
        // For the edison check the pin prefix
        // to always return Edison Breakout pin name when applicable.
        if (sBoardVariant.equals(DEVICE_EDISON)) {
            PeripheralManagerService pioService = new PeripheralManagerService();
            List<String> gpioList = pioService.getGpioList();
            if (gpioList.size() != 0) {
                String pin = gpioList.get(0);
                if (pin.startsWith("IO")) {
                    sBoardVariant = DEVICE_EDISON_ARDUINO;
                }
            }
        }
        return sBoardVariant;
    }
}

@@ -1006,65 +1006,183 @@
 ICE_
-RPI3 = %22rpi3%22;%0A    private static final String DEVICE_NXP
+JOULE = %22joule%22;%0A    private static final String DEVICE_RPI3 = %22rpi3%22;%0A    private static final String DEVICE_PICO = %22imx6ul_pico%22;%0A    private static final String DEVICE_VVDN
  = %22
@@ -1187,16 +1187,21 @@
  %22imx6ul
+_iopb
 %22;%0A    p
@@ -1691,16 +1691,80 @@
 %22GP45%22;%0A
+            case DEVICE_JOULE:%0A                return %22LED100%22;%0A
         
@@ -1832,35 +1832,36 @@
     case DEVICE_
-NXP
+PICO
 :%0A              
@@ -1879,24 +1879,91 @@
 PIO4_IO21%22;%0A
+            case DEVICE_VVDN:%0A                return %22GPIO3_IO06%22;%0A
             
@@ -2370,16 +2370,87 @@
 %22GP44%22;%0A
+            case DEVICE_JOULE:%0A                return %22FLASH_TRIGGER%22;%0A
         
@@ -2531,11 +2531,12 @@
 ICE_
-NXP
+PICO
 :%0A  
@@ -2566,24 +2566,91 @@
 PIO4_IO20%22;%0A
+            case DEVICE_VVDN:%0A                return %22GPIO3_IO01%22;%0A
             

Add BoardDefaults for Intel and NXP platforms.