├── ADCDemo ├── Android.mk ├── AndroidManifest.xml ├── libs │ ├── arm64-v8a │ │ └── libfriendlyarm-things.so │ └── armeabi │ │ └── libfriendlyarm-things.so ├── res │ ├── drawable │ │ └── icon.png │ ├── layout │ │ ├── adc_listview_item.xml │ │ └── adc_main.xml │ └── values │ │ └── strings.xml └── src │ └── com │ └── friendlyarm │ ├── ADCDemo │ ├── ADC.java │ └── ADCDemoMainActivity.java │ ├── FriendlyThings │ ├── BoardType.java │ ├── FileCtlEnum.java │ ├── GPIOEnum.java │ ├── HardwareControler.java │ ├── SPI.java │ ├── SPIEnum.java │ └── WatchDogEnum.java │ └── Utils │ └── CommonFuncs.java ├── GPIO_LED_Demo ├── Android.mk ├── AndroidManifest.xml ├── build.sh ├── libs │ ├── arm64-v8a │ │ └── libfriendlyarm-things.so │ └── armeabi │ │ └── libfriendlyarm-things.so ├── res │ ├── drawable │ │ ├── gray_thumb.xml │ │ ├── gray_track.xml │ │ ├── green_thumb.xml │ │ ├── green_track.xml │ │ ├── icon.png │ │ ├── red_thumb.xml │ │ ├── thumb.xml │ │ └── track.xml │ ├── layout │ │ ├── gpiodemo_main.xml │ │ └── listview_item.xml │ └── values │ │ └── strings.xml └── src │ └── com │ └── friendlyarm │ ├── FriendlyThings │ ├── BoardType.java │ ├── FileCtlEnum.java │ ├── GPIOEnum.java │ ├── HardwareControler.java │ ├── SPI.java │ ├── SPIEnum.java │ └── WatchDogEnum.java │ ├── GPIODemo │ ├── GPIODemoMainActivity.java │ └── GPIOPin.java │ └── Utils │ └── CommonFuncs.java ├── I2C_LCD1602_Demo ├── .settings │ └── org.eclipse.jdt.core.prefs ├── Android.mk ├── AndroidManifest.xml ├── build.sh ├── libs │ ├── arm64-v8a │ │ └── libfriendlyarm-things.so │ └── armeabi │ │ └── libfriendlyarm-things.so ├── res │ ├── drawable │ │ └── icon.png │ ├── layout │ │ └── mainactivity.xml │ └── values │ │ └── strings.xml └── src │ └── com │ └── friendlyarm │ ├── FriendlyThings │ ├── BoardType.java │ ├── FileCtlEnum.java │ ├── GPIOEnum.java │ ├── HardwareControler.java │ ├── SPI.java │ ├── SPIEnum.java │ └── WatchDogEnum.java │ ├── LCD1602Demo │ ├── MainActivity.java │ └── PCF8574.java │ └── Utils │ └── CommonFuncs.java ├── PWMDemo-Rockchip ├── Android.mk ├── AndroidManifest.xml ├── libs │ ├── arm64-v8a │ │ └── libfriendlyarm-things.so │ └── armeabi │ │ └── libfriendlyarm-things.so ├── res │ ├── drawable │ │ └── icon.png │ ├── layout │ │ └── pwmtestingactivity.xml │ └── values │ │ └── strings.xml └── src │ └── com │ └── friendlyarm │ ├── FriendlyThings │ ├── BoardType.java │ ├── FileCtlEnum.java │ ├── GPIOEnum.java │ ├── HardwareControler.java │ ├── SPI.java │ ├── SPIEnum.java │ └── WatchDogEnum.java │ ├── PWMDemo │ └── PWMTestingActivity.java │ └── Utils │ ├── BorderScrollView.java │ └── CommonFuncs.java ├── PWMDemo ├── Android.mk ├── AndroidManifest.xml ├── build.sh ├── libs │ ├── arm64-v8a │ │ └── libfriendlyarm-things.so │ └── armeabi │ │ └── libfriendlyarm-things.so ├── res │ ├── drawable │ │ └── icon.png │ ├── layout │ │ └── pwmtestingactivity.xml │ └── values │ │ └── strings.xml └── src │ └── com │ └── friendlyarm │ ├── FriendlyThings │ ├── BoardType.java │ ├── FileCtlEnum.java │ ├── GPIOEnum.java │ ├── HardwareControler.java │ ├── SPI.java │ ├── SPIEnum.java │ └── WatchDogEnum.java │ ├── PWMDemo │ └── PWMTestingActivity.java │ └── Utils │ ├── BorderScrollView.java │ └── CommonFuncs.java ├── README.md ├── RTC_Demo-Rockchip ├── Android.mk ├── AndroidManifest.xml ├── libs │ ├── arm64-v8a │ │ └── libfriendlyarm-things.so │ └── armeabi │ │ └── libfriendlyarm-things.so ├── res │ ├── drawable │ │ └── icon.png │ ├── layout │ │ └── main.xml │ └── values │ │ └── strings.xml ├── src │ └── com │ │ └── friendlyarm │ │ ├── FriendlyThings │ │ ├── BoardType.java │ │ ├── FileCtlEnum.java │ │ ├── GPIOEnum.java │ │ ├── HardwareControler.java │ │ ├── SPI.java │ │ ├── SPIEnum.java │ │ └── WatchDogEnum.java │ │ ├── RTCDemo │ │ └── RTCDemoMainActivity.java │ │ └── Utils │ │ └── CommonFuncs.java └── sync.sh ├── SDCardDemo ├── Android.mk ├── AndroidManifest.xml ├── build.sh ├── ic_launcher-web.png ├── res │ ├── drawable-hdpi │ │ ├── ic_action_search.png │ │ └── ic_launcher.png │ ├── drawable-ldpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ ├── ic_action_search.png │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ ├── ic_action_search.png │ │ └── ic_launcher.png │ ├── layout │ │ └── activity_main.xml │ ├── menu │ │ └── activity_main.xml │ ├── values-v11 │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ └── values │ │ ├── strings.xml │ │ └── styles.xml └── src │ └── com │ └── FriendlyARM │ └── sdcarddemo │ └── MainActivity.java ├── SPI_OLED_Demo ├── .classpath ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs ├── Android.mk ├── AndroidManifest.xml ├── Smart4418SDK+OLED.png ├── build.sh ├── libs │ ├── arm64-v8a │ │ └── libfriendlyarm-things.so │ └── armeabi │ │ └── libfriendlyarm-things.so ├── project.properties ├── res │ ├── drawable │ │ └── icon.png │ ├── layout │ │ └── mainactivity.xml │ └── values │ │ └── strings.xml └── src │ └── com │ └── friendlyarm │ ├── FriendlyThings │ ├── BoardType.java │ ├── FileCtlEnum.java │ ├── GPIOEnum.java │ ├── HardwareControler.java │ ├── SPI.java │ ├── SPIEnum.java │ └── WatchDogEnum.java │ ├── SPI_OLED │ ├── MainActivity.java │ └── OLED.java │ └── Utils │ └── CommonFuncs.java ├── SerialPortDemo ├── .classpath ├── Android.mk ├── AndroidManifest.xml ├── libs │ ├── arm64-v8a │ │ └── libfriendlyarm-things.so │ └── armeabi │ │ └── libfriendlyarm-things.so ├── res │ ├── drawable │ │ └── icon.png │ ├── layout │ │ ├── serialport_dataprocessview.xml │ │ └── serialport_dataprocessview_landscape.xml │ └── values │ │ └── strings.xml └── src │ └── com │ └── friendlyarm │ ├── FriendlyThings │ ├── BoardType.java │ ├── FileCtlEnum.java │ ├── GPIOEnum.java │ ├── HardwareControler.java │ ├── SPI.java │ ├── SPIEnum.java │ └── WatchDogEnum.java │ ├── SerialPortDemo │ └── SerialPortDataProcessView.java │ └── Utils │ ├── BorderScrollView.java │ └── CommonFuncs.java └── WatchDogDemo-Rockchip ├── Android.mk ├── AndroidManifest.xml ├── libs ├── arm64-v8a │ └── libfriendlyarm-things.so └── armeabi │ └── libfriendlyarm-things.so ├── res ├── drawable │ └── icon.png ├── layout │ └── main.xml └── values │ ├── colors.xml │ └── strings.xml ├── src └── com │ └── friendlyarm │ ├── FriendlyThings │ ├── BoardType.java │ ├── FileCtlEnum.java │ ├── GPIOEnum.java │ ├── HardwareControler.java │ ├── SPI.java │ ├── SPIEnum.java │ └── WatchDogEnum.java │ ├── Utils │ └── CommonFuncs.java │ └── WatchDogDemo │ └── WatchdogSampleActivity.java └── sync.sh /ADCDemo/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_SRC_FILES := $(call all-subdir-java-files) 5 | 6 | LOCAL_PACKAGE_NAME := ADCDemo 7 | 8 | LOCAL_PRIVATE_PLATFORM_APIS := true 9 | LOCAL_PRIVILEGED_MODULE := true 10 | LOCAL_CERTIFICATE := platform 11 | LOCAL_MODULE_TAGS := optional 12 | LOCAL_CFLAGS := -lfriendlyarm-things 13 | 14 | include $(BUILD_PACKAGE) 15 | -------------------------------------------------------------------------------- /ADCDemo/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /ADCDemo/libs/arm64-v8a/libfriendlyarm-things.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/ADCDemo/libs/arm64-v8a/libfriendlyarm-things.so -------------------------------------------------------------------------------- /ADCDemo/libs/armeabi/libfriendlyarm-things.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/ADCDemo/libs/armeabi/libfriendlyarm-things.so -------------------------------------------------------------------------------- /ADCDemo/res/drawable/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/ADCDemo/res/drawable/icon.png -------------------------------------------------------------------------------- /ADCDemo/res/layout/adc_listview_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 15 | 16 | 26 | 27 | -------------------------------------------------------------------------------- /ADCDemo/res/layout/adc_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 9 | 10 | -------------------------------------------------------------------------------- /ADCDemo/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | ADC Sample 4 | ADC Sample 5 | 6 | -------------------------------------------------------------------------------- /ADCDemo/src/com/friendlyarm/ADCDemo/ADC.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.ADCDemo; 2 | 3 | public class ADC { 4 | 5 | int value = 0; 6 | String name = null; 7 | 8 | public ADC(int value, String name) { 9 | super(); 10 | this.value = value; 11 | this.name = name; 12 | } 13 | 14 | public int getValue() { 15 | return value; 16 | } 17 | 18 | public void setValue(int value) { 19 | this.value = value; 20 | } 21 | 22 | public String getName() { 23 | return name; 24 | } 25 | 26 | public void setName(String name) { 27 | this.name = name; 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /ADCDemo/src/com/friendlyarm/FriendlyThings/FileCtlEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | 3 | public class FileCtlEnum { 4 | /* File Flag */ 5 | public final static int O_ACCMODE = 00000003; 6 | public final static int O_RDONLY = 00000000; 7 | public final static int O_WRONLY = 00000001; 8 | public final static int O_RDWR = 00000002; 9 | public final static int O_CREAT = 00000100; /* not fcntl */ 10 | public final static int O_EXCL = 00000200; /* not fcntl */ 11 | public final static int O_NOCTTY = 00000400; /* not fcntl */ 12 | public final static int O_TRUNC = 00001000; /* not fcntl */ 13 | public final static int O_APPEND = 00002000; 14 | public final static int O_NONBLOCK = 00004000; 15 | public final static int O_DSYNC = 00010000; /* used to be O_SYNC, see below */ 16 | public final static int FASYNC = 00020000; /* fcntl, for BSD compatibility */ 17 | public final static int O_DIRECT = 00040000; /* direct disk access hint */ 18 | public final static int O_LARGEFILE = 00100000; 19 | public final static int O_DIRECTORY = 00200000; /* must be a directory */ 20 | public final static int O_NOFOLLOW = 00400000; /* don't follow links */ 21 | public final static int O_NOATIME = 01000000; 22 | public final static int O_CLOEXEC = 02000000; /* set close_on_exec */ 23 | } 24 | -------------------------------------------------------------------------------- /ADCDemo/src/com/friendlyarm/FriendlyThings/GPIOEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | 3 | /* 4 | GPIO signals have paths like /sys/class/gpio/gpio42/ (for GPIO #42) 5 | and have the following read/write attributes: 6 | 7 | /sys/class/gpio/gpioN/ 8 | 9 | "direction" ... reads as either "in" or "out". This value may 10 | normally be written. Writing as "out" defaults to 11 | initializing the value as low. To ensure glitch free 12 | operation, values "low" and "high" may be written to 13 | configure the GPIO as an output with that initial value. 14 | 15 | Note that this attribute *will not exist* if the kernel 16 | doesn't support changing the direction of a GPIO, or 17 | it was exported by kernel code that didn't explicitly 18 | allow userspace to reconfigure this GPIO's direction. 19 | 20 | "value" ... reads as either 0 (low) or 1 (high). If the GPIO 21 | is configured as an output, this value may be written; 22 | any nonzero value is treated as high. 23 | 24 | If the pin can be configured as interrupt-generating interrupt 25 | and if it has been configured to generate interrupts (see the 26 | description of "edge"), you can poll(2) on that file and 27 | poll(2) will return whenever the interrupt was triggered. If 28 | you use poll(2), set the events POLLPRI and POLLERR. If you 29 | use select(2), set the file descriptor in exceptfds. After 30 | poll(2) returns, either lseek(2) to the beginning of the sysfs 31 | file and read the new value or close the file and re-open it 32 | to read the value. 33 | */ 34 | 35 | public class GPIOEnum { 36 | //Direction 37 | public final static int IN = 1; 38 | public final static int OUT = 2; 39 | 40 | //Value 41 | public final static int LOW = 0; 42 | public final static int HIGH = 1; 43 | } 44 | -------------------------------------------------------------------------------- /ADCDemo/src/com/friendlyarm/FriendlyThings/HardwareControler.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | import android.util.Log; 3 | 4 | public class HardwareControler 5 | { 6 | /* I/O */ 7 | static public native int open(String devName, int flags); 8 | static public native int write(int fd, byte[] data); 9 | static public native int read(int fd, byte[] buf, int len); 10 | static public native int select(int fd, int sec, int usec); 11 | static public native void close(int fd); 12 | static public native int ioctlWithIntValue(int fd, int cmd, int value); 13 | static public native int ioctl(int fd, int cmd, byte[] buf); 14 | 15 | /* Serial Port */ 16 | static public native int openSerialPort( String devName, long baud, int dataBits, int stopBits ); 17 | static public native int openSerialPortEx( String devName 18 | , long baud 19 | , int dataBits 20 | , int stopBits 21 | , String parityBit 22 | , String flowCtrl 23 | ); 24 | 25 | /* LED */ 26 | static public native int setLedState( int ledID, int ledState ); 27 | 28 | /* PWM */ 29 | static public native int PWMPlay(int frequency); 30 | static public native int PWMStop(); 31 | static public native int PWMPlayEx(int gpioPin, int frequency); 32 | static public native int PWMStopEx(int gpioPin); 33 | 34 | /* ADC */ 35 | static public native int readADC(); 36 | static public native int readADCWithChannel(int channel); 37 | static public native int[] readADCWithChannels(int[] channels); 38 | 39 | /* I2C */ 40 | static public native int setI2CSlave(int fd, int slave); 41 | static public native int setI2CTimeout(int fd, int timeout); 42 | static public native int setI2CRetries(int fd, int retries); 43 | static public native int I2CReadByteData(int fd, int pos, int wait_us); 44 | static public native int I2CReadByte(int fd, int wait_us); 45 | static public native int I2CWriteByteData(int fd, int pos, byte byteData, int wait_us); 46 | static public native int I2CWriteByte(int fd, byte byteData, int wait_us); 47 | 48 | /* Discard */ static public native int readByteFromI2C(int fd, int pos, int wait_ms); 49 | /* Discard */ static public native int writeByteToI2C(int fd, int pos, byte byteData, int wait_ms); 50 | /* Discard */ static public native int writeByteToI2C2(int fd, byte byteData, int wait_ms); 51 | 52 | /* SPI */ 53 | static public native int setSPIWriteBitsPerWord( int spi_fd, int bits ); 54 | static public native int setSPIReadBitsPerWord( int spi_fd, int bits ); 55 | static public native int setSPIBitOrder( int spi_fd, int order); 56 | static public native int setSPIClockDivider( int spi_fd, int divider); 57 | static public native int setSPIMaxSpeed( int spi_fd, int spi_speed); 58 | static public native int setSPIDataMode( int spi_fd, int mode); 59 | static public native int SPItransferOneByte( int spi_fd, byte byteData, int spi_delay, int spi_speed, int spi_bits); 60 | static public native int SPItransferBytes(int spi_fd, byte[] writeData, byte[] readBuff, int spi_delay, int spi_speed, int spi_bits); 61 | static public native int writeBytesToSPI(int spi_fd, byte[] writeData, int spi_delay, int spi_speed, int spi_bits); 62 | static public native int readBytesFromSPI(int spi_fd, byte[] readBuff, int spi_delay, int spi_speed, int spi_bits); 63 | 64 | /* GPIO */ 65 | static public native int exportGPIOPin(int pin); 66 | static public native int unexportGPIOPin(int pin); 67 | //GPIOEnum.LOW or GPIOEnum.HIGH 68 | static public native int setGPIOValue(int pin, int value); 69 | static public native int getGPIOValue(int pin); 70 | //GPIOEnum.IN or GPIOEnum.OUT 71 | static public native int setGPIODirection(int pin, int direction); 72 | static public native int getGPIODirection(int pin); 73 | 74 | /* OldInterface: for EEPROM */ 75 | static public native int openI2CDevice(); 76 | static public native int writeByteDataToI2C(int fd, int pos, byte byteData); 77 | static public native int readByteDataFromI2C(int fd, int pos); 78 | 79 | /* return BoardType.xxx */ 80 | static public native int getBoardType(); 81 | 82 | static { 83 | try { 84 | System.loadLibrary("friendlyarm-things"); 85 | } catch (UnsatisfiedLinkError e) { 86 | Log.d("HardwareControler", "libfriendlyarm-things library not found!"); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /ADCDemo/src/com/friendlyarm/FriendlyThings/SPI.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | import android.util.Log; 3 | import android.widget.Toast; 4 | 5 | import com.friendlyarm.FriendlyThings.HardwareControler; 6 | import com.friendlyarm.FriendlyThings.SPIEnum; 7 | import com.friendlyarm.FriendlyThings.GPIOEnum; 8 | import com.friendlyarm.FriendlyThings.FileCtlEnum; 9 | 10 | public class SPI { 11 | private static final String TAG = "com.friendlyarm.FriendlyThings.SPI"; 12 | private int spi_mode = 0; 13 | private int spi_bits = 8; 14 | private int spi_delay = 0; 15 | private int spi_speed = 500000; 16 | private int spi_byte_order = SPIEnum.LSBFIRST; 17 | 18 | private static final String devName = "/dev/spidev1.0"; 19 | private int spi_fd = -1; 20 | 21 | public void begin() { 22 | spi_fd = HardwareControler.open( devName, FileCtlEnum.O_RDWR ); 23 | if (spi_fd >= 0) { 24 | Log.d(TAG, "open " + devName + "ok!"); 25 | 26 | /* spi init */ 27 | HardwareControler.setSPIWriteBitsPerWord( spi_fd, spi_bits ); 28 | HardwareControler.setSPIReadBitsPerWord( spi_fd, spi_bits ); 29 | } else { 30 | Log.d(TAG, "open " + devName + "failed!"); 31 | spi_fd = -1; 32 | } 33 | } 34 | 35 | public void end() { 36 | if (spi_fd != -1) { 37 | HardwareControler.close(spi_fd); 38 | spi_fd = -1; 39 | } 40 | } 41 | 42 | public void setBitOrder(int order) { 43 | if (spi_fd < 0) { 44 | return ; 45 | } 46 | spi_byte_order = SPIEnum.MSBFIRST; 47 | if(spi_byte_order == SPIEnum.LSBFIRST) { 48 | spi_mode |= SPIEnum.SPI_LSB_FIRST; 49 | } else { 50 | spi_mode &= ~SPIEnum.SPI_LSB_FIRST; 51 | } 52 | HardwareControler.setSPIBitOrder( spi_fd, spi_byte_order ); 53 | 54 | } 55 | 56 | public void setClockDivider(int divider) { 57 | if (spi_fd < 0) { 58 | return ; 59 | } 60 | spi_speed = 66666666/(2*(divider+1)); 61 | if(spi_speed > 500000) { 62 | spi_speed = 500000; 63 | } 64 | HardwareControler.setSPIClockDivider( spi_fd, divider); 65 | } 66 | 67 | public void setDataMode(int mode) { 68 | if (spi_fd < 0) { 69 | return ; 70 | } 71 | switch(mode) 72 | { 73 | case SPIEnum.SPI_MODE0: 74 | spi_mode &= ~(SPIEnum.SPI_CPHA|SPIEnum.SPI_CPOL); 75 | break; 76 | case SPIEnum.SPI_MODE1: 77 | spi_mode &= ~(SPIEnum.SPI_CPOL); 78 | spi_mode |= (SPIEnum.SPI_CPHA); 79 | break; 80 | case SPIEnum.SPI_MODE2: 81 | spi_mode |= (SPIEnum.SPI_CPOL); 82 | spi_mode &= ~(SPIEnum.SPI_CPHA); 83 | break; 84 | case SPIEnum.SPI_MODE3: 85 | spi_mode |= (SPIEnum.SPI_CPHA|SPIEnum.SPI_CPOL); 86 | break; 87 | default: 88 | Log.e(TAG, "error data mode"); 89 | } 90 | 91 | HardwareControler.setSPIDataMode( spi_fd, spi_mode ); 92 | } 93 | 94 | public void setChipSelectPolarity(int cs, int active) { 95 | 96 | } 97 | 98 | public void chipSelect(int cs) { 99 | 100 | } 101 | 102 | public byte transfer(int value) { 103 | if (spi_fd < 0) { 104 | return 0; 105 | } 106 | return (byte) HardwareControler.SPItransferOneByte(spi_fd, (byte) value, spi_delay, spi_speed, spi_bits); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /ADCDemo/src/com/friendlyarm/FriendlyThings/SPIEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | public class SPIEnum { 3 | 4 | // SPIBitOrder 5 | public final static int LSBFIRST = 0; ///< LSB First 6 | public final static int MSBFIRST = 1; ///< MSB First 7 | 8 | // SPIMode 9 | public final static int SPI_MODE0 = 0; ///< CPOL = 0, CPHA = 0 10 | public final static int SPI_MODE1 = 1; ///< CPOL = 0, CPHA = 1 11 | public final static int SPI_MODE2 = 2; ///< CPOL = 1, CPHA = 0 12 | public final static int SPI_MODE3 = 3; ///< CPOL = 1, CPHA = 1 13 | 14 | 15 | public final static int SPI_CPHA = 0x01; 16 | public final static int SPI_CPOL = 0x02; 17 | public final static int SPI_CS_HIGH = 0x04; 18 | public final static int SPI_LSB_FIRST = 0x08; 19 | public final static int SPI_3WIRE = 0x10; 20 | public final static int SPI_LOOP = 0x20; 21 | public final static int SPI_NO_CS = 0x40; 22 | public final static int SPI_READY = 0x80; 23 | 24 | // SPIClockDivider 25 | public final static int SPI_CLOCK_DIV65536 = 0; ///< 65536 = 256us = 4kHz 26 | public final static int SPI_CLOCK_DIV32768 = 32768; ///< 32768 = 126us = 8kHz 27 | public final static int SPI_CLOCK_DIV16384 = 16384; ///< 16384 = 64us = 15.625kHz 28 | public final static int SPI_CLOCK_DIV8192 = 8192; ///< 8192 = 32us = 31.25kHz 29 | public final static int SPI_CLOCK_DIV4096 = 4096; ///< 4096 = 16us = 62.5kHz 30 | public final static int SPI_CLOCK_DIV2048 = 2048; ///< 2048 = 8us = 125kHz 31 | public final static int SPI_CLOCK_DIV1024 = 1024; ///< 1024 = 4us = 250kHz 32 | public final static int SPI_CLOCK_DIV512 = 512; ///< 512 = 2us = 500kHz 33 | public final static int SPI_CLOCK_DIV256 = 256; ///< 256 = 1us = 1MHz 34 | public final static int SPI_CLOCK_DIV128 = 128; ///< 128 = 500ns = = 2MHz 35 | public final static int SPI_CLOCK_DIV64 = 64; ///< 64 = 250ns = 4MHz 36 | public final static int SPI_CLOCK_DIV32 = 32; ///< 32 = 125ns = 8MHz 37 | public final static int SPI_CLOCK_DIV16 = 16; ///< 16 = 50ns = 20MHz 38 | public final static int SPI_CLOCK_DIV8 = 8; ///< 8 = 25ns = 40MHz 39 | public final static int SPI_CLOCK_DIV4 = 4; ///< 4 = 12.5ns 80MHz 40 | public final static int SPI_CLOCK_DIV2 = 2; ///< 2 = 6.25ns = 160MHz 41 | public final static int SPI_CLOCK_DIV1 = 1; ///< 0 = 256us = 4kHz 42 | } -------------------------------------------------------------------------------- /ADCDemo/src/com/friendlyarm/FriendlyThings/WatchDogEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | 3 | public class WatchDogEnum { 4 | /* include/uapi/linux/watchdog.h */ 5 | public final static int WDIOC_GETSUPPORT = 0x80285700; 6 | public final static int WDIOC_GETSTATUS = 0x80045701; 7 | public final static int WDIOC_GETBOOTSTATUS = 0x80045702; 8 | public final static int WDIOC_GETTEMP = 0x80045703; 9 | public final static int WDIOC_SETOPTIONS = 0x80045704; 10 | public final static int WDIOC_KEEPALIVE = 0x80045705; 11 | public final static int WDIOC_SETTIMEOUT = 0xC0045706; 12 | public final static int WDIOC_GETTIMEOUT = 0x80045707; 13 | public final static int WDIOC_SETPRETIMEOUT = 0xC0045708; 14 | public final static int WDIOC_GETPRETIMEOUT = 0x80045709; 15 | public final static int WDIOC_GETTIMELEFT = 0x8004570A; 16 | 17 | public final static int WDIOF_UNKNOWN = -1; /* Unknown flag error */ 18 | public final static int WDIOS_UNKNOWN = -1; /* Unknown status error */ 19 | 20 | public final static int WDIOF_OVERHEAT = 0x0001; /* Reset due to CPU overheat */ 21 | public final static int WDIOF_FANFAULT = 0x0002; /* Fan failed */ 22 | public final static int WDIOF_EXTERN1 = 0x0004; /* External relay 1 */ 23 | public final static int WDIOF_EXTERN2 = 0x0008; /* External relay 2 */ 24 | public final static int WDIOF_POWERUNDER = 0x0010; /* Power bad/power fault */ 25 | public final static int WDIOF_CARDRESET = 0x0020; /* Card previously reset the CPU */ 26 | public final static int WDIOF_POWEROVER = 0x0040; /* Power over voltage */ 27 | public final static int WDIOF_SETTIMEOUT = 0x0080; /* Set timeout (in seconds) */ 28 | public final static int WDIOF_MAGICCLOSE = 0x0100; /* Supports magic close char */ 29 | public final static int WDIOF_PRETIMEOUT = 0x0200; /* Pretimeout (in seconds), get/set */ 30 | public final static int WDIOF_ALARMONLY = 0x0400; /* Watchdog triggers a management or other external alarm not a reboot */ 31 | public final static int WDIOF_KEEPALIVEPING = 0x8000; /* Keep alive ping reply */ 32 | 33 | public final static int WDIOS_DISABLECARD = 0x0001; /* Turn off the watchdog timer */ 34 | public final static int WDIOS_ENABLECARD = 0x0002; /* Turn on the watchdog timer */ 35 | public final static int WDIOS_TEMPPANIC = 0x0004; /* Kernel panic on temperature trip */ 36 | 37 | } 38 | -------------------------------------------------------------------------------- /ADCDemo/src/com/friendlyarm/Utils/CommonFuncs.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.Utils; 2 | 3 | import android.app.Activity; 4 | import android.app.AlertDialog; 5 | import android.widget.Toast; 6 | import android.app.Activity; 7 | import android.os.Bundle; 8 | import android.os.Handler; 9 | import android.os.Message; 10 | import android.content.Context; 11 | import android.content.DialogInterface; 12 | 13 | public class CommonFuncs { 14 | public static void showAlertDialog(Context context, String message) { 15 | AlertDialog.Builder builder = new AlertDialog.Builder(context); 16 | builder.setMessage(message) 17 | .setCancelable(false) 18 | .setPositiveButton("Close", 19 | new DialogInterface.OnClickListener() { 20 | public void onClick(DialogInterface dialog, int id) { 21 | } 22 | }); 23 | AlertDialog alert = builder.create(); 24 | alert.show(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_SRC_FILES := $(call all-subdir-java-files) 5 | 6 | LOCAL_PACKAGE_NAME := GPIO_LED_Demo 7 | 8 | LOCAL_PRIVATE_PLATFORM_APIS := true 9 | LOCAL_PRIVILEGED_MODULE := true 10 | LOCAL_CERTIFICATE := platform 11 | LOCAL_MODULE_TAGS := optional 12 | LOCAL_CFLAGS := -lfriendlyarm-things 13 | 14 | include $(BUILD_PACKAGE) 15 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | cd /opt/FriendlyARM/android_examples/jni-demos/GPIO_LED_Demo 5 | rm -rf gen bin 6 | 7 | cd /opt/FriendlyARM/smart4418/android/ 8 | rm -f GPIODemo-r1.0.apk 9 | . setenv 10 | mmm /opt/FriendlyARM/android_examples/jni-demos/GPIO_LED_Demo 11 | java -jar out/host/linux-x86/framework/signapk.jar vendor/friendly-arm/nanopi3/security/platform.x509.pem vendor/friendly-arm/nanopi3/security/platform.pk8 /opt/FriendlyARM/smart4418/android/out/target/product/nanopi3/obj/APPS/GPIODemo_intermediates/package.apk.unsigned GPIODemo-unaligned.apk 12 | zipalign -v 4 GPIODemo-unaligned.apk GPIODemo-r1.0.apk 13 | # out/host/linux-x86/bin/zipalign -f 4 out/target/product/nanopi3/obj/APPS/GPIODemo_intermediates/package.apk.unaligned out/target/product/nanopi3/obj/APPS/GPIODemo_intermediates/package.apk.aligned 14 | adb install -r GPIODemo-r1.0.apk 15 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/libs/arm64-v8a/libfriendlyarm-things.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/GPIO_LED_Demo/libs/arm64-v8a/libfriendlyarm-things.so -------------------------------------------------------------------------------- /GPIO_LED_Demo/libs/armeabi/libfriendlyarm-things.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/GPIO_LED_Demo/libs/armeabi/libfriendlyarm-things.so -------------------------------------------------------------------------------- /GPIO_LED_Demo/res/drawable/gray_thumb.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/res/drawable/gray_track.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/res/drawable/green_thumb.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/res/drawable/green_track.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/res/drawable/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/GPIO_LED_Demo/res/drawable/icon.png -------------------------------------------------------------------------------- /GPIO_LED_Demo/res/drawable/red_thumb.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/res/drawable/thumb.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/res/drawable/track.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/res/layout/gpiodemo_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 9 | 10 | 18 | 25 | 26 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/res/layout/listview_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 19 | 20 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | GPIO Sample 4 | GPIO Sample 5 | LED 6 | More samples? \nClick here 7 | 8 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/src/com/friendlyarm/FriendlyThings/FileCtlEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | 3 | public class FileCtlEnum { 4 | /* File Flag */ 5 | public final static int O_ACCMODE = 00000003; 6 | public final static int O_RDONLY = 00000000; 7 | public final static int O_WRONLY = 00000001; 8 | public final static int O_RDWR = 00000002; 9 | public final static int O_CREAT = 00000100; /* not fcntl */ 10 | public final static int O_EXCL = 00000200; /* not fcntl */ 11 | public final static int O_NOCTTY = 00000400; /* not fcntl */ 12 | public final static int O_TRUNC = 00001000; /* not fcntl */ 13 | public final static int O_APPEND = 00002000; 14 | public final static int O_NONBLOCK = 00004000; 15 | public final static int O_DSYNC = 00010000; /* used to be O_SYNC, see below */ 16 | public final static int FASYNC = 00020000; /* fcntl, for BSD compatibility */ 17 | public final static int O_DIRECT = 00040000; /* direct disk access hint */ 18 | public final static int O_LARGEFILE = 00100000; 19 | public final static int O_DIRECTORY = 00200000; /* must be a directory */ 20 | public final static int O_NOFOLLOW = 00400000; /* don't follow links */ 21 | public final static int O_NOATIME = 01000000; 22 | public final static int O_CLOEXEC = 02000000; /* set close_on_exec */ 23 | } 24 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/src/com/friendlyarm/FriendlyThings/GPIOEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | 3 | /* 4 | GPIO signals have paths like /sys/class/gpio/gpio42/ (for GPIO #42) 5 | and have the following read/write attributes: 6 | 7 | /sys/class/gpio/gpioN/ 8 | 9 | "direction" ... reads as either "in" or "out". This value may 10 | normally be written. Writing as "out" defaults to 11 | initializing the value as low. To ensure glitch free 12 | operation, values "low" and "high" may be written to 13 | configure the GPIO as an output with that initial value. 14 | 15 | Note that this attribute *will not exist* if the kernel 16 | doesn't support changing the direction of a GPIO, or 17 | it was exported by kernel code that didn't explicitly 18 | allow userspace to reconfigure this GPIO's direction. 19 | 20 | "value" ... reads as either 0 (low) or 1 (high). If the GPIO 21 | is configured as an output, this value may be written; 22 | any nonzero value is treated as high. 23 | 24 | If the pin can be configured as interrupt-generating interrupt 25 | and if it has been configured to generate interrupts (see the 26 | description of "edge"), you can poll(2) on that file and 27 | poll(2) will return whenever the interrupt was triggered. If 28 | you use poll(2), set the events POLLPRI and POLLERR. If you 29 | use select(2), set the file descriptor in exceptfds. After 30 | poll(2) returns, either lseek(2) to the beginning of the sysfs 31 | file and read the new value or close the file and re-open it 32 | to read the value. 33 | */ 34 | 35 | public class GPIOEnum { 36 | //Direction 37 | public final static int IN = 1; 38 | public final static int OUT = 2; 39 | 40 | //Value 41 | public final static int LOW = 0; 42 | public final static int HIGH = 1; 43 | } 44 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/src/com/friendlyarm/FriendlyThings/HardwareControler.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | import android.util.Log; 3 | 4 | public class HardwareControler 5 | { 6 | /* I/O */ 7 | static public native int open(String devName, int flags); 8 | static public native int write(int fd, byte[] data); 9 | static public native int read(int fd, byte[] buf, int len); 10 | static public native int select(int fd, int sec, int usec); 11 | static public native void close(int fd); 12 | static public native int ioctlWithIntValue(int fd, int cmd, int value); 13 | static public native int ioctl(int fd, int cmd, byte[] buf); 14 | 15 | /* Serial Port */ 16 | static public native int openSerialPort( String devName, long baud, int dataBits, int stopBits ); 17 | static public native int openSerialPortEx( String devName 18 | , long baud 19 | , int dataBits 20 | , int stopBits 21 | , String parityBit 22 | , String flowCtrl 23 | ); 24 | 25 | /* LED */ 26 | static public native int setLedState( int ledID, int ledState ); 27 | 28 | /* PWM */ 29 | static public native int PWMPlay(int frequency); 30 | static public native int PWMStop(); 31 | static public native int PWMPlayEx(int gpioPin, int frequency); 32 | static public native int PWMStopEx(int gpioPin); 33 | 34 | /* ADC */ 35 | static public native int readADC(); 36 | static public native int readADCWithChannel(int channel); 37 | static public native int[] readADCWithChannels(int[] channels); 38 | 39 | /* I2C */ 40 | static public native int setI2CSlave(int fd, int slave); 41 | static public native int setI2CTimeout(int fd, int timeout); 42 | static public native int setI2CRetries(int fd, int retries); 43 | static public native int I2CReadByteData(int fd, int pos, int wait_us); 44 | static public native int I2CReadByte(int fd, int wait_us); 45 | static public native int I2CWriteByteData(int fd, int pos, byte byteData, int wait_us); 46 | static public native int I2CWriteByte(int fd, byte byteData, int wait_us); 47 | 48 | /* Discard */ static public native int readByteFromI2C(int fd, int pos, int wait_ms); 49 | /* Discard */ static public native int writeByteToI2C(int fd, int pos, byte byteData, int wait_ms); 50 | /* Discard */ static public native int writeByteToI2C2(int fd, byte byteData, int wait_ms); 51 | 52 | /* SPI */ 53 | static public native int setSPIWriteBitsPerWord( int spi_fd, int bits ); 54 | static public native int setSPIReadBitsPerWord( int spi_fd, int bits ); 55 | static public native int setSPIBitOrder( int spi_fd, int order); 56 | static public native int setSPIClockDivider( int spi_fd, int divider); 57 | static public native int setSPIMaxSpeed( int spi_fd, int spi_speed); 58 | static public native int setSPIDataMode( int spi_fd, int mode); 59 | static public native int SPItransferOneByte( int spi_fd, byte byteData, int spi_delay, int spi_speed, int spi_bits); 60 | static public native int SPItransferBytes(int spi_fd, byte[] writeData, byte[] readBuff, int spi_delay, int spi_speed, int spi_bits); 61 | static public native int writeBytesToSPI(int spi_fd, byte[] writeData, int spi_delay, int spi_speed, int spi_bits); 62 | static public native int readBytesFromSPI(int spi_fd, byte[] readBuff, int spi_delay, int spi_speed, int spi_bits); 63 | 64 | /* GPIO */ 65 | static public native int exportGPIOPin(int pin); 66 | static public native int unexportGPIOPin(int pin); 67 | //GPIOEnum.LOW or GPIOEnum.HIGH 68 | static public native int setGPIOValue(int pin, int value); 69 | static public native int getGPIOValue(int pin); 70 | //GPIOEnum.IN or GPIOEnum.OUT 71 | static public native int setGPIODirection(int pin, int direction); 72 | static public native int getGPIODirection(int pin); 73 | 74 | /* OldInterface: for EEPROM */ 75 | static public native int openI2CDevice(); 76 | static public native int writeByteDataToI2C(int fd, int pos, byte byteData); 77 | static public native int readByteDataFromI2C(int fd, int pos); 78 | 79 | /* return BoardType.xxx */ 80 | static public native int getBoardType(); 81 | 82 | static { 83 | try { 84 | System.loadLibrary("friendlyarm-things"); 85 | } catch (UnsatisfiedLinkError e) { 86 | Log.d("HardwareControler", "libfriendlyarm-things library not found!"); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/src/com/friendlyarm/FriendlyThings/SPI.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | import android.util.Log; 3 | import android.widget.Toast; 4 | 5 | import com.friendlyarm.FriendlyThings.HardwareControler; 6 | import com.friendlyarm.FriendlyThings.SPIEnum; 7 | import com.friendlyarm.FriendlyThings.GPIOEnum; 8 | import com.friendlyarm.FriendlyThings.FileCtlEnum; 9 | 10 | public class SPI { 11 | private static final String TAG = "com.friendlyarm.FriendlyThings.SPI"; 12 | private int spi_mode = 0; 13 | private int spi_bits = 8; 14 | private int spi_delay = 0; 15 | private int spi_speed = 500000; 16 | private int spi_byte_order = SPIEnum.LSBFIRST; 17 | 18 | private static final String devName = "/dev/spidev1.0"; 19 | private int spi_fd = -1; 20 | 21 | public void begin() { 22 | spi_fd = HardwareControler.open( devName, FileCtlEnum.O_RDWR ); 23 | if (spi_fd >= 0) { 24 | Log.d(TAG, "open " + devName + "ok!"); 25 | 26 | /* spi init */ 27 | HardwareControler.setSPIWriteBitsPerWord( spi_fd, spi_bits ); 28 | HardwareControler.setSPIReadBitsPerWord( spi_fd, spi_bits ); 29 | } else { 30 | Log.d(TAG, "open " + devName + "failed!"); 31 | spi_fd = -1; 32 | } 33 | } 34 | 35 | public void end() { 36 | if (spi_fd != -1) { 37 | HardwareControler.close(spi_fd); 38 | spi_fd = -1; 39 | } 40 | } 41 | 42 | public void setBitOrder(int order) { 43 | if (spi_fd < 0) { 44 | return ; 45 | } 46 | spi_byte_order = SPIEnum.MSBFIRST; 47 | if(spi_byte_order == SPIEnum.LSBFIRST) { 48 | spi_mode |= SPIEnum.SPI_LSB_FIRST; 49 | } else { 50 | spi_mode &= ~SPIEnum.SPI_LSB_FIRST; 51 | } 52 | HardwareControler.setSPIBitOrder( spi_fd, spi_byte_order ); 53 | 54 | } 55 | 56 | public void setClockDivider(int divider) { 57 | if (spi_fd < 0) { 58 | return ; 59 | } 60 | spi_speed = 66666666/(2*(divider+1)); 61 | if(spi_speed > 500000) { 62 | spi_speed = 500000; 63 | } 64 | HardwareControler.setSPIClockDivider( spi_fd, divider); 65 | } 66 | 67 | public void setDataMode(int mode) { 68 | if (spi_fd < 0) { 69 | return ; 70 | } 71 | switch(mode) 72 | { 73 | case SPIEnum.SPI_MODE0: 74 | spi_mode &= ~(SPIEnum.SPI_CPHA|SPIEnum.SPI_CPOL); 75 | break; 76 | case SPIEnum.SPI_MODE1: 77 | spi_mode &= ~(SPIEnum.SPI_CPOL); 78 | spi_mode |= (SPIEnum.SPI_CPHA); 79 | break; 80 | case SPIEnum.SPI_MODE2: 81 | spi_mode |= (SPIEnum.SPI_CPOL); 82 | spi_mode &= ~(SPIEnum.SPI_CPHA); 83 | break; 84 | case SPIEnum.SPI_MODE3: 85 | spi_mode |= (SPIEnum.SPI_CPHA|SPIEnum.SPI_CPOL); 86 | break; 87 | default: 88 | Log.e(TAG, "error data mode"); 89 | } 90 | 91 | HardwareControler.setSPIDataMode( spi_fd, spi_mode ); 92 | } 93 | 94 | public void setChipSelectPolarity(int cs, int active) { 95 | 96 | } 97 | 98 | public void chipSelect(int cs) { 99 | 100 | } 101 | 102 | public byte transfer(int value) { 103 | if (spi_fd < 0) { 104 | return 0; 105 | } 106 | return (byte) HardwareControler.SPItransferOneByte(spi_fd, (byte) value, spi_delay, spi_speed, spi_bits); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/src/com/friendlyarm/FriendlyThings/SPIEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | public class SPIEnum { 3 | 4 | // SPIBitOrder 5 | public final static int LSBFIRST = 0; ///< LSB First 6 | public final static int MSBFIRST = 1; ///< MSB First 7 | 8 | // SPIMode 9 | public final static int SPI_MODE0 = 0; ///< CPOL = 0, CPHA = 0 10 | public final static int SPI_MODE1 = 1; ///< CPOL = 0, CPHA = 1 11 | public final static int SPI_MODE2 = 2; ///< CPOL = 1, CPHA = 0 12 | public final static int SPI_MODE3 = 3; ///< CPOL = 1, CPHA = 1 13 | 14 | 15 | public final static int SPI_CPHA = 0x01; 16 | public final static int SPI_CPOL = 0x02; 17 | public final static int SPI_CS_HIGH = 0x04; 18 | public final static int SPI_LSB_FIRST = 0x08; 19 | public final static int SPI_3WIRE = 0x10; 20 | public final static int SPI_LOOP = 0x20; 21 | public final static int SPI_NO_CS = 0x40; 22 | public final static int SPI_READY = 0x80; 23 | 24 | // SPIClockDivider 25 | public final static int SPI_CLOCK_DIV65536 = 0; ///< 65536 = 256us = 4kHz 26 | public final static int SPI_CLOCK_DIV32768 = 32768; ///< 32768 = 126us = 8kHz 27 | public final static int SPI_CLOCK_DIV16384 = 16384; ///< 16384 = 64us = 15.625kHz 28 | public final static int SPI_CLOCK_DIV8192 = 8192; ///< 8192 = 32us = 31.25kHz 29 | public final static int SPI_CLOCK_DIV4096 = 4096; ///< 4096 = 16us = 62.5kHz 30 | public final static int SPI_CLOCK_DIV2048 = 2048; ///< 2048 = 8us = 125kHz 31 | public final static int SPI_CLOCK_DIV1024 = 1024; ///< 1024 = 4us = 250kHz 32 | public final static int SPI_CLOCK_DIV512 = 512; ///< 512 = 2us = 500kHz 33 | public final static int SPI_CLOCK_DIV256 = 256; ///< 256 = 1us = 1MHz 34 | public final static int SPI_CLOCK_DIV128 = 128; ///< 128 = 500ns = = 2MHz 35 | public final static int SPI_CLOCK_DIV64 = 64; ///< 64 = 250ns = 4MHz 36 | public final static int SPI_CLOCK_DIV32 = 32; ///< 32 = 125ns = 8MHz 37 | public final static int SPI_CLOCK_DIV16 = 16; ///< 16 = 50ns = 20MHz 38 | public final static int SPI_CLOCK_DIV8 = 8; ///< 8 = 25ns = 40MHz 39 | public final static int SPI_CLOCK_DIV4 = 4; ///< 4 = 12.5ns 80MHz 40 | public final static int SPI_CLOCK_DIV2 = 2; ///< 2 = 6.25ns = 160MHz 41 | public final static int SPI_CLOCK_DIV1 = 1; ///< 0 = 256us = 4kHz 42 | } -------------------------------------------------------------------------------- /GPIO_LED_Demo/src/com/friendlyarm/FriendlyThings/WatchDogEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | 3 | public class WatchDogEnum { 4 | /* include/uapi/linux/watchdog.h */ 5 | public final static int WDIOC_GETSUPPORT = 0x80285700; 6 | public final static int WDIOC_GETSTATUS = 0x80045701; 7 | public final static int WDIOC_GETBOOTSTATUS = 0x80045702; 8 | public final static int WDIOC_GETTEMP = 0x80045703; 9 | public final static int WDIOC_SETOPTIONS = 0x80045704; 10 | public final static int WDIOC_KEEPALIVE = 0x80045705; 11 | public final static int WDIOC_SETTIMEOUT = 0xC0045706; 12 | public final static int WDIOC_GETTIMEOUT = 0x80045707; 13 | public final static int WDIOC_SETPRETIMEOUT = 0xC0045708; 14 | public final static int WDIOC_GETPRETIMEOUT = 0x80045709; 15 | public final static int WDIOC_GETTIMELEFT = 0x8004570A; 16 | 17 | public final static int WDIOF_UNKNOWN = -1; /* Unknown flag error */ 18 | public final static int WDIOS_UNKNOWN = -1; /* Unknown status error */ 19 | 20 | public final static int WDIOF_OVERHEAT = 0x0001; /* Reset due to CPU overheat */ 21 | public final static int WDIOF_FANFAULT = 0x0002; /* Fan failed */ 22 | public final static int WDIOF_EXTERN1 = 0x0004; /* External relay 1 */ 23 | public final static int WDIOF_EXTERN2 = 0x0008; /* External relay 2 */ 24 | public final static int WDIOF_POWERUNDER = 0x0010; /* Power bad/power fault */ 25 | public final static int WDIOF_CARDRESET = 0x0020; /* Card previously reset the CPU */ 26 | public final static int WDIOF_POWEROVER = 0x0040; /* Power over voltage */ 27 | public final static int WDIOF_SETTIMEOUT = 0x0080; /* Set timeout (in seconds) */ 28 | public final static int WDIOF_MAGICCLOSE = 0x0100; /* Supports magic close char */ 29 | public final static int WDIOF_PRETIMEOUT = 0x0200; /* Pretimeout (in seconds), get/set */ 30 | public final static int WDIOF_ALARMONLY = 0x0400; /* Watchdog triggers a management or other external alarm not a reboot */ 31 | public final static int WDIOF_KEEPALIVEPING = 0x8000; /* Keep alive ping reply */ 32 | 33 | public final static int WDIOS_DISABLECARD = 0x0001; /* Turn off the watchdog timer */ 34 | public final static int WDIOS_ENABLECARD = 0x0002; /* Turn on the watchdog timer */ 35 | public final static int WDIOS_TEMPPANIC = 0x0004; /* Kernel panic on temperature trip */ 36 | 37 | } 38 | -------------------------------------------------------------------------------- /GPIO_LED_Demo/src/com/friendlyarm/GPIODemo/GPIOPin.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.GPIODemo; 2 | import com.friendlyarm.FriendlyThings.GPIOEnum; 3 | 4 | public class GPIOPin { 5 | private int sysPinNum = 0; 6 | private String name = null; 7 | private int value = GPIOEnum.LOW; 8 | 9 | public GPIOPin(int sysPinNum, String name, int value) { 10 | super(); 11 | this.sysPinNum = sysPinNum; 12 | this.name = name; 13 | this.value = value; 14 | } 15 | public int getSysPinNum() { 16 | return sysPinNum; 17 | } 18 | public void setSysPinNum(int sysPinNum) { 19 | this.sysPinNum = sysPinNum; 20 | } 21 | public String getName() { 22 | return name; 23 | } 24 | public void setName(String name) { 25 | this.name = name; 26 | } 27 | 28 | public int getValue() { 29 | return this.value; 30 | } 31 | public void setValue(int newValue) { 32 | this.value = newValue; 33 | } 34 | } -------------------------------------------------------------------------------- /GPIO_LED_Demo/src/com/friendlyarm/Utils/CommonFuncs.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.Utils; 2 | 3 | import android.app.Activity; 4 | import android.app.AlertDialog; 5 | import android.widget.Toast; 6 | import android.app.Activity; 7 | import android.os.Bundle; 8 | import android.os.Handler; 9 | import android.os.Message; 10 | import android.content.Context; 11 | import android.content.DialogInterface; 12 | 13 | public class CommonFuncs { 14 | public static void showAlertDialog(Context context, String message) { 15 | AlertDialog.Builder builder = new AlertDialog.Builder(context); 16 | builder.setMessage(message) 17 | .setCancelable(false) 18 | .setPositiveButton("Close", 19 | new DialogInterface.OnClickListener() { 20 | public void onClick(DialogInterface dialog, int id) { 21 | } 22 | }); 23 | AlertDialog alert = builder.create(); 24 | alert.show(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /I2C_LCD1602_Demo/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /I2C_LCD1602_Demo/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_SRC_FILES := $(call all-subdir-java-files) 5 | 6 | LOCAL_PACKAGE_NAME := LCD1602 7 | 8 | LOCAL_PRIVATE_PLATFORM_APIS := true 9 | LOCAL_PRIVILEGED_MODULE := true 10 | LOCAL_CERTIFICATE := platform 11 | LOCAL_MODULE_TAGS := optional 12 | LOCAL_CFLAGS := -lfriendlyarm-things 13 | 14 | include $(BUILD_PACKAGE) 15 | -------------------------------------------------------------------------------- /I2C_LCD1602_Demo/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /I2C_LCD1602_Demo/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ANDROIDPATH=/opt/FriendlyARM/smart4418/android/ 4 | APPNAME=LCD1602 5 | APKNAME=${APPNAME}-r1.0.apk 6 | PRJPATH=$PWD 7 | cd $PRJPATH 8 | rm -rf bin gen 9 | 10 | cd $ANDROIDPATH 11 | rm -f $APKNAME 12 | . setenv 13 | mmm $PRJPATH -B 14 | java -jar out/host/linux-x86/framework/signapk.jar vendor/friendly-arm/nanopi2/security/platform.x509.pem vendor/friendly-arm/nanopi2/security/platform.pk8 out/target/product/nanopi2/obj/APPS/${APPNAME}_intermediates/package.apk.unsigned ${APPNAME}-unaligned.apk 15 | zipalign -v 4 ${APPNAME}-unaligned.apk $APKNAME 16 | adb install -r ${APKNAME} 17 | -------------------------------------------------------------------------------- /I2C_LCD1602_Demo/libs/arm64-v8a/libfriendlyarm-things.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/I2C_LCD1602_Demo/libs/arm64-v8a/libfriendlyarm-things.so -------------------------------------------------------------------------------- /I2C_LCD1602_Demo/libs/armeabi/libfriendlyarm-things.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/I2C_LCD1602_Demo/libs/armeabi/libfriendlyarm-things.so -------------------------------------------------------------------------------- /I2C_LCD1602_Demo/res/drawable/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/I2C_LCD1602_Demo/res/drawable/icon.png -------------------------------------------------------------------------------- /I2C_LCD1602_Demo/res/layout/mainactivity.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 9 | 12 | 13 | 16 | 17 | -------------------------------------------------------------------------------- /I2C_LCD1602_Demo/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | I2C-LCD1602 Sample 4 | I2C-LCD1602 Sample 5 | Apply 6 | 7 | -------------------------------------------------------------------------------- /I2C_LCD1602_Demo/src/com/friendlyarm/FriendlyThings/FileCtlEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | 3 | public class FileCtlEnum { 4 | /* File Flag */ 5 | public final static int O_ACCMODE = 00000003; 6 | public final static int O_RDONLY = 00000000; 7 | public final static int O_WRONLY = 00000001; 8 | public final static int O_RDWR = 00000002; 9 | public final static int O_CREAT = 00000100; /* not fcntl */ 10 | public final static int O_EXCL = 00000200; /* not fcntl */ 11 | public final static int O_NOCTTY = 00000400; /* not fcntl */ 12 | public final static int O_TRUNC = 00001000; /* not fcntl */ 13 | public final static int O_APPEND = 00002000; 14 | public final static int O_NONBLOCK = 00004000; 15 | public final static int O_DSYNC = 00010000; /* used to be O_SYNC, see below */ 16 | public final static int FASYNC = 00020000; /* fcntl, for BSD compatibility */ 17 | public final static int O_DIRECT = 00040000; /* direct disk access hint */ 18 | public final static int O_LARGEFILE = 00100000; 19 | public final static int O_DIRECTORY = 00200000; /* must be a directory */ 20 | public final static int O_NOFOLLOW = 00400000; /* don't follow links */ 21 | public final static int O_NOATIME = 01000000; 22 | public final static int O_CLOEXEC = 02000000; /* set close_on_exec */ 23 | } 24 | -------------------------------------------------------------------------------- /I2C_LCD1602_Demo/src/com/friendlyarm/FriendlyThings/GPIOEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | 3 | /* 4 | GPIO signals have paths like /sys/class/gpio/gpio42/ (for GPIO #42) 5 | and have the following read/write attributes: 6 | 7 | /sys/class/gpio/gpioN/ 8 | 9 | "direction" ... reads as either "in" or "out". This value may 10 | normally be written. Writing as "out" defaults to 11 | initializing the value as low. To ensure glitch free 12 | operation, values "low" and "high" may be written to 13 | configure the GPIO as an output with that initial value. 14 | 15 | Note that this attribute *will not exist* if the kernel 16 | doesn't support changing the direction of a GPIO, or 17 | it was exported by kernel code that didn't explicitly 18 | allow userspace to reconfigure this GPIO's direction. 19 | 20 | "value" ... reads as either 0 (low) or 1 (high). If the GPIO 21 | is configured as an output, this value may be written; 22 | any nonzero value is treated as high. 23 | 24 | If the pin can be configured as interrupt-generating interrupt 25 | and if it has been configured to generate interrupts (see the 26 | description of "edge"), you can poll(2) on that file and 27 | poll(2) will return whenever the interrupt was triggered. If 28 | you use poll(2), set the events POLLPRI and POLLERR. If you 29 | use select(2), set the file descriptor in exceptfds. After 30 | poll(2) returns, either lseek(2) to the beginning of the sysfs 31 | file and read the new value or close the file and re-open it 32 | to read the value. 33 | */ 34 | 35 | public class GPIOEnum { 36 | //Direction 37 | public final static int IN = 1; 38 | public final static int OUT = 2; 39 | 40 | //Value 41 | public final static int LOW = 0; 42 | public final static int HIGH = 1; 43 | } 44 | -------------------------------------------------------------------------------- /I2C_LCD1602_Demo/src/com/friendlyarm/FriendlyThings/SPI.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | import android.util.Log; 3 | import android.widget.Toast; 4 | 5 | import com.friendlyarm.FriendlyThings.HardwareControler; 6 | import com.friendlyarm.FriendlyThings.SPIEnum; 7 | import com.friendlyarm.FriendlyThings.GPIOEnum; 8 | import com.friendlyarm.FriendlyThings.FileCtlEnum; 9 | 10 | public class SPI { 11 | private static final String TAG = "com.friendlyarm.FriendlyThings.SPI"; 12 | private int spi_mode = 0; 13 | private int spi_bits = 8; 14 | private int spi_delay = 0; 15 | private int spi_speed = 500000; 16 | private int spi_byte_order = SPIEnum.LSBFIRST; 17 | 18 | private static final String devName = "/dev/spidev1.0"; 19 | private int spi_fd = -1; 20 | 21 | public void begin() { 22 | spi_fd = HardwareControler.open( devName, FileCtlEnum.O_RDWR ); 23 | if (spi_fd >= 0) { 24 | Log.d(TAG, "open " + devName + "ok!"); 25 | 26 | /* spi init */ 27 | HardwareControler.setSPIWriteBitsPerWord( spi_fd, spi_bits ); 28 | HardwareControler.setSPIReadBitsPerWord( spi_fd, spi_bits ); 29 | } else { 30 | Log.d(TAG, "open " + devName + "failed!"); 31 | spi_fd = -1; 32 | } 33 | } 34 | 35 | public void end() { 36 | if (spi_fd != -1) { 37 | HardwareControler.close(spi_fd); 38 | spi_fd = -1; 39 | } 40 | } 41 | 42 | public void setBitOrder(int order) { 43 | if (spi_fd < 0) { 44 | return ; 45 | } 46 | spi_byte_order = SPIEnum.MSBFIRST; 47 | if(spi_byte_order == SPIEnum.LSBFIRST) { 48 | spi_mode |= SPIEnum.SPI_LSB_FIRST; 49 | } else { 50 | spi_mode &= ~SPIEnum.SPI_LSB_FIRST; 51 | } 52 | HardwareControler.setSPIBitOrder( spi_fd, spi_byte_order ); 53 | 54 | } 55 | 56 | public void setClockDivider(int divider) { 57 | if (spi_fd < 0) { 58 | return ; 59 | } 60 | spi_speed = 66666666/(2*(divider+1)); 61 | if(spi_speed > 500000) { 62 | spi_speed = 500000; 63 | } 64 | HardwareControler.setSPIClockDivider( spi_fd, divider); 65 | } 66 | 67 | public void setDataMode(int mode) { 68 | if (spi_fd < 0) { 69 | return ; 70 | } 71 | switch(mode) 72 | { 73 | case SPIEnum.SPI_MODE0: 74 | spi_mode &= ~(SPIEnum.SPI_CPHA|SPIEnum.SPI_CPOL); 75 | break; 76 | case SPIEnum.SPI_MODE1: 77 | spi_mode &= ~(SPIEnum.SPI_CPOL); 78 | spi_mode |= (SPIEnum.SPI_CPHA); 79 | break; 80 | case SPIEnum.SPI_MODE2: 81 | spi_mode |= (SPIEnum.SPI_CPOL); 82 | spi_mode &= ~(SPIEnum.SPI_CPHA); 83 | break; 84 | case SPIEnum.SPI_MODE3: 85 | spi_mode |= (SPIEnum.SPI_CPHA|SPIEnum.SPI_CPOL); 86 | break; 87 | default: 88 | Log.e(TAG, "error data mode"); 89 | } 90 | 91 | HardwareControler.setSPIDataMode( spi_fd, spi_mode ); 92 | } 93 | 94 | public void setChipSelectPolarity(int cs, int active) { 95 | 96 | } 97 | 98 | public void chipSelect(int cs) { 99 | 100 | } 101 | 102 | public byte transfer(int value) { 103 | if (spi_fd < 0) { 104 | return 0; 105 | } 106 | return (byte) HardwareControler.SPItransferOneByte(spi_fd, (byte) value, spi_delay, spi_speed, spi_bits); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /I2C_LCD1602_Demo/src/com/friendlyarm/FriendlyThings/SPIEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | public class SPIEnum { 3 | 4 | // SPIBitOrder 5 | public final static int LSBFIRST = 0; ///< LSB First 6 | public final static int MSBFIRST = 1; ///< MSB First 7 | 8 | // SPIMode 9 | public final static int SPI_MODE0 = 0; ///< CPOL = 0, CPHA = 0 10 | public final static int SPI_MODE1 = 1; ///< CPOL = 0, CPHA = 1 11 | public final static int SPI_MODE2 = 2; ///< CPOL = 1, CPHA = 0 12 | public final static int SPI_MODE3 = 3; ///< CPOL = 1, CPHA = 1 13 | 14 | 15 | public final static int SPI_CPHA = 0x01; 16 | public final static int SPI_CPOL = 0x02; 17 | public final static int SPI_CS_HIGH = 0x04; 18 | public final static int SPI_LSB_FIRST = 0x08; 19 | public final static int SPI_3WIRE = 0x10; 20 | public final static int SPI_LOOP = 0x20; 21 | public final static int SPI_NO_CS = 0x40; 22 | public final static int SPI_READY = 0x80; 23 | 24 | // SPIClockDivider 25 | public final static int SPI_CLOCK_DIV65536 = 0; ///< 65536 = 256us = 4kHz 26 | public final static int SPI_CLOCK_DIV32768 = 32768; ///< 32768 = 126us = 8kHz 27 | public final static int SPI_CLOCK_DIV16384 = 16384; ///< 16384 = 64us = 15.625kHz 28 | public final static int SPI_CLOCK_DIV8192 = 8192; ///< 8192 = 32us = 31.25kHz 29 | public final static int SPI_CLOCK_DIV4096 = 4096; ///< 4096 = 16us = 62.5kHz 30 | public final static int SPI_CLOCK_DIV2048 = 2048; ///< 2048 = 8us = 125kHz 31 | public final static int SPI_CLOCK_DIV1024 = 1024; ///< 1024 = 4us = 250kHz 32 | public final static int SPI_CLOCK_DIV512 = 512; ///< 512 = 2us = 500kHz 33 | public final static int SPI_CLOCK_DIV256 = 256; ///< 256 = 1us = 1MHz 34 | public final static int SPI_CLOCK_DIV128 = 128; ///< 128 = 500ns = = 2MHz 35 | public final static int SPI_CLOCK_DIV64 = 64; ///< 64 = 250ns = 4MHz 36 | public final static int SPI_CLOCK_DIV32 = 32; ///< 32 = 125ns = 8MHz 37 | public final static int SPI_CLOCK_DIV16 = 16; ///< 16 = 50ns = 20MHz 38 | public final static int SPI_CLOCK_DIV8 = 8; ///< 8 = 25ns = 40MHz 39 | public final static int SPI_CLOCK_DIV4 = 4; ///< 4 = 12.5ns 80MHz 40 | public final static int SPI_CLOCK_DIV2 = 2; ///< 2 = 6.25ns = 160MHz 41 | public final static int SPI_CLOCK_DIV1 = 1; ///< 0 = 256us = 4kHz 42 | } -------------------------------------------------------------------------------- /I2C_LCD1602_Demo/src/com/friendlyarm/FriendlyThings/WatchDogEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | 3 | public class WatchDogEnum { 4 | /* include/uapi/linux/watchdog.h */ 5 | public final static int WDIOC_GETSUPPORT = 0x80285700; 6 | public final static int WDIOC_GETSTATUS = 0x80045701; 7 | public final static int WDIOC_GETBOOTSTATUS = 0x80045702; 8 | public final static int WDIOC_GETTEMP = 0x80045703; 9 | public final static int WDIOC_SETOPTIONS = 0x80045704; 10 | public final static int WDIOC_KEEPALIVE = 0x80045705; 11 | public final static int WDIOC_SETTIMEOUT = 0xC0045706; 12 | public final static int WDIOC_GETTIMEOUT = 0x80045707; 13 | public final static int WDIOC_SETPRETIMEOUT = 0xC0045708; 14 | public final static int WDIOC_GETPRETIMEOUT = 0x80045709; 15 | public final static int WDIOC_GETTIMELEFT = 0x8004570A; 16 | 17 | public final static int WDIOF_UNKNOWN = -1; /* Unknown flag error */ 18 | public final static int WDIOS_UNKNOWN = -1; /* Unknown status error */ 19 | 20 | public final static int WDIOF_OVERHEAT = 0x0001; /* Reset due to CPU overheat */ 21 | public final static int WDIOF_FANFAULT = 0x0002; /* Fan failed */ 22 | public final static int WDIOF_EXTERN1 = 0x0004; /* External relay 1 */ 23 | public final static int WDIOF_EXTERN2 = 0x0008; /* External relay 2 */ 24 | public final static int WDIOF_POWERUNDER = 0x0010; /* Power bad/power fault */ 25 | public final static int WDIOF_CARDRESET = 0x0020; /* Card previously reset the CPU */ 26 | public final static int WDIOF_POWEROVER = 0x0040; /* Power over voltage */ 27 | public final static int WDIOF_SETTIMEOUT = 0x0080; /* Set timeout (in seconds) */ 28 | public final static int WDIOF_MAGICCLOSE = 0x0100; /* Supports magic close char */ 29 | public final static int WDIOF_PRETIMEOUT = 0x0200; /* Pretimeout (in seconds), get/set */ 30 | public final static int WDIOF_ALARMONLY = 0x0400; /* Watchdog triggers a management or other external alarm not a reboot */ 31 | public final static int WDIOF_KEEPALIVEPING = 0x8000; /* Keep alive ping reply */ 32 | 33 | public final static int WDIOS_DISABLECARD = 0x0001; /* Turn off the watchdog timer */ 34 | public final static int WDIOS_ENABLECARD = 0x0002; /* Turn on the watchdog timer */ 35 | public final static int WDIOS_TEMPPANIC = 0x0004; /* Kernel panic on temperature trip */ 36 | 37 | } 38 | -------------------------------------------------------------------------------- /I2C_LCD1602_Demo/src/com/friendlyarm/LCD1602Demo/PCF8574.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.LCD1602Demo; 2 | 3 | import com.friendlyarm.FriendlyThings.HardwareControler; 4 | 5 | public class PCF8574 { 6 | static final byte RS = 0x01; 7 | static final byte En = 0x04; 8 | static final byte BL = 0x08; 9 | 10 | static int pulseEnable(int devFD, byte data) throws InterruptedException { 11 | if (HardwareControler.I2CWriteByte(devFD, (byte)(data | En), 1) != 0) { 12 | return -1; 13 | } 14 | if (HardwareControler.I2CWriteByte(devFD, (byte)(data & ~En), 0) != 0) { 15 | return -1; 16 | } 17 | return 0; 18 | } 19 | 20 | static int writeCmd4(int devFD, byte command) throws InterruptedException { 21 | if (HardwareControler.I2CWriteByte(devFD, (byte)(command | BL), 0) != 0) { 22 | return -1; 23 | } 24 | if (pulseEnable(devFD, (byte)(command | BL)) != 0) { 25 | return -1; 26 | } 27 | return 0; 28 | } 29 | 30 | static int writeCmd8(int devFD, byte command) throws InterruptedException { 31 | byte command_H = (byte) (command & 0xf0); 32 | byte command_L = (byte) ((command << 4) & 0xf0); 33 | if (writeCmd4(devFD, command_H) == -1) { 34 | return -1; 35 | } 36 | 37 | if (writeCmd4(devFD, command_L) == -1) { 38 | return -1; 39 | } 40 | return 0; 41 | } 42 | 43 | static int writeData4(int devFD, byte data) throws InterruptedException { 44 | if (HardwareControler.I2CWriteByte(devFD, (byte)(data | RS | BL), 0) != 0) { 45 | return -1; 46 | } 47 | if (pulseEnable(devFD, (byte)(data | RS | BL)) == -1) { 48 | return -1; 49 | } 50 | return 0; 51 | } 52 | 53 | static int writeData8(int devFD, byte data) throws InterruptedException { 54 | byte data_H = (byte) (data & 0xf0); 55 | byte data_L = (byte) ((data << 4) & 0xf0); 56 | if (writeData4(devFD, data_H) == -1) { 57 | return -1; 58 | } 59 | if (writeData4(devFD, data_L) == -1) { 60 | return -1; 61 | } 62 | return 0; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /I2C_LCD1602_Demo/src/com/friendlyarm/Utils/CommonFuncs.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.Utils; 2 | 3 | import android.app.Activity; 4 | import android.app.AlertDialog; 5 | import android.widget.Toast; 6 | import android.app.Activity; 7 | import android.os.Bundle; 8 | import android.os.Handler; 9 | import android.os.Message; 10 | import android.content.Context; 11 | import android.content.DialogInterface; 12 | 13 | public class CommonFuncs { 14 | public static void showAlertDialog(Context context, String message) { 15 | AlertDialog.Builder builder = new AlertDialog.Builder(context); 16 | builder.setMessage(message) 17 | .setCancelable(false) 18 | .setPositiveButton("Close", 19 | new DialogInterface.OnClickListener() { 20 | public void onClick(DialogInterface dialog, int id) { 21 | } 22 | }); 23 | AlertDialog alert = builder.create(); 24 | alert.show(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /PWMDemo-Rockchip/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_SRC_FILES := $(call all-subdir-java-files) 5 | 6 | LOCAL_PACKAGE_NAME := PWMDemo 7 | 8 | LOCAL_PRIVATE_PLATFORM_APIS := true 9 | LOCAL_PRIVILEGED_MODULE := true 10 | LOCAL_CERTIFICATE := platform 11 | LOCAL_MODULE_TAGS := optional 12 | LOCAL_CFLAGS := -lfriendlyarm-things 13 | 14 | include $(BUILD_PACKAGE) 15 | -------------------------------------------------------------------------------- /PWMDemo-Rockchip/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /PWMDemo-Rockchip/libs/arm64-v8a/libfriendlyarm-things.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/PWMDemo-Rockchip/libs/arm64-v8a/libfriendlyarm-things.so -------------------------------------------------------------------------------- /PWMDemo-Rockchip/libs/armeabi/libfriendlyarm-things.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/PWMDemo-Rockchip/libs/armeabi/libfriendlyarm-things.so -------------------------------------------------------------------------------- /PWMDemo-Rockchip/res/drawable/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/PWMDemo-Rockchip/res/drawable/icon.png -------------------------------------------------------------------------------- /PWMDemo-Rockchip/res/layout/pwmtestingactivity.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 12 | 18 | 26 | 32 | 38 | 13 | 14 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /PWMDemo/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | PWM Demo 4 | PWM Testing: /dev/pwm 5 | + 6 | - 7 | 1000 8 | Frequency: 9 | Start 10 | Stop 11 | Back 12 | 13 | -------------------------------------------------------------------------------- /PWMDemo/src/com/friendlyarm/FriendlyThings/FileCtlEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | 3 | public class FileCtlEnum { 4 | /* File Flag */ 5 | public final static int O_ACCMODE = 00000003; 6 | public final static int O_RDONLY = 00000000; 7 | public final static int O_WRONLY = 00000001; 8 | public final static int O_RDWR = 00000002; 9 | public final static int O_CREAT = 00000100; /* not fcntl */ 10 | public final static int O_EXCL = 00000200; /* not fcntl */ 11 | public final static int O_NOCTTY = 00000400; /* not fcntl */ 12 | public final static int O_TRUNC = 00001000; /* not fcntl */ 13 | public final static int O_APPEND = 00002000; 14 | public final static int O_NONBLOCK = 00004000; 15 | public final static int O_DSYNC = 00010000; /* used to be O_SYNC, see below */ 16 | public final static int FASYNC = 00020000; /* fcntl, for BSD compatibility */ 17 | public final static int O_DIRECT = 00040000; /* direct disk access hint */ 18 | public final static int O_LARGEFILE = 00100000; 19 | public final static int O_DIRECTORY = 00200000; /* must be a directory */ 20 | public final static int O_NOFOLLOW = 00400000; /* don't follow links */ 21 | public final static int O_NOATIME = 01000000; 22 | public final static int O_CLOEXEC = 02000000; /* set close_on_exec */ 23 | } 24 | -------------------------------------------------------------------------------- /PWMDemo/src/com/friendlyarm/FriendlyThings/GPIOEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | 3 | /* 4 | GPIO signals have paths like /sys/class/gpio/gpio42/ (for GPIO #42) 5 | and have the following read/write attributes: 6 | 7 | /sys/class/gpio/gpioN/ 8 | 9 | "direction" ... reads as either "in" or "out". This value may 10 | normally be written. Writing as "out" defaults to 11 | initializing the value as low. To ensure glitch free 12 | operation, values "low" and "high" may be written to 13 | configure the GPIO as an output with that initial value. 14 | 15 | Note that this attribute *will not exist* if the kernel 16 | doesn't support changing the direction of a GPIO, or 17 | it was exported by kernel code that didn't explicitly 18 | allow userspace to reconfigure this GPIO's direction. 19 | 20 | "value" ... reads as either 0 (low) or 1 (high). If the GPIO 21 | is configured as an output, this value may be written; 22 | any nonzero value is treated as high. 23 | 24 | If the pin can be configured as interrupt-generating interrupt 25 | and if it has been configured to generate interrupts (see the 26 | description of "edge"), you can poll(2) on that file and 27 | poll(2) will return whenever the interrupt was triggered. If 28 | you use poll(2), set the events POLLPRI and POLLERR. If you 29 | use select(2), set the file descriptor in exceptfds. After 30 | poll(2) returns, either lseek(2) to the beginning of the sysfs 31 | file and read the new value or close the file and re-open it 32 | to read the value. 33 | */ 34 | 35 | public class GPIOEnum { 36 | //Direction 37 | public final static int IN = 1; 38 | public final static int OUT = 2; 39 | 40 | //Value 41 | public final static int LOW = 0; 42 | public final static int HIGH = 1; 43 | } 44 | -------------------------------------------------------------------------------- /PWMDemo/src/com/friendlyarm/FriendlyThings/HardwareControler.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | import android.util.Log; 3 | 4 | public class HardwareControler 5 | { 6 | /* I/O */ 7 | static public native int open(String devName, int flags); 8 | static public native int write(int fd, byte[] data); 9 | static public native int read(int fd, byte[] buf, int len); 10 | static public native int select(int fd, int sec, int usec); 11 | static public native void close(int fd); 12 | static public native int ioctlWithIntValue(int fd, int cmd, int value); 13 | static public native int ioctl(int fd, int cmd, byte[] buf); 14 | 15 | /* Serial Port */ 16 | static public native int openSerialPort( String devName, long baud, int dataBits, int stopBits ); 17 | static public native int openSerialPortEx( String devName 18 | , long baud 19 | , int dataBits 20 | , int stopBits 21 | , String parityBit 22 | , String flowCtrl 23 | ); 24 | 25 | /* LED */ 26 | static public native int setLedState( int ledID, int ledState ); 27 | 28 | /* PWM */ 29 | static public native int PWMPlay(int frequency); 30 | static public native int PWMStop(); 31 | static public native int PWMPlayEx(int gpioPin, int frequency); 32 | static public native int PWMStopEx(int gpioPin); 33 | 34 | /* ADC */ 35 | static public native int readADC(); 36 | static public native int readADCWithChannel(int channel); 37 | static public native int[] readADCWithChannels(int[] channels); 38 | 39 | /* I2C */ 40 | static public native int setI2CSlave(int fd, int slave); 41 | static public native int setI2CTimeout(int fd, int timeout); 42 | static public native int setI2CRetries(int fd, int retries); 43 | static public native int I2CReadByteData(int fd, int pos, int wait_us); 44 | static public native int I2CReadByte(int fd, int wait_us); 45 | static public native int I2CWriteByteData(int fd, int pos, byte byteData, int wait_us); 46 | static public native int I2CWriteByte(int fd, byte byteData, int wait_us); 47 | 48 | /* Discard */ static public native int readByteFromI2C(int fd, int pos, int wait_ms); 49 | /* Discard */ static public native int writeByteToI2C(int fd, int pos, byte byteData, int wait_ms); 50 | /* Discard */ static public native int writeByteToI2C2(int fd, byte byteData, int wait_ms); 51 | 52 | /* SPI */ 53 | static public native int setSPIWriteBitsPerWord( int spi_fd, int bits ); 54 | static public native int setSPIReadBitsPerWord( int spi_fd, int bits ); 55 | static public native int setSPIBitOrder( int spi_fd, int order); 56 | static public native int setSPIClockDivider( int spi_fd, int divider); 57 | static public native int setSPIMaxSpeed( int spi_fd, int spi_speed); 58 | static public native int setSPIDataMode( int spi_fd, int mode); 59 | static public native int SPItransferOneByte( int spi_fd, byte byteData, int spi_delay, int spi_speed, int spi_bits); 60 | static public native int SPItransferBytes(int spi_fd, byte[] writeData, byte[] readBuff, int spi_delay, int spi_speed, int spi_bits); 61 | static public native int writeBytesToSPI(int spi_fd, byte[] writeData, int spi_delay, int spi_speed, int spi_bits); 62 | static public native int readBytesFromSPI(int spi_fd, byte[] readBuff, int spi_delay, int spi_speed, int spi_bits); 63 | 64 | /* GPIO */ 65 | static public native int exportGPIOPin(int pin); 66 | static public native int unexportGPIOPin(int pin); 67 | //GPIOEnum.LOW or GPIOEnum.HIGH 68 | static public native int setGPIOValue(int pin, int value); 69 | static public native int getGPIOValue(int pin); 70 | //GPIOEnum.IN or GPIOEnum.OUT 71 | static public native int setGPIODirection(int pin, int direction); 72 | static public native int getGPIODirection(int pin); 73 | 74 | /* OldInterface: for EEPROM */ 75 | static public native int openI2CDevice(); 76 | static public native int writeByteDataToI2C(int fd, int pos, byte byteData); 77 | static public native int readByteDataFromI2C(int fd, int pos); 78 | 79 | /* return BoardType.xxx */ 80 | static public native int getBoardType(); 81 | 82 | static { 83 | try { 84 | System.loadLibrary("friendlyarm-things"); 85 | } catch (UnsatisfiedLinkError e) { 86 | Log.d("HardwareControler", "libfriendlyarm-things library not found!"); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /PWMDemo/src/com/friendlyarm/FriendlyThings/SPI.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | import android.util.Log; 3 | import android.widget.Toast; 4 | 5 | import com.friendlyarm.FriendlyThings.HardwareControler; 6 | import com.friendlyarm.FriendlyThings.SPIEnum; 7 | import com.friendlyarm.FriendlyThings.GPIOEnum; 8 | import com.friendlyarm.FriendlyThings.FileCtlEnum; 9 | 10 | public class SPI { 11 | private static final String TAG = "com.friendlyarm.FriendlyThings.SPI"; 12 | private int spi_mode = 0; 13 | private int spi_bits = 8; 14 | private int spi_delay = 0; 15 | private int spi_speed = 500000; 16 | private int spi_byte_order = SPIEnum.LSBFIRST; 17 | 18 | private static final String devName = "/dev/spidev1.0"; 19 | private int spi_fd = -1; 20 | 21 | public void begin() { 22 | spi_fd = HardwareControler.open( devName, FileCtlEnum.O_RDWR ); 23 | if (spi_fd >= 0) { 24 | Log.d(TAG, "open " + devName + "ok!"); 25 | 26 | /* spi init */ 27 | HardwareControler.setSPIWriteBitsPerWord( spi_fd, spi_bits ); 28 | HardwareControler.setSPIReadBitsPerWord( spi_fd, spi_bits ); 29 | } else { 30 | Log.d(TAG, "open " + devName + "failed!"); 31 | spi_fd = -1; 32 | } 33 | } 34 | 35 | public void end() { 36 | if (spi_fd != -1) { 37 | HardwareControler.close(spi_fd); 38 | spi_fd = -1; 39 | } 40 | } 41 | 42 | public void setBitOrder(int order) { 43 | if (spi_fd < 0) { 44 | return ; 45 | } 46 | spi_byte_order = SPIEnum.MSBFIRST; 47 | if(spi_byte_order == SPIEnum.LSBFIRST) { 48 | spi_mode |= SPIEnum.SPI_LSB_FIRST; 49 | } else { 50 | spi_mode &= ~SPIEnum.SPI_LSB_FIRST; 51 | } 52 | HardwareControler.setSPIBitOrder( spi_fd, spi_byte_order ); 53 | 54 | } 55 | 56 | public void setClockDivider(int divider) { 57 | if (spi_fd < 0) { 58 | return ; 59 | } 60 | spi_speed = 66666666/(2*(divider+1)); 61 | if(spi_speed > 500000) { 62 | spi_speed = 500000; 63 | } 64 | HardwareControler.setSPIClockDivider( spi_fd, divider); 65 | } 66 | 67 | public void setDataMode(int mode) { 68 | if (spi_fd < 0) { 69 | return ; 70 | } 71 | switch(mode) 72 | { 73 | case SPIEnum.SPI_MODE0: 74 | spi_mode &= ~(SPIEnum.SPI_CPHA|SPIEnum.SPI_CPOL); 75 | break; 76 | case SPIEnum.SPI_MODE1: 77 | spi_mode &= ~(SPIEnum.SPI_CPOL); 78 | spi_mode |= (SPIEnum.SPI_CPHA); 79 | break; 80 | case SPIEnum.SPI_MODE2: 81 | spi_mode |= (SPIEnum.SPI_CPOL); 82 | spi_mode &= ~(SPIEnum.SPI_CPHA); 83 | break; 84 | case SPIEnum.SPI_MODE3: 85 | spi_mode |= (SPIEnum.SPI_CPHA|SPIEnum.SPI_CPOL); 86 | break; 87 | default: 88 | Log.e(TAG, "error data mode"); 89 | } 90 | 91 | HardwareControler.setSPIDataMode( spi_fd, spi_mode ); 92 | } 93 | 94 | public void setChipSelectPolarity(int cs, int active) { 95 | 96 | } 97 | 98 | public void chipSelect(int cs) { 99 | 100 | } 101 | 102 | public byte transfer(int value) { 103 | if (spi_fd < 0) { 104 | return 0; 105 | } 106 | return (byte) HardwareControler.SPItransferOneByte(spi_fd, (byte) value, spi_delay, spi_speed, spi_bits); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /PWMDemo/src/com/friendlyarm/FriendlyThings/SPIEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | public class SPIEnum { 3 | 4 | // SPIBitOrder 5 | public final static int LSBFIRST = 0; ///< LSB First 6 | public final static int MSBFIRST = 1; ///< MSB First 7 | 8 | // SPIMode 9 | public final static int SPI_MODE0 = 0; ///< CPOL = 0, CPHA = 0 10 | public final static int SPI_MODE1 = 1; ///< CPOL = 0, CPHA = 1 11 | public final static int SPI_MODE2 = 2; ///< CPOL = 1, CPHA = 0 12 | public final static int SPI_MODE3 = 3; ///< CPOL = 1, CPHA = 1 13 | 14 | 15 | public final static int SPI_CPHA = 0x01; 16 | public final static int SPI_CPOL = 0x02; 17 | public final static int SPI_CS_HIGH = 0x04; 18 | public final static int SPI_LSB_FIRST = 0x08; 19 | public final static int SPI_3WIRE = 0x10; 20 | public final static int SPI_LOOP = 0x20; 21 | public final static int SPI_NO_CS = 0x40; 22 | public final static int SPI_READY = 0x80; 23 | 24 | // SPIClockDivider 25 | public final static int SPI_CLOCK_DIV65536 = 0; ///< 65536 = 256us = 4kHz 26 | public final static int SPI_CLOCK_DIV32768 = 32768; ///< 32768 = 126us = 8kHz 27 | public final static int SPI_CLOCK_DIV16384 = 16384; ///< 16384 = 64us = 15.625kHz 28 | public final static int SPI_CLOCK_DIV8192 = 8192; ///< 8192 = 32us = 31.25kHz 29 | public final static int SPI_CLOCK_DIV4096 = 4096; ///< 4096 = 16us = 62.5kHz 30 | public final static int SPI_CLOCK_DIV2048 = 2048; ///< 2048 = 8us = 125kHz 31 | public final static int SPI_CLOCK_DIV1024 = 1024; ///< 1024 = 4us = 250kHz 32 | public final static int SPI_CLOCK_DIV512 = 512; ///< 512 = 2us = 500kHz 33 | public final static int SPI_CLOCK_DIV256 = 256; ///< 256 = 1us = 1MHz 34 | public final static int SPI_CLOCK_DIV128 = 128; ///< 128 = 500ns = = 2MHz 35 | public final static int SPI_CLOCK_DIV64 = 64; ///< 64 = 250ns = 4MHz 36 | public final static int SPI_CLOCK_DIV32 = 32; ///< 32 = 125ns = 8MHz 37 | public final static int SPI_CLOCK_DIV16 = 16; ///< 16 = 50ns = 20MHz 38 | public final static int SPI_CLOCK_DIV8 = 8; ///< 8 = 25ns = 40MHz 39 | public final static int SPI_CLOCK_DIV4 = 4; ///< 4 = 12.5ns 80MHz 40 | public final static int SPI_CLOCK_DIV2 = 2; ///< 2 = 6.25ns = 160MHz 41 | public final static int SPI_CLOCK_DIV1 = 1; ///< 0 = 256us = 4kHz 42 | } -------------------------------------------------------------------------------- /PWMDemo/src/com/friendlyarm/FriendlyThings/WatchDogEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | 3 | public class WatchDogEnum { 4 | /* include/uapi/linux/watchdog.h */ 5 | public final static int WDIOC_GETSUPPORT = 0x80285700; 6 | public final static int WDIOC_GETSTATUS = 0x80045701; 7 | public final static int WDIOC_GETBOOTSTATUS = 0x80045702; 8 | public final static int WDIOC_GETTEMP = 0x80045703; 9 | public final static int WDIOC_SETOPTIONS = 0x80045704; 10 | public final static int WDIOC_KEEPALIVE = 0x80045705; 11 | public final static int WDIOC_SETTIMEOUT = 0xC0045706; 12 | public final static int WDIOC_GETTIMEOUT = 0x80045707; 13 | public final static int WDIOC_SETPRETIMEOUT = 0xC0045708; 14 | public final static int WDIOC_GETPRETIMEOUT = 0x80045709; 15 | public final static int WDIOC_GETTIMELEFT = 0x8004570A; 16 | 17 | public final static int WDIOF_UNKNOWN = -1; /* Unknown flag error */ 18 | public final static int WDIOS_UNKNOWN = -1; /* Unknown status error */ 19 | 20 | public final static int WDIOF_OVERHEAT = 0x0001; /* Reset due to CPU overheat */ 21 | public final static int WDIOF_FANFAULT = 0x0002; /* Fan failed */ 22 | public final static int WDIOF_EXTERN1 = 0x0004; /* External relay 1 */ 23 | public final static int WDIOF_EXTERN2 = 0x0008; /* External relay 2 */ 24 | public final static int WDIOF_POWERUNDER = 0x0010; /* Power bad/power fault */ 25 | public final static int WDIOF_CARDRESET = 0x0020; /* Card previously reset the CPU */ 26 | public final static int WDIOF_POWEROVER = 0x0040; /* Power over voltage */ 27 | public final static int WDIOF_SETTIMEOUT = 0x0080; /* Set timeout (in seconds) */ 28 | public final static int WDIOF_MAGICCLOSE = 0x0100; /* Supports magic close char */ 29 | public final static int WDIOF_PRETIMEOUT = 0x0200; /* Pretimeout (in seconds), get/set */ 30 | public final static int WDIOF_ALARMONLY = 0x0400; /* Watchdog triggers a management or other external alarm not a reboot */ 31 | public final static int WDIOF_KEEPALIVEPING = 0x8000; /* Keep alive ping reply */ 32 | 33 | public final static int WDIOS_DISABLECARD = 0x0001; /* Turn off the watchdog timer */ 34 | public final static int WDIOS_ENABLECARD = 0x0002; /* Turn on the watchdog timer */ 35 | public final static int WDIOS_TEMPPANIC = 0x0004; /* Kernel panic on temperature trip */ 36 | 37 | } 38 | -------------------------------------------------------------------------------- /PWMDemo/src/com/friendlyarm/PWMDemo/PWMTestingActivity.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.PWMDemo; 2 | 3 | import com.friendlyarm.FriendlyThings.HardwareControler; 4 | import com.friendlyarm.FriendlyThings.BoardType; 5 | import com.friendlyarm.PWMDemo.R; 6 | import com.friendlyarm.Utils.CommonFuncs; 7 | 8 | import android.app.Activity; 9 | import android.content.res.Configuration; 10 | import android.os.Bundle; 11 | import android.widget.TextView; 12 | import android.util.Log; 13 | import android.view.View; 14 | import android.widget.Button; 15 | import android.widget.EditText; 16 | import android.view.View.OnClickListener; 17 | 18 | public class PWMTestingActivity extends Activity implements OnClickListener { 19 | HardwareControler hw; 20 | EditText textEditor; 21 | Button btnSub; 22 | Button btnAdd; 23 | 24 | final int smart4418PWMGPIOPin = 97; //GPIOD1, Smart4418/NanoPC-T2/NanoPC-T3 25 | 26 | private int mBoardType = HardwareControler.getBoardType(); 27 | private boolean isS5Pxx18Board() { 28 | if (mBoardType>=BoardType.S5P4418_BASE && mBoardType<=BoardType.S5P4418_MAX) { 29 | return true; 30 | } 31 | if (mBoardType>=BoardType.S5P6818_BASE && mBoardType<=BoardType.S5P6818_MAX) { 32 | return true; 33 | } 34 | return false; 35 | } 36 | 37 | /** Called when the activity is first created. */ 38 | @Override 39 | public void onCreate(Bundle savedInstanceState) { 40 | super.onCreate(savedInstanceState); 41 | setContentView(R.layout.pwmtestingactivity); 42 | 43 | btnSub = ((Button)findViewById(R.id.btnSub)); 44 | btnAdd = ((Button)findViewById(R.id.btnAdd)); 45 | 46 | btnSub.setOnClickListener(this); 47 | btnAdd.setOnClickListener(this); 48 | 49 | textEditor = ((EditText)findViewById(R.id.fEditor)); 50 | hw = new HardwareControler(); 51 | } 52 | 53 | private void playPWM() 54 | { 55 | int f; 56 | f = Integer.valueOf(textEditor.getText().toString()).intValue(); 57 | int boardType = HardwareControler.getBoardType(); 58 | Log.d("PWMDemo", "boardtype = " + boardType); 59 | 60 | if (isS5Pxx18Board()) { 61 | if (hw.PWMPlayEx(smart4418PWMGPIOPin, f) != 0) { 62 | CommonFuncs.showAlertDialog(this,"Fail to play!"); 63 | } 64 | } else { 65 | if (hw.PWMPlay(f) != 0) { 66 | CommonFuncs.showAlertDialog(this,"Fail to play!"); 67 | } 68 | } 69 | } 70 | 71 | private void stopPWM() 72 | { 73 | if (isS5Pxx18Board()) { 74 | if (hw.PWMStopEx(smart4418PWMGPIOPin) != 0) { 75 | CommonFuncs.showAlertDialog(this,"Fail to stop!"); 76 | } 77 | } else { 78 | if (hw.PWMStop() != 0) { 79 | CommonFuncs.showAlertDialog(this,"Fail to stop!"); 80 | } 81 | } 82 | } 83 | 84 | public void onClick(View v) { 85 | int f; 86 | switch (v.getId()) { 87 | case R.id.btnSub: 88 | f = Integer.valueOf(textEditor.getText().toString()).intValue() - 100; 89 | if (f < 1) { 90 | f = 1; 91 | } 92 | textEditor.setText( "" + f ); 93 | playPWM(); 94 | break; 95 | case R.id.btnAdd: 96 | f = Integer.valueOf(textEditor.getText().toString()).intValue() + 100; 97 | if (f < 1) { 98 | f = 1; 99 | } 100 | textEditor.setText( "" + f ); 101 | playPWM(); 102 | break; 103 | default: 104 | break; 105 | } 106 | } 107 | 108 | @Override 109 | public void onStart() { 110 | super.onStart(); 111 | } 112 | 113 | @Override 114 | public void onRestart() { 115 | super.onRestart(); 116 | } 117 | 118 | @Override 119 | public void onResume() { 120 | super.onResume(); 121 | playPWM(); 122 | } 123 | 124 | @Override 125 | public void onPause() { 126 | stopPWM(); 127 | super.onPause(); 128 | } 129 | 130 | @Override 131 | public void onStop() { 132 | stopPWM(); 133 | super.onStop(); 134 | } 135 | 136 | @Override 137 | public void onDestroy() { 138 | stopPWM(); 139 | super.onDestroy(); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /PWMDemo/src/com/friendlyarm/Utils/BorderScrollView.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.Utils; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Paint; 6 | import android.util.AttributeSet; 7 | import android.widget.ScrollView; 8 | 9 | 10 | public class BorderScrollView extends ScrollView 11 | { 12 | @Override 13 | protected void onDraw(Canvas canvas) 14 | { 15 | super.onDraw(canvas); 16 | Paint paint = new Paint(); 17 | paint.setColor(android.graphics.Color.GRAY); 18 | canvas.drawLine(0, 0, this.getWidth() - 1, 0, paint); 19 | canvas.drawLine(0, 0, 0, this.getHeight() - 1, paint); 20 | canvas.drawLine(this.getWidth() - 1, 0, this.getWidth() - 1, this.getHeight() - 1, paint); 21 | canvas.drawLine(0, this.getHeight() - 1, this.getWidth() - 1, this.getHeight() - 1, paint); 22 | } 23 | public BorderScrollView(Context context, AttributeSet attrs) 24 | { 25 | super(context, attrs); 26 | } 27 | } -------------------------------------------------------------------------------- /PWMDemo/src/com/friendlyarm/Utils/CommonFuncs.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.Utils; 2 | 3 | import android.app.Activity; 4 | import android.app.AlertDialog; 5 | import android.widget.Toast; 6 | import android.app.Activity; 7 | import android.os.Bundle; 8 | import android.os.Handler; 9 | import android.os.Message; 10 | import android.content.Context; 11 | import android.content.DialogInterface; 12 | 13 | public class CommonFuncs { 14 | public static void showAlertDialog(Context context, String message) { 15 | AlertDialog.Builder builder = new AlertDialog.Builder(context); 16 | builder.setMessage(message) 17 | .setCancelable(false) 18 | .setPositiveButton("Close", 19 | new DialogInterface.OnClickListener() { 20 | public void onClick(DialogInterface dialog, int id) { 21 | } 22 | }); 23 | AlertDialog alert = builder.create(); 24 | alert.show(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FriendlyThings examples 2 | Examples for accessing FriendlyELEC's development board hardware on android. 3 | 4 | ## Applicable Boards & OS 5 | * NanoPC-T6/NanoPC-R6S/NanoPC-R6C: Android 12 6 | * NanoPC-R5S/NanoPC-R5C: Android 12 7 | * NanoPC-T4/NanoPi-M4/NanoPi-NEO4: Android 7, Android 8 8 | * NanoPC-T3/NanoPi-M3: Android 5 9 | * Smart4418 SDK/NanoPC-T2/NanoPi-M2/NanoPi S2: Android 5, Android 4.4 10 | * Tiny4412: Android 4.2, Android 5 11 | * Tiny210/Smart210/Mini210: Android 4.2 12 | * Tiny6410/Mini6410: Android 2.3 13 | 14 | ## Accessible Interfaces & Ports 15 | 16 | * Serial Port 17 | * PWM 18 | * EEPROM 19 | * ADC 20 | * LED 21 | * LCD 1602 (I2C) 22 | * OLED (SPI) 23 | 24 | I2C, SPI, GPIO are accessible. 25 | 26 | ![image](https://github.com/friendlyarm/AndroidHardwareAccess/raw/master/SPI_OLED_Demo/Smart4418SDK%2BOLED.png) 27 | 28 | ## Download SDK 29 | ``` 30 | git clone https://github.com/friendlyarm/friendlythings-sdk 31 | ``` 32 | 33 | ## Document 34 | [FriendlyThings](http://wiki.friendlyelec.com/wiki/index.php/FriendlyThings) 35 | [FriendlyThings APIs](http://wiki.friendlyelec.com/wiki/index.php/FriendlyThings) 36 | [FriendlyThings for Rockchip](http://wiki.friendlyelec.com/wiki/index.php/FriendlyThings_for_Rockchip) 37 | -------------------------------------------------------------------------------- /RTC_Demo-Rockchip/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_SRC_FILES := $(call all-subdir-java-files) 5 | 6 | LOCAL_PACKAGE_NAME := RTCDemo 7 | 8 | LOCAL_PRIVATE_PLATFORM_APIS := true 9 | LOCAL_PRIVILEGED_MODULE := true 10 | LOCAL_CERTIFICATE := platform 11 | LOCAL_MODULE_TAGS := optional 12 | LOCAL_CFLAGS := -lfriendlyarm-things 13 | 14 | include $(BUILD_PACKAGE) 15 | -------------------------------------------------------------------------------- /RTC_Demo-Rockchip/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 15 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /RTC_Demo-Rockchip/libs/arm64-v8a/libfriendlyarm-things.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/RTC_Demo-Rockchip/libs/arm64-v8a/libfriendlyarm-things.so -------------------------------------------------------------------------------- /RTC_Demo-Rockchip/libs/armeabi/libfriendlyarm-things.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/RTC_Demo-Rockchip/libs/armeabi/libfriendlyarm-things.so -------------------------------------------------------------------------------- /RTC_Demo-Rockchip/res/drawable/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/RTC_Demo-Rockchip/res/drawable/icon.png -------------------------------------------------------------------------------- /RTC_Demo-Rockchip/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 10 | 11 | 17 | 18 | 23 | 29 | 30 | 35 | 36 | 43 | 44 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /RTC_Demo-Rockchip/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | RTC Sample 4 | RTC Date 5 | RTC Time 6 | Auto Wake Up 7 | Enable Auto Wake Up 8 | Power off 9 | More samples? \nClick here 10 | 11 | 12 | -------------------------------------------------------------------------------- /RTC_Demo-Rockchip/src/com/friendlyarm/FriendlyThings/FileCtlEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | 3 | public class FileCtlEnum { 4 | /* File Flag */ 5 | public final static int O_ACCMODE = 00000003; 6 | public final static int O_RDONLY = 00000000; 7 | public final static int O_WRONLY = 00000001; 8 | public final static int O_RDWR = 00000002; 9 | public final static int O_CREAT = 00000100; /* not fcntl */ 10 | public final static int O_EXCL = 00000200; /* not fcntl */ 11 | public final static int O_NOCTTY = 00000400; /* not fcntl */ 12 | public final static int O_TRUNC = 00001000; /* not fcntl */ 13 | public final static int O_APPEND = 00002000; 14 | public final static int O_NONBLOCK = 00004000; 15 | public final static int O_DSYNC = 00010000; /* used to be O_SYNC, see below */ 16 | public final static int FASYNC = 00020000; /* fcntl, for BSD compatibility */ 17 | public final static int O_DIRECT = 00040000; /* direct disk access hint */ 18 | public final static int O_LARGEFILE = 00100000; 19 | public final static int O_DIRECTORY = 00200000; /* must be a directory */ 20 | public final static int O_NOFOLLOW = 00400000; /* don't follow links */ 21 | public final static int O_NOATIME = 01000000; 22 | public final static int O_CLOEXEC = 02000000; /* set close_on_exec */ 23 | } 24 | -------------------------------------------------------------------------------- /RTC_Demo-Rockchip/src/com/friendlyarm/FriendlyThings/GPIOEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | 3 | /* 4 | GPIO signals have paths like /sys/class/gpio/gpio42/ (for GPIO #42) 5 | and have the following read/write attributes: 6 | 7 | /sys/class/gpio/gpioN/ 8 | 9 | "direction" ... reads as either "in" or "out". This value may 10 | normally be written. Writing as "out" defaults to 11 | initializing the value as low. To ensure glitch free 12 | operation, values "low" and "high" may be written to 13 | configure the GPIO as an output with that initial value. 14 | 15 | Note that this attribute *will not exist* if the kernel 16 | doesn't support changing the direction of a GPIO, or 17 | it was exported by kernel code that didn't explicitly 18 | allow userspace to reconfigure this GPIO's direction. 19 | 20 | "value" ... reads as either 0 (low) or 1 (high). If the GPIO 21 | is configured as an output, this value may be written; 22 | any nonzero value is treated as high. 23 | 24 | If the pin can be configured as interrupt-generating interrupt 25 | and if it has been configured to generate interrupts (see the 26 | description of "edge"), you can poll(2) on that file and 27 | poll(2) will return whenever the interrupt was triggered. If 28 | you use poll(2), set the events POLLPRI and POLLERR. If you 29 | use select(2), set the file descriptor in exceptfds. After 30 | poll(2) returns, either lseek(2) to the beginning of the sysfs 31 | file and read the new value or close the file and re-open it 32 | to read the value. 33 | */ 34 | 35 | public class GPIOEnum { 36 | //Direction 37 | public final static int IN = 1; 38 | public final static int OUT = 2; 39 | 40 | //Value 41 | public final static int LOW = 0; 42 | public final static int HIGH = 1; 43 | } 44 | -------------------------------------------------------------------------------- /RTC_Demo-Rockchip/src/com/friendlyarm/FriendlyThings/SPI.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | import android.util.Log; 3 | import android.widget.Toast; 4 | 5 | import com.friendlyarm.FriendlyThings.HardwareControler; 6 | import com.friendlyarm.FriendlyThings.SPIEnum; 7 | import com.friendlyarm.FriendlyThings.GPIOEnum; 8 | import com.friendlyarm.FriendlyThings.FileCtlEnum; 9 | 10 | public class SPI { 11 | private static final String TAG = "com.friendlyarm.FriendlyThings.SPI"; 12 | private int spi_mode = 0; 13 | private int spi_bits = 8; 14 | private int spi_delay = 0; 15 | private int spi_speed = 500000; 16 | private int spi_byte_order = SPIEnum.LSBFIRST; 17 | 18 | private static final String devName = "/dev/spidev1.0"; 19 | private int spi_fd = -1; 20 | 21 | public void begin() { 22 | spi_fd = HardwareControler.open( devName, FileCtlEnum.O_RDWR ); 23 | if (spi_fd >= 0) { 24 | Log.d(TAG, "open " + devName + "ok!"); 25 | 26 | /* spi init */ 27 | HardwareControler.setSPIWriteBitsPerWord( spi_fd, spi_bits ); 28 | HardwareControler.setSPIReadBitsPerWord( spi_fd, spi_bits ); 29 | } else { 30 | Log.d(TAG, "open " + devName + "failed!"); 31 | spi_fd = -1; 32 | } 33 | } 34 | 35 | public void end() { 36 | if (spi_fd != -1) { 37 | HardwareControler.close(spi_fd); 38 | spi_fd = -1; 39 | } 40 | } 41 | 42 | public void setBitOrder(int order) { 43 | if (spi_fd < 0) { 44 | return ; 45 | } 46 | spi_byte_order = SPIEnum.MSBFIRST; 47 | if(spi_byte_order == SPIEnum.LSBFIRST) { 48 | spi_mode |= SPIEnum.SPI_LSB_FIRST; 49 | } else { 50 | spi_mode &= ~SPIEnum.SPI_LSB_FIRST; 51 | } 52 | HardwareControler.setSPIBitOrder( spi_fd, spi_byte_order ); 53 | 54 | } 55 | 56 | public void setClockDivider(int divider) { 57 | if (spi_fd < 0) { 58 | return ; 59 | } 60 | spi_speed = 66666666/(2*(divider+1)); 61 | if(spi_speed > 500000) { 62 | spi_speed = 500000; 63 | } 64 | HardwareControler.setSPIClockDivider( spi_fd, divider); 65 | } 66 | 67 | public void setDataMode(int mode) { 68 | if (spi_fd < 0) { 69 | return ; 70 | } 71 | switch(mode) 72 | { 73 | case SPIEnum.SPI_MODE0: 74 | spi_mode &= ~(SPIEnum.SPI_CPHA|SPIEnum.SPI_CPOL); 75 | break; 76 | case SPIEnum.SPI_MODE1: 77 | spi_mode &= ~(SPIEnum.SPI_CPOL); 78 | spi_mode |= (SPIEnum.SPI_CPHA); 79 | break; 80 | case SPIEnum.SPI_MODE2: 81 | spi_mode |= (SPIEnum.SPI_CPOL); 82 | spi_mode &= ~(SPIEnum.SPI_CPHA); 83 | break; 84 | case SPIEnum.SPI_MODE3: 85 | spi_mode |= (SPIEnum.SPI_CPHA|SPIEnum.SPI_CPOL); 86 | break; 87 | default: 88 | Log.e(TAG, "error data mode"); 89 | } 90 | 91 | HardwareControler.setSPIDataMode( spi_fd, spi_mode ); 92 | } 93 | 94 | public void setChipSelectPolarity(int cs, int active) { 95 | 96 | } 97 | 98 | public void chipSelect(int cs) { 99 | 100 | } 101 | 102 | public byte transfer(int value) { 103 | if (spi_fd < 0) { 104 | return 0; 105 | } 106 | return (byte) HardwareControler.SPItransferOneByte(spi_fd, (byte) value, spi_delay, spi_speed, spi_bits); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /RTC_Demo-Rockchip/src/com/friendlyarm/FriendlyThings/SPIEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | public class SPIEnum { 3 | 4 | // SPIBitOrder 5 | public final static int LSBFIRST = 0; ///< LSB First 6 | public final static int MSBFIRST = 1; ///< MSB First 7 | 8 | // SPIMode 9 | public final static int SPI_MODE0 = 0; ///< CPOL = 0, CPHA = 0 10 | public final static int SPI_MODE1 = 1; ///< CPOL = 0, CPHA = 1 11 | public final static int SPI_MODE2 = 2; ///< CPOL = 1, CPHA = 0 12 | public final static int SPI_MODE3 = 3; ///< CPOL = 1, CPHA = 1 13 | 14 | 15 | public final static int SPI_CPHA = 0x01; 16 | public final static int SPI_CPOL = 0x02; 17 | public final static int SPI_CS_HIGH = 0x04; 18 | public final static int SPI_LSB_FIRST = 0x08; 19 | public final static int SPI_3WIRE = 0x10; 20 | public final static int SPI_LOOP = 0x20; 21 | public final static int SPI_NO_CS = 0x40; 22 | public final static int SPI_READY = 0x80; 23 | 24 | // SPIClockDivider 25 | public final static int SPI_CLOCK_DIV65536 = 0; ///< 65536 = 256us = 4kHz 26 | public final static int SPI_CLOCK_DIV32768 = 32768; ///< 32768 = 126us = 8kHz 27 | public final static int SPI_CLOCK_DIV16384 = 16384; ///< 16384 = 64us = 15.625kHz 28 | public final static int SPI_CLOCK_DIV8192 = 8192; ///< 8192 = 32us = 31.25kHz 29 | public final static int SPI_CLOCK_DIV4096 = 4096; ///< 4096 = 16us = 62.5kHz 30 | public final static int SPI_CLOCK_DIV2048 = 2048; ///< 2048 = 8us = 125kHz 31 | public final static int SPI_CLOCK_DIV1024 = 1024; ///< 1024 = 4us = 250kHz 32 | public final static int SPI_CLOCK_DIV512 = 512; ///< 512 = 2us = 500kHz 33 | public final static int SPI_CLOCK_DIV256 = 256; ///< 256 = 1us = 1MHz 34 | public final static int SPI_CLOCK_DIV128 = 128; ///< 128 = 500ns = = 2MHz 35 | public final static int SPI_CLOCK_DIV64 = 64; ///< 64 = 250ns = 4MHz 36 | public final static int SPI_CLOCK_DIV32 = 32; ///< 32 = 125ns = 8MHz 37 | public final static int SPI_CLOCK_DIV16 = 16; ///< 16 = 50ns = 20MHz 38 | public final static int SPI_CLOCK_DIV8 = 8; ///< 8 = 25ns = 40MHz 39 | public final static int SPI_CLOCK_DIV4 = 4; ///< 4 = 12.5ns 80MHz 40 | public final static int SPI_CLOCK_DIV2 = 2; ///< 2 = 6.25ns = 160MHz 41 | public final static int SPI_CLOCK_DIV1 = 1; ///< 0 = 256us = 4kHz 42 | } -------------------------------------------------------------------------------- /RTC_Demo-Rockchip/src/com/friendlyarm/FriendlyThings/WatchDogEnum.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.FriendlyThings; 2 | 3 | public class WatchDogEnum { 4 | /* include/uapi/linux/watchdog.h */ 5 | public final static int WDIOC_GETSUPPORT = 0x80285700; 6 | public final static int WDIOC_GETSTATUS = 0x80045701; 7 | public final static int WDIOC_GETBOOTSTATUS = 0x80045702; 8 | public final static int WDIOC_GETTEMP = 0x80045703; 9 | public final static int WDIOC_SETOPTIONS = 0x80045704; 10 | public final static int WDIOC_KEEPALIVE = 0x80045705; 11 | public final static int WDIOC_SETTIMEOUT = 0xC0045706; 12 | public final static int WDIOC_GETTIMEOUT = 0x80045707; 13 | public final static int WDIOC_SETPRETIMEOUT = 0xC0045708; 14 | public final static int WDIOC_GETPRETIMEOUT = 0x80045709; 15 | public final static int WDIOC_GETTIMELEFT = 0x8004570A; 16 | 17 | public final static int WDIOF_UNKNOWN = -1; /* Unknown flag error */ 18 | public final static int WDIOS_UNKNOWN = -1; /* Unknown status error */ 19 | 20 | public final static int WDIOF_OVERHEAT = 0x0001; /* Reset due to CPU overheat */ 21 | public final static int WDIOF_FANFAULT = 0x0002; /* Fan failed */ 22 | public final static int WDIOF_EXTERN1 = 0x0004; /* External relay 1 */ 23 | public final static int WDIOF_EXTERN2 = 0x0008; /* External relay 2 */ 24 | public final static int WDIOF_POWERUNDER = 0x0010; /* Power bad/power fault */ 25 | public final static int WDIOF_CARDRESET = 0x0020; /* Card previously reset the CPU */ 26 | public final static int WDIOF_POWEROVER = 0x0040; /* Power over voltage */ 27 | public final static int WDIOF_SETTIMEOUT = 0x0080; /* Set timeout (in seconds) */ 28 | public final static int WDIOF_MAGICCLOSE = 0x0100; /* Supports magic close char */ 29 | public final static int WDIOF_PRETIMEOUT = 0x0200; /* Pretimeout (in seconds), get/set */ 30 | public final static int WDIOF_ALARMONLY = 0x0400; /* Watchdog triggers a management or other external alarm not a reboot */ 31 | public final static int WDIOF_KEEPALIVEPING = 0x8000; /* Keep alive ping reply */ 32 | 33 | public final static int WDIOS_DISABLECARD = 0x0001; /* Turn off the watchdog timer */ 34 | public final static int WDIOS_ENABLECARD = 0x0002; /* Turn on the watchdog timer */ 35 | public final static int WDIOS_TEMPPANIC = 0x0004; /* Kernel panic on temperature trip */ 36 | 37 | } 38 | -------------------------------------------------------------------------------- /RTC_Demo-Rockchip/src/com/friendlyarm/Utils/CommonFuncs.java: -------------------------------------------------------------------------------- 1 | package com.friendlyarm.Utils; 2 | 3 | import android.app.Activity; 4 | import android.app.AlertDialog; 5 | import android.widget.Toast; 6 | import android.app.Activity; 7 | import android.os.Bundle; 8 | import android.os.Handler; 9 | import android.os.Message; 10 | import android.content.Context; 11 | import android.content.DialogInterface; 12 | 13 | public class CommonFuncs { 14 | public static void showAlertDialog(Context context, String message) { 15 | AlertDialog.Builder builder = new AlertDialog.Builder(context); 16 | builder.setMessage(message) 17 | .setCancelable(false) 18 | .setPositiveButton("Close", 19 | new DialogInterface.OnClickListener() { 20 | public void onClick(DialogInterface dialog, int id) { 21 | } 22 | }); 23 | AlertDialog alert = builder.create(); 24 | alert.show(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /RTC_Demo-Rockchip/sync.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | adb root; adb remount; adb sync; adb reboot; 4 | -------------------------------------------------------------------------------- /SDCardDemo/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_MODULE_TAGS := eng 5 | 6 | 7 | LOCAL_SRC_FILES := \ 8 | $(call all-java-files-under, src) 9 | 10 | LOCAL_PACKAGE_NAME := SDCardDemo 11 | 12 | include $(BUILD_PACKAGE) 13 | 14 | # additionally, build tests in sub-folders in a separate .apk 15 | include $(call all-makefiles-under,$(LOCAL_PATH)) 16 | -------------------------------------------------------------------------------- /SDCardDemo/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 17 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /SDCardDemo/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ANDROIDPATH=/opt/FriendlyARM/smart4418/android/ 4 | APPNAME=SDCardDemo 5 | APKNAME=${APPNAME}-r1.0.apk 6 | PRJPATH=$PWD 7 | cd $PRJPATH 8 | rm -rf bin gen 9 | 10 | cd $ANDROIDPATH 11 | rm -f $APKNAME 12 | . setenv 13 | mmm $PRJPATH -B 14 | java -jar out/host/linux-x86/framework/signapk.jar vendor/friendly-arm/nanopi2/security/platform.x509.pem vendor/friendly-arm/nanopi2/security/platform.pk8 out/target/product/nanopi2/obj/APPS/${APPNAME}_intermediates/package.apk.unsigned ${APPNAME}-unaligned.apk 15 | zipalign -v 4 ${APPNAME}-unaligned.apk $APKNAME 16 | adb install -r ${APKNAME} 17 | -------------------------------------------------------------------------------- /SDCardDemo/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/SDCardDemo/ic_launcher-web.png -------------------------------------------------------------------------------- /SDCardDemo/res/drawable-hdpi/ic_action_search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/SDCardDemo/res/drawable-hdpi/ic_action_search.png -------------------------------------------------------------------------------- /SDCardDemo/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/SDCardDemo/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /SDCardDemo/res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/SDCardDemo/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /SDCardDemo/res/drawable-mdpi/ic_action_search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/SDCardDemo/res/drawable-mdpi/ic_action_search.png -------------------------------------------------------------------------------- /SDCardDemo/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/SDCardDemo/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /SDCardDemo/res/drawable-xhdpi/ic_action_search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/SDCardDemo/res/drawable-xhdpi/ic_action_search.png -------------------------------------------------------------------------------- /SDCardDemo/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyarm/friendlythings-examples/9b5e5a09c04d9635304d0404e56796c9308f9eb3/SDCardDemo/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /SDCardDemo/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 |