forked from androidthings/doorbell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for more boards e.g. iMX7d
Add more board variants to support their respective namings of GPIO pins for input button Bug: 63540960 Change-Id: Iaa1c4a03f55e74c6d95cc2334bdb1237671f8e08
- Loading branch information
Showing
2 changed files
with
86 additions
and
14 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
app/src/main/java/com/example/androidthings/doorbell/BoardDefaults.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* 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.doorbell; | ||
|
||
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_JOULE = "joule"; | ||
private static final String DEVICE_RPI3 = "rpi3"; | ||
private static final String DEVICE_IMX6UL_PICO = "imx6ul_pico"; | ||
private static final String DEVICE_IMX6UL_VVDN = "imx6ul_iopb"; | ||
private static final String DEVICE_IMX7D_PICO = "imx7d_pico"; | ||
private static String sBoardVariant = ""; | ||
|
||
/** | ||
* Return the GPIO pin that the Button is connected on. | ||
*/ | ||
public static String getGPIOForButton() { | ||
switch (getBoardVariant()) { | ||
case DEVICE_RPI3: | ||
return "BCM21"; | ||
case DEVICE_IMX7D_PICO: | ||
return "GPIO_174"; | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters