@@ -5,3 +5,5 @@ lib*.so.* | |||
debian-template/wiringPi | |||
debian-template/wiringpi-*.deb | |||
gpio/gpio | |||
libs/ | |||
obj/ |
@@ -0,0 +1,119 @@ | |||
cc_library_headers { | |||
name: "wiringPi-headers", | |||
export_include_dirs: ["wiringPi"], | |||
vendor_available: true, | |||
host_supported: true, | |||
} | |||
cc_library_shared { | |||
header_libs: ["wiringPi-headers"], | |||
name: "libwiringPi", | |||
srcs: [ | |||
"wiringPi/ads1115.c", | |||
"wiringPi/mcp23008.c", | |||
"wiringPi/mcp4802.c", | |||
"wiringPi/piHiPri.c", | |||
"wiringPi/sr595.c", | |||
"wiringPi/bmp180.c", | |||
"wiringPi/mcp23016.c", | |||
"wiringPi/piThread.c", | |||
"wiringPi/wiringPi.c", | |||
"wiringPi/mcp23017.c", | |||
"wiringPi/drcSerial.c", | |||
"wiringPi/mcp23s08.c", | |||
"wiringPi/wiringPiI2C.c", | |||
"wiringPi/ds18b20.c", | |||
"wiringPi/mcp23s17.c", | |||
"wiringPi/sn3218.c", | |||
"wiringPi/wiringPiSPI.c", | |||
"wiringPi/htu21d.c", | |||
"wiringPi/mcp3002.c", | |||
"wiringPi/softPwm.c", | |||
"wiringPi/wiringSerial.c", | |||
"wiringPi/max31855.c", | |||
"wiringPi/mcp3004.c", | |||
"wiringPi/pcf8574.c", | |||
"wiringPi/softServo.c", | |||
"wiringPi/wiringShift.c", | |||
"wiringPi/max5322.c", | |||
"wiringPi/mcp3422.c", | |||
"wiringPi/pcf8591.c", | |||
"wiringPi/softTone.c", | |||
"wiringPi/wpiExtensions.c", | |||
"wiringPi/khadas_vim1.c", | |||
"wiringPi/khadas_vim2.c", | |||
"wiringPi/khadas_vim3.c", | |||
"wiringPi/khadas_edge.c", | |||
], | |||
vendor_available: true, | |||
cflags: [ | |||
"-UNDEBUG", | |||
"-DANDROID", | |||
"-Wno-return-type", | |||
], | |||
host_ldlibs: [ | |||
"-ldl", | |||
"-llog", | |||
], | |||
} | |||
cc_library_shared { | |||
header_libs: ["wiringPi-headers"], | |||
name: "libwiringPiDev", | |||
srcs: [ | |||
"devLib/ds1302.c", | |||
"devLib/maxdetect.c", | |||
"devLib/piNes.c", | |||
"devLib/gertboard.c", | |||
"devLib/lcd128x64.c", | |||
"devLib/lcd.c", | |||
"devLib/piGlow.c", | |||
"devLib/scrollPhat.c", | |||
"devLib/piFace.c", | |||
], | |||
shared_libs: ["libwiringPi"], | |||
host_ldlibs: [ | |||
"-ldl", | |||
"-llog", | |||
], | |||
cflags: [ | |||
"-UNDEBUG", | |||
"-DANDROID", | |||
"-Wno-return-type", | |||
], | |||
} | |||
cc_binary { | |||
name: "gpio", | |||
srcs: [ | |||
"gpio/gpio.c", | |||
"gpio/readall.c", | |||
], | |||
header_libs: ["wiringPi-headers"], | |||
local_include_dirs: [ | |||
"devLib", | |||
], | |||
cflags: [ | |||
"-UNDEBUG", | |||
"-DANDROID", | |||
"-Wno-return-type", | |||
], | |||
host_ldlibs: ["-llog"], | |||
shared_libs: [ | |||
"libwiringPi", | |||
"libwiringPiDev", | |||
], | |||
} |
@@ -0,0 +1,3 @@ | |||
NDK_TOOLCHAIN_VERSION=clang | |||
APP_ABI := armeabi-v7a arm64-v8a | |||
APP_PLATFORM := android-21 |
@@ -40,7 +40,7 @@ | |||
********************************************************************************* | |||
*/ | |||
void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value) | |||
void myDigitalWrite (UNU struct wiringPiNodeStruct *node, int pin, int value) | |||
{ | |||
digitalWrite (pin + 16, value) ; | |||
} | |||
@@ -69,7 +69,7 @@ int myDigitalRead (struct wiringPiNodeStruct *node, int pin) | |||
********************************************************************************* | |||
*/ | |||
void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int pud) | |||
void myPullUpDnControl (UNU struct wiringPiNodeStruct *node, int pin, int pud) | |||
{ | |||
pullUpDnControl (pin + 16 + 8, pud) ; | |||
} | |||
@@ -192,79 +192,15 @@ static void checkDevTree (char *argv []) | |||
} | |||
} | |||
static void _doLoadUsage (char *argv []) | |||
static void UNU _doLoadUsage (char *argv []) | |||
{ | |||
fprintf (stderr, "Usage: %s load <spi/i2c> [I2C baudrate in Kb/sec]\n", argv [0]) ; | |||
exit (1) ; | |||
} | |||
static void doLoad (int argc, char *argv []) | |||
static void doLoad (int UNU argc, char *argv []) | |||
{ | |||
char *module1, *module2 ; | |||
char cmd [80] ; | |||
char *file1, *file2 ; | |||
char args1 [32], args2 [32] ; | |||
checkDevTree (argv) ; | |||
if (argc < 3) | |||
_doLoadUsage (argv) ; | |||
args1 [0] = args2 [0] = 0 ; | |||
/**/ if (strcasecmp (argv [2], "spi") == 0) | |||
{ | |||
module1 = "spidev" ; | |||
module2 = "spi_bcm2708" ; | |||
file1 = "/dev/spidev0.0" ; | |||
file2 = "/dev/spidev0.1" ; | |||
if (argc == 4) | |||
{ | |||
fprintf (stderr, "%s: Unable to set the buffer size now. Load aborted. Please see the man page.\n", argv [0]) ; | |||
exit (1) ; | |||
} | |||
else if (argc > 4) | |||
_doLoadUsage (argv) ; | |||
} | |||
else if (strcasecmp (argv [2], "i2c") == 0) | |||
{ | |||
module1 = "i2c_dev" ; | |||
module2 = "i2c_bcm2708" ; | |||
file1 = "/dev/i2c-0" ; | |||
file2 = "/dev/i2c-1" ; | |||
if (argc == 4) | |||
sprintf (args2, " baudrate=%d", atoi (argv [3]) * 1000) ; | |||
else if (argc > 4) | |||
_doLoadUsage (argv) ; | |||
} | |||
else | |||
_doLoadUsage (argv) ; | |||
if (findExecutable ("modprobe") == NULL) | |||
printf ("No found\n") ; | |||
if (!moduleLoaded (module1)) | |||
{ | |||
sprintf (cmd, "%s %s%s", findExecutable (MODPROBE), module1, args1) ; | |||
system (cmd) ; | |||
} | |||
if (!moduleLoaded (module2)) | |||
{ | |||
sprintf (cmd, "%s %s%s", findExecutable (MODPROBE), module2, args2) ; | |||
system (cmd) ; | |||
} | |||
if (!moduleLoaded (module2)) | |||
{ | |||
fprintf (stderr, "%s: Unable to load %s\n", argv [0], module2) ; | |||
exit (1) ; | |||
} | |||
sleep (1) ; // To let things get settled | |||
changeOwner (argv [0], file1) ; | |||
changeOwner (argv [0], file2) ; | |||
checkDevTree (argv) ; | |||
} | |||
@@ -274,46 +210,15 @@ static void doLoad (int argc, char *argv []) | |||
********************************************************************************* | |||
*/ | |||
static void _doUnLoadUsage (char *argv []) | |||
static void UNU _doUnLoadUsage (char *argv []) | |||
{ | |||
fprintf (stderr, "Usage: %s unload <spi/i2c>\n", argv [0]) ; | |||
exit (1) ; | |||
} | |||
static void doUnLoad (int argc, char *argv []) | |||
static void doUnLoad (int UNU argc, char *argv []) | |||
{ | |||
char *module1, *module2 ; | |||
char cmd [80] ; | |||
checkDevTree (argv) ; | |||
if (argc != 3) | |||
_doUnLoadUsage (argv) ; | |||
/**/ if (strcasecmp (argv [2], "spi") == 0) | |||
{ | |||
module1 = "spidev" ; | |||
module2 = "spi_bcm2708" ; | |||
} | |||
else if (strcasecmp (argv [2], "i2c") == 0) | |||
{ | |||
module1 = "i2c_dev" ; | |||
module2 = "i2c_bcm2708" ; | |||
} | |||
else | |||
_doUnLoadUsage (argv) ; | |||
if (moduleLoaded (module1)) | |||
{ | |||
sprintf (cmd, "%s %s", findExecutable (RMMOD), module1) ; | |||
system (cmd) ; | |||
} | |||
if (moduleLoaded (module2)) | |||
{ | |||
sprintf (cmd, "%s %s", findExecutable (RMMOD), module2) ; | |||
system (cmd) ; | |||
} | |||
checkDevTree (argv) ; | |||
} | |||
@@ -326,8 +231,17 @@ static void doUnLoad (int argc, char *argv []) | |||
static void doI2Cdetect (UNU int argc, char *argv []) | |||
{ | |||
int port = piGpioLayout () == 1 ? 0 : 1 ; | |||
int model, rev, mem, maker, overVolted; | |||
char *c, *command ; | |||
piBoardId(&model, &rev, &mem, &maker, &overVolted); | |||
switch (model) { | |||
case MODEL_KHADAS_EDGE: | |||
port = 2; | |||
break; | |||
default: | |||
break; | |||
} | |||
if ((c = findExecutable (I2CDETECT)) == NULL) | |||
{ | |||
fprintf (stderr, "%s: Unable to find i2cdetect command: %s\n", argv [0], strerror (errno)) ; | |||
@@ -776,7 +690,7 @@ static void doPadDrive (int argc, char *argv []) | |||
********************************************************************************* | |||
*/ | |||
static void doUsbP (int argc, char *argv []) | |||
static void doUsbP (int UNU argc, UNU char *argv []) | |||
{ | |||
/* | |||
int model, rev, mem, maker, overVolted ; | |||
@@ -118,6 +118,40 @@ static int physToWpi [64] = | |||
-1, -1, -1, -1, -1, -1, -1, -1, -1 | |||
} ; | |||
/*----------------------------------------------------------------------------*/ | |||
static int physToWpi_Edge [64] = | |||
{ | |||
-1, // 0 | |||
-1, -1, // 1, 2 | |||
-1, 13, | |||
-1, 12, | |||
-1, -1, | |||
-1, 9, | |||
-1, 8, | |||
-1, -1, | |||
-1, -1, | |||
-1, 0, | |||
25, 11, | |||
-1, 7, | |||
29, 2, | |||
17, 3, | |||
-1, -1, | |||
10, 6, | |||
14, 5, | |||
-1, 4, | |||
-1, 1, | |||
-1, -1, | |||
-1, -1, | |||
-1, -1, | |||
-1, -1, | |||
-1, -1, | |||
-1, -1, | |||
-1, -1, | |||
-1, -1, | |||
-1, -1, | |||
-1, -1, -1, -1, -1, -1, -1, -1, -1 | |||
} ; | |||
/*------------------------------------------------------------------------------------------*/ | |||
static const char *physNamesKhadasVim1[64] = { | |||
NULL, | |||
@@ -202,8 +236,38 @@ static const char *physNamesKhadasVim3[64] = { | |||
NULL,NULL,NULL, | |||
}; | |||
/*----------------------------------------------------------------------------*/ | |||
static const char *physNamesKhadasEdge [64] = | |||
{ | |||
NULL, | |||
" 5V", "GND(0V) ", | |||
" 5V", "SPI3_RXD/I2C0_SCK/GPIO1_C0", | |||
" HOST1_DM", "SPI3_TXD/I2C0_SDA/GPIO1_B7", | |||
" HOST1_DP", "GND(0V) ", | |||
" GND(0V)", "I2C2_SCL/GPIO2_A1 ", | |||
" MCU_TX", "I2C2_SDA/GPIO2_A0 ", | |||
" MCU_NRST", "3.3V ", | |||
" MCU_SWIM", "GND(0V) ", | |||
" GND(0V)", "I2S0_SCLK/GPIO3_D0 ", | |||
" ADC_IN2", "I2S_CLK/GPIO4_A0 ", | |||
" 1.8V", "I2S0_SDO0/GPIO3_D7 ", | |||
" ADC_IN3", "2S0_LRCK_TX/GPIO3_D2 ", | |||
" SPDIF/GPIO3_C0", "I2S0_SDI0/GPIO3_D3 ", | |||
" GND(0V", "GND(0V) ", | |||
" SPI3_CS/GPIO1_C2", "I2S0_SDI3SDO1/GPIO3_D6 ", | |||
"SPI3_CLK/GPIO1_C1", "2S0_SDI2SDO2/GPIO3_D5 ", | |||
" GND(0V)", "I2S0_SDI1SDO3/GPIO3_D4 ", | |||
" UART_RX", "I2S0_LRCK_RX/GPIO3_D1 ", | |||
" UART_TX", "MCU_PA1 ", | |||
" 3.3V", "GND(0V) ", | |||
static void readallPhysKhadas (int model, int rev, int physPin, const char *physNames[]) | |||
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, | |||
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, | |||
NULL,NULL,NULL, | |||
} ; | |||
static void readallPhysKhadas (int model, int UNU rev, int physPin, const char *physNames[]) | |||
{ | |||
int pin; | |||
@@ -287,16 +351,114 @@ static void readallPhysKhadas (int model, int rev, int physPin, const char *phys | |||
printf (" |\n") ; | |||
} | |||
static void readallPhysKhadas_edge (int model, int UNU rev, int physPin, const char *physNames[]) | |||
{ | |||
int pin; | |||
//GPIO, wPi pin number | |||
if ((physPinToGpio (physPin) == -1) && (physToWpi_Edge [physPin] == -1)) | |||
printf (" | | ") ; | |||
else if (physPinToGpio (physPin) != -1) | |||
printf (" | %3d | %3d", physPinToGpio (physPin), physToWpi_Edge [physPin]); | |||
else | |||
printf (" | | %3d", physToWpi_Edge [physPin]); | |||
// GPIO pin name | |||
printf (" | %s", physNames [physPin]); | |||
// GPIO pin mode, value, drive strength, pupd | |||
if ((physToWpi_Edge [physPin] == -1) || (physPinToGpio (physPin) == -1)){ | |||
printf (" | | | | ") ; | |||
} | |||
else { | |||
if (wpMode == MODE_GPIO) | |||
pin = physPinToGpio (physPin); | |||
else if(wpMode == MODE_PHYS) | |||
pin = physPin; | |||
else{ | |||
pin = physToWpi_Edge [physPin]; | |||
} | |||
printf (" | %4s", alts [getAlt (pin)]); | |||
printf (" | %d", digitalRead (pin)); | |||
switch(model) { | |||
case MODEL_KHADAS_VIM1: | |||
case MODEL_KHADAS_VIM2: | |||
case MODEL_KHADAS_VIM3: | |||
printf (" | | %5s", pupd[getPUPD(pin)]); | |||
break; | |||
case MODEL_KHADAS_EDGE: | |||
printf (" | | "); | |||
break; | |||
default: | |||
break; | |||
} | |||
} | |||
// Physical pin number | |||
printf (" | %2d", (physPin+1)/2); | |||
printf (" || %-2d", (physPin+41)/2); | |||
++physPin; | |||
// GPIO pin mode, value, drive strength, pupd | |||
if ((physToWpi_Edge [physPin] == -1) || (physPinToGpio (physPin) == -1)) | |||
printf (" | | | | "); | |||
else { | |||
if(wpMode == MODE_GPIO) | |||
pin = physPinToGpio (physPin); | |||
else if(wpMode == MODE_PHYS) | |||
pin = physPin; | |||
else | |||
pin = physToWpi_Edge [physPin]; | |||
switch(model){ | |||
case MODEL_KHADAS_VIM1: | |||
case MODEL_KHADAS_VIM2: | |||
case MODEL_KHADAS_VIM3: | |||
printf (" | %-5s | ", pupd[getPUPD(pin)]); | |||
break; | |||
case MODEL_KHADAS_EDGE: | |||
printf (" | | "); | |||
break; | |||
default: | |||
break; | |||
} | |||
printf (" | %d", digitalRead (pin)); | |||
printf (" | %-4s", alts [getAlt (pin)]); | |||
} | |||
// GPIO pin name | |||
printf (" | %-6s", physNames [physPin]); | |||
//GPIO, wPi pin number | |||
if ((physPinToGpio (physPin) == -1) && (physToWpi_Edge [physPin] == -1)) | |||
printf (" | | ") ; | |||
else if(physPinToGpio (physPin) != -1) | |||
printf (" | %-3d | %-3d", physToWpi_Edge [physPin], physPinToGpio (physPin)); | |||
else | |||
printf (" | %-3d | ", physToWpi_Edge [physPin]); | |||
printf (" |\n") ; | |||
} | |||
/*--------------------------------------------------------------------------------------*/ | |||
void ReadallKhadas(int model, int rev, const char *physNames[]) | |||
{ | |||
int pin; | |||
printf (" | GPIO | wPi | Name | Mode | V | DS | PU/PD | Physical | PU/PD | DS | V | Mode | Name | wPi | GPIO |\n"); | |||
printf (" +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+\n"); | |||
for (pin = 1 ; pin <= 40 ; pin += 2) | |||
readallPhysKhadas (model, rev, pin, physNames); | |||
printf (" +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+\n"); | |||
if(MODEL_KHADAS_EDGE == model){ | |||
printf (" | GPIO | wPi | Name | Mode | V | DS | PU/PD | Physical | PU/PD | DS | V | Mode | Name | wPi | GPIO |\n") ; | |||
printf (" +------+-----+-------------------+------+---+----+-------+----++----+-------+----+---+------+----------------------------+-----+------+\n") ; | |||
for (pin = 1 ; pin <= 40 ; pin += 2) | |||
readallPhysKhadas_edge (model, rev, pin, physNames) ; | |||
printf (" +------+-----+-------------------+------+---+----+-------+----++----+-------+----+---+------+----------------------------+-----+------+\n") ; | |||
} | |||
else{ | |||
printf (" | GPIO | wPi | Name | Mode | V | DS | PU/PD | Physical | PU/PD | DS | V | Mode | Name | wPi | GPIO |\n"); | |||
printf (" +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+\n"); | |||
for (pin = 1 ; pin <= 40 ; pin += 2) | |||
readallPhysKhadas (model, rev, pin, physNames); | |||
printf (" +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+\n"); | |||
} | |||
} | |||
/*--------------------------------------------------------------------------------------*/ | |||
@@ -334,6 +496,10 @@ void doReadall(void) | |||
printf (" +------+-----+----------+------+---+----+---- Model KDADAS-VIM3---+----+---+------+----------+-----+------+\n") ; | |||
physNames = physNamesKhadasVim3; | |||
break; | |||
case MODEL_KHADAS_EDGE: | |||
printf (" +------+-----+-------------------+------+---+----+--- Model KHADAS-EDGE ---+----+---+------+----------------------------+-----+------+\n"); | |||
physNames = physNamesKhadasEdge; | |||
break; | |||
default: | |||
printf ("Oops - unable to determine board type... model: %d\n", model); | |||
return; | |||
@@ -65,7 +65,8 @@ SRC = wiringPi.c \ | |||
wpiExtensions.c \ | |||
khadas_vim1.c \ | |||
khadas_vim2.c \ | |||
khadas_vim3.c | |||
khadas_vim3.c \ | |||
khadas_edge.c | |||
HEADERS = $(shell ls *.h) | |||
@@ -135,6 +136,7 @@ depend: | |||
khadas_vim1.o : wiringPi.h khadas_vim1.h | |||
khadas_vim2.o : wiringPi.h khadas_vim2.h | |||
khadas_vim3.o : wiringPi.h khadas_vim3.h | |||
khadas_edge.o : wiringPi.h khadas_edge.h | |||
wiringPi.o: softPwm.h softTone.h wiringPi.h ../version.h | |||
wiringSerial.o: wiringSerial.h | |||
@@ -116,6 +116,10 @@ | |||
#define CONFIG_DEFAULT (0x8583) // From the datasheet | |||
#if defined ANDROID | |||
#define __bswap_16(x) bswap_16(x) | |||
#define __bswap_32(x) bswap_32(x) | |||
#endif | |||
static const uint16_t dataRates [8] = | |||
{ | |||
@@ -0,0 +1,786 @@ | |||
/*----------------------------------------------------------------------------*/ | |||
// | |||
// | |||
// WiringPi KHADAS-EDGE Board Control file (ROCKCHIP 64Bits Platform) | |||
// | |||
// | |||
/*----------------------------------------------------------------------------*/ | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <stdint.h> | |||
#include <unistd.h> | |||
#include <errno.h> | |||
#include <string.h> | |||
#include <fcntl.h> | |||
#include <sys/ioctl.h> | |||
#include <asm/ioctl.h> | |||
#include <sys/mman.h> | |||
#include <sys/utsname.h> | |||
/*----------------------------------------------------------------------------*/ | |||
#include "softPwm.h" | |||
#include "softTone.h" | |||
/*----------------------------------------------------------------------------*/ | |||
#include "wiringPi.h" | |||
#include "khadas_edge.h" | |||
/*----------------------------------------------------------------------------*/ | |||
// wiringPi gpio map define | |||
/*----------------------------------------------------------------------------*/ | |||
// Revision 2: | |||
static const int pinToGpio[64] = { | |||
// wiringPi number to native gpio number | |||
120, 121, // 0 | 1 : GPIO3_D0 | GPIO3_D1 | |||
122, 123, // 2 | 3 : GPIO3_D2 | GPIO3_D3 | |||
124, 125, // 4 | 5 : GPIO3_D4 | GPIO3_D5 | |||
126, 127, // 6 | 7 : GPIO3_D6 | GPIO3_D7 | |||
64, 65, // 8 | 9 : (GPIO2_A0) I2C2_SDA | I2C2_SCL (GPIO2_A1) | |||
50, 128, // 10 | 11 : (GPIO1_C2) SPI3_CS | I2S_CLK (GPIO4_A0) | |||
47, 48, // 12 | 13 : (GPIO1_B7) SPI3_TXD | SPI3_RXD (GPIO1_C0) | |||
49, -1, // 14 | 15 : (GPIO1_C1) SPI3_CLK | UART_TX | |||
-1, 112, // 16 | 17 : UART_RX | SPDIF_TX (GPIO3_C0) | |||
-1, -1, // 18 | 19 : | |||
-1, -1, // 20 | 21 : | |||
-1, -1, // 22 | 23 : | |||
-1, -1, // 24 | 25 : | ADC_IN2 | |||
-1, -1, // 26 | 27 : | |||
-1, -1, // 28 | 29 : | ADC_IN3 | |||
-1, -1, // 30 | 31 : | |||
// Padding: | |||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 32...47 | |||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 48...63 | |||
}; | |||
static const int phyToGpio[64] = { | |||
// physical header pin number to native gpio number | |||
-1, // 0 | |||
-1, -1, // 1 | 21 : 5V | GND | |||
-1, 48, // 2 | 22 : 5V | SPI3_RXD (GPIO1_C0) | |||
-1, 47, // 3 | 23 : HOST1_DM | SPI3_TXD (GPIO1_B7) | |||
-1, -1, // 4 | 24 : HOST1_DP | GND | |||
-1, 65, // 5 | 25 : GND | I2C2_SCL (GPIO2_A1) | |||
-1, 64, // 6 | 26 : 3.3V | I2C2_SDA (GPIO2_A0) | |||
-1, -1, // 7 | 27 : MCU_NRST | 3.3V | |||
-1, -1, // 8 | 28 : MCU_SWIM | GND | |||
-1,120, // 9 | 29 : GND | I2S0_SCLK (GPIO3_D0) | |||
-1,128, // 10 | 30 : ADC_IN2 | I2S_CLK (GPIO4_A0) | |||
-1,127, // 11 | 31 : 1.8V | I2S0_SDO0 (GPIO3_D7) | |||
-1,122, // 12 | 32 : ADC_IN3 | I2S0_LRCK_TX (GPIO3_D2) | |||
112,123, // 13 | 33 : (GPIO3_C0) SPDIF_TX | I2S0_SDI0 (GPIO3_D3) | |||
-1, -1, // 14 | 34 : GND | GND | |||
50,126, // 15 | 35 : (GPIO1_C2) SPI3_CS | I2S0_SDI3SDO1 (GPIO3_D6) | |||
49,125, // 16 | 36 : (GPIO1_C1) SPI3_CLK | I2S0_SDI2SDO2 (GPIO3_D5) | |||
-1,124, // 17 | 37 : GND | I2S0_SDI1SDO3 (GPIO3_D4) | |||
-1,121, // 18 | 38 : UART_RX | I2S0_LRCK_RX (GPIO3_D1) | |||
-1, -1, // 19 | 39 : UART_TX | MCU_PA1 | |||
-1, -1, // 20 | 40 : 3.3V | GND | |||
// Not used | |||
-1, -1, -1, -1, -1, -1, -1, -1, // 41...48 | |||
-1, -1, -1, -1, -1, -1, -1, -1, // 49...56 | |||
-1, -1, -1, -1, -1, -1, -1 // 57...63 | |||
}; | |||
/*----------------------------------------------------------------------------*/ | |||
// | |||
// Global variable define | |||
// | |||
/*----------------------------------------------------------------------------*/ | |||
/* ADC file descriptor */ | |||
static int adcFds[2]; | |||
/* GPIO mmap control. Actual GPIO bank number. */ | |||
static volatile uint32_t *gpio[5]; | |||
/* GRF(General Register Files) base addresses to control GPIO modes */ | |||
static volatile uint32_t *grf[2]; | |||
/* CRU(Clock & Reset Unit) base addresses to control CLK mode */ | |||
static volatile uint32_t *cru[2]; | |||
/* wiringPi Global library */ | |||
static struct libkhadas *lib = NULL; | |||
/*----------------------------------------------------------------------------*/ | |||
// Function prototype define | |||
/*----------------------------------------------------------------------------*/ | |||
static int gpioToShiftReg (int pin); | |||
static int gpioToShiftGReg (int pin); | |||
static void setClkState (int pin, int state); | |||
static void setIomuxMode (int pin, int mode); | |||
/*----------------------------------------------------------------------------*/ | |||
// wiringPi core function | |||
/*----------------------------------------------------------------------------*/ | |||
static int _getModeToGpio (int mode, int pin); | |||
static void _pinMode (int pin, int mode); | |||
static int _getAlt (int pin); | |||
static void _pullUpDnControl (int pin, int pud); | |||
static int _digitalRead (int pin); | |||
static void _digitalWrite (int pin, int value); | |||
static int _analogRead (int pin); | |||
static void _digitalWriteByte (const int value); | |||
static unsigned int _digitalReadByte (void); | |||
/*----------------------------------------------------------------------------*/ | |||
// board init function | |||
/*----------------------------------------------------------------------------*/ | |||
static void init_gpio_mmap (void); | |||
static void init_adc_fds (void); | |||
void init_khadas_edge (struct libkhadas *libwiring); | |||
/*----------------------------------------------------------------------------*/ | |||
/*----------------------------------------------------------------------------*/ | |||
// | |||
// offset to the GPIO bit | |||
// | |||
/*----------------------------------------------------------------------------*/ | |||
static int gpioToShiftReg (int pin) | |||
{ | |||
return pin % 32; | |||
} | |||
/*----------------------------------------------------------------------------*/ | |||
// | |||
// offset to the GPIO bit at GRF address | |||
// | |||
/*----------------------------------------------------------------------------*/ | |||
static int gpioToShiftGReg (int pin) | |||
{ | |||
return pin % 8; | |||
} | |||
/*----------------------------------------------------------------------------*/ | |||
static int _getModeToGpio (int mode, int pin) | |||
{ | |||
if (pin > 255) | |||
return msg(MSG_ERR, "%s : Invalid pin number %d\n", __func__, pin); | |||
switch (mode) { | |||
/* Native gpio number */ | |||
case MODE_GPIO: | |||
return pin; | |||
/* Native gpio number for sysfs */ | |||
case MODE_GPIO_SYS: | |||
return lib->sysFds[pin] != -1 ? pin : -1; | |||
/* wiringPi number */ | |||
case MODE_PINS: | |||
return pin < 64 ? pinToGpio[pin] : -1; | |||
/* header pin number */ | |||
case MODE_PHYS: | |||
return pin < 64 ? phyToGpio[pin] : -1; | |||
default : | |||
msg(MSG_WARN, "%s : Unknown Mode %d\n", __func__, mode); | |||
return -1; | |||
} | |||
} | |||
/*----------------------------------------------------------------------------*/ | |||
// | |||
// set GPIO clock state | |||
// | |||
/*----------------------------------------------------------------------------*/ | |||
static void setClkState (int pin, int state) | |||
{ | |||
uint32_t target = 0; | |||
uint8_t bank = pin / 32; | |||
uint8_t shift = bank < 2 ? bank + 2 : bank + 1; | |||
target |= (1 << (shift + 16)); | |||
switch (state) { | |||
case EDGE_CLK_ENABLE: | |||
if (bank < 2) { | |||
target |= *(cru[0] + (EDGE_PMUCRU_GPIO_CLK_OFFSET >> 2)); | |||
target &= ~(1 << shift); | |||
*(cru[0] + (EDGE_PMUCRU_GPIO_CLK_OFFSET >> 2)) = target; | |||
} else { | |||
target |= *(cru[1] + (EDGE_CRU_GPIO_CLK_OFFSET >> 2)); | |||
target &= ~(1 << shift); | |||
*(cru[1] + (EDGE_CRU_GPIO_CLK_OFFSET >> 2)) = target; | |||
} | |||
break; | |||
case EDGE_CLK_DISABLE: | |||
if (bank < 2) { | |||
target |= *(cru[0] + (EDGE_PMUCRU_GPIO_CLK_OFFSET >> 2)); | |||
target |= (1 << shift); | |||
*(cru[0] + (EDGE_PMUCRU_GPIO_CLK_OFFSET >> 2)) = target; | |||
} else { | |||
target |= *(cru[1] + (EDGE_CRU_GPIO_CLK_OFFSET >> 2)); | |||
target |= (1 << shift); | |||
*(cru[1] + (EDGE_CRU_GPIO_CLK_OFFSET >> 2)) = target; | |||
} | |||
break; | |||
default: | |||
break; | |||
} | |||
} | |||
/*----------------------------------------------------------------------------*/ | |||
// | |||
// set IOMUX mode | |||
// | |||
/*----------------------------------------------------------------------------*/ | |||
static void setIomuxMode (int pin, int mode) | |||
{ | |||
uint32_t offset, target; | |||
uint8_t bank, group; | |||
bank = pin / 32; | |||
group = (pin - bank * 32) / 8; | |||
offset = 0x10 * (bank > 1 ? bank - 2 : bank) + 0x4 * group; | |||
target = 0; | |||
target |= (1 << (gpioToShiftGReg(pin) * 2 + 17)); | |||
target |= (1 << (gpioToShiftGReg(pin) * 2 + 16)); | |||
switch (mode) { | |||
case EDGE_FUNC_GPIO: | |||
// Common IOMUX Funtion 1 : GPIO (0b00) | |||
if (bank < 2) { | |||
offset += EDGE_PMUGRF_IOMUX_OFFSET; | |||
target |= *(grf[0] + (offset >> 2)); | |||
target &= ~(1 << (gpioToShiftGReg(pin) * 2 + 1)); | |||
target &= ~(1 << (gpioToShiftGReg(pin) * 2)); | |||
*(grf[0] + (offset >> 2)) = target; | |||
} else { | |||
offset += EDGE_GRF_IOMUX_OFFSET; | |||
target |= *(grf[1] + (offset >> 2)); | |||
target &= ~(1 << (gpioToShiftGReg(pin) * 2 + 1)); | |||
target &= ~(1 << (gpioToShiftGReg(pin) * 2)); | |||
*(grf[1] + (offset >> 2)) = target; | |||
} | |||
break; | |||
default: | |||
break; | |||
} | |||
} | |||
/*----------------------------------------------------------------------------*/ | |||
static void _pinMode (int pin, int mode) | |||
{ | |||
int origPin, bank; | |||
unsigned long UNU flags; | |||
if (lib->mode == MODE_GPIO_SYS) | |||
return; | |||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0) | |||
return; | |||
origPin = pin; | |||
bank = pin / 32; | |||
softPwmStop (origPin); | |||
softToneStop(origPin); | |||
setClkState (pin, EDGE_CLK_ENABLE); | |||
setIomuxMode(pin, EDGE_FUNC_GPIO); | |||
switch (mode) { | |||
case INPUT: | |||
*(gpio[bank] + (EDGE_GPIO_CON_OFFSET >> 2)) &= ~(1 << gpioToShiftReg(pin)); | |||
break; | |||
case OUTPUT: | |||
*(gpio[bank] + (EDGE_GPIO_CON_OFFSET >> 2)) |= (1 << gpioToShiftReg(pin)); | |||
break; | |||
case SOFT_PWM_OUTPUT: | |||
softPwmCreate (origPin, 0, 100); | |||
break; | |||
case SOFT_TONE_OUTPUT: | |||
softToneCreate (origPin); | |||
break; | |||
default: | |||
msg(MSG_WARN, "%s : Unknown Mode %d\n", __func__, mode); | |||
return; | |||
} | |||
setClkState (pin, EDGE_CLK_DISABLE); | |||
} | |||
/*----------------------------------------------------------------------------*/ | |||
static int _getAlt (int pin) | |||
{ | |||
uint32_t offset; | |||
uint8_t bank, group, shift; | |||
uint8_t ret = 0; | |||
if (lib->mode == MODE_GPIO_SYS) | |||
return -1; | |||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0) | |||
return -1; | |||
bank = pin / 32; | |||
group = (pin - bank * 32) / 8; | |||
offset = 0x10 * (bank > 1 ? bank - 2 : bank) + 0x4 * group; | |||
shift = gpioToShiftGReg(pin) << 1; | |||
setClkState(pin, EDGE_CLK_ENABLE); | |||
// Check if the pin is GPIO mode on GRF register | |||
if (bank < 2) { | |||
offset += EDGE_PMUGRF_IOMUX_OFFSET; | |||
ret = (*(grf[0] + (offset >> 2)) >> shift) & 0b11; | |||
} else { | |||
offset += EDGE_GRF_IOMUX_OFFSET; | |||
ret = (*(grf[1] + (offset >> 2)) >> shift) & 0b11; | |||
} | |||
// If it is GPIO mode, check it's direction | |||
if (ret == 0) | |||
ret = *(gpio[bank] + (EDGE_GPIO_CON_OFFSET >> 2)) & (1 << gpioToShiftReg(pin)) ? 1 : 0; | |||
else { | |||
// ALT1 is GPIO mode(0b00) on this SoC | |||
ret++; | |||
} | |||
setClkState(pin, EDGE_CLK_DISABLE); | |||
return ret; | |||
} | |||
/*----------------------------------------------------------------------------*/ | |||
static void _pullUpDnControl (int pin, int pud) | |||
{ | |||
uint32_t offset, target; | |||
uint8_t bank, group; | |||
if (lib->mode == MODE_GPIO_SYS) | |||
return; | |||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0) | |||
return; | |||
bank = pin / 32; | |||
group = (pin - bank * 32) / 8; | |||
offset = 0x10 * (bank > 1 ? bank - 2 : bank) + 0x4 * group; | |||
target = 0; | |||
target |= (1 << (gpioToShiftGReg(pin) * 2 + 17)); | |||
target |= (1 << (gpioToShiftGReg(pin) * 2 + 16)); | |||
setClkState(pin, EDGE_CLK_ENABLE); | |||
switch (pud) { | |||
case PUD_UP: | |||
if (bank < 2) { | |||
offset += EDGE_PMUGRF_PUPD_OFFSET; | |||
target |= *(grf[0] + (offset >> 2)); | |||
target &= ~(1 << (gpioToShiftGReg(pin) * 2 + 1)); | |||
target |= (1 << (gpioToShiftGReg(pin) * 2)); | |||
*(grf[0] + (offset >> 2)) = target; | |||
} else { | |||
offset += EDGE_GRF_PUPD_OFFSET; | |||
target |= *(grf[1] + (offset >> 2)); | |||
if (bank == 2 && group >= 2) { | |||
target |= (1 << (gpioToShiftGReg(pin) * 2 + 1)); | |||
target |= (1 << (gpioToShiftGReg(pin) * 2)); | |||
} else { | |||
target &= ~(1 << (gpioToShiftGReg(pin) * 2 + 1)); | |||
target |= (1 << (gpioToShiftGReg(pin) * 2)); | |||
} | |||
*(grf[1] + (offset >> 2)) = target; | |||
} | |||
break; | |||
case PUD_DOWN: | |||
if (bank < 2) { | |||
offset += EDGE_PMUGRF_PUPD_OFFSET; | |||
target |= *(grf[0] + (offset >> 2)); | |||
target |= (1 << (gpioToShiftGReg(pin) * 2 + 1)); | |||
target &= ~(1 << (gpioToShiftGReg(pin) * 2)); | |||
*(grf[0] + (offset >> 2)) = target; | |||
} else { | |||
offset += EDGE_GRF_PUPD_OFFSET; | |||
target |= *(grf[1] + (offset >> 2)); | |||
if (bank == 2 && group >= 2) { | |||
target &= ~(1 << (gpioToShiftGReg(pin) * 2 + 1)); | |||
target |= (1 << (gpioToShiftGReg(pin) * 2)); | |||
} else { | |||
target |= (1 << (gpioToShiftGReg(pin) * 2 + 1)); | |||
target &= ~(1 << (gpioToShiftGReg(pin) * 2)); | |||
} | |||
*(grf[1] + (offset >> 2)) = target; | |||
} | |||
break; | |||
case PUD_OFF: | |||
if (bank < 2) { | |||
offset += EDGE_PMUGRF_PUPD_OFFSET; | |||
target |= *(grf[0] + (offset >> 2)); | |||
target &= ~(1 << (gpioToShiftGReg(pin) * 2 + 1)); | |||
target &= ~(1 << (gpioToShiftGReg(pin) * 2)); | |||
*(grf[0] + (offset >> 2)) = target; | |||
} else { | |||
offset += EDGE_GRF_PUPD_OFFSET; | |||
target |= *(grf[1] + (offset >> 2)); | |||
target &= ~(1 << (gpioToShiftGReg(pin) * 2 + 1)); | |||
target &= ~(1 << (gpioToShiftGReg(pin) * 2)); | |||
*(grf[1] + (offset >> 2)) = target; | |||
} | |||
break; | |||
default: | |||
break; | |||
} | |||
setClkState(pin, EDGE_CLK_DISABLE); | |||
} | |||
/*----------------------------------------------------------------------------*/ | |||
static int _digitalRead (int pin) | |||
{ | |||
int bank, ret; | |||
char c; | |||
if (lib->mode == MODE_GPIO_SYS) { | |||
if (lib->sysFds[pin] == -1) | |||
return -1; | |||
lseek (lib->sysFds[pin], 0L, SEEK_SET); | |||
if (read(lib->sysFds[pin], &c, 1) < 0) { | |||
msg(MSG_WARN, "%s: Failed with reading from sysfs GPIO node. \n", __func__); | |||
return -1; | |||
} | |||
return (c == '0') ? LOW : HIGH; | |||
} | |||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0) | |||
return -1; | |||
bank = pin / 32; | |||
setClkState(pin, EDGE_CLK_ENABLE); | |||
ret = *(gpio[bank] + (EDGE_GPIO_GET_OFFSET >> 2)) & (1 << gpioToShiftReg(pin)) ? HIGH : LOW; | |||
setClkState(pin, EDGE_CLK_DISABLE); | |||
return ret; | |||
} | |||
/*----------------------------------------------------------------------------*/ | |||
static void _digitalWrite (int pin, int value) | |||
{ | |||
int bank; | |||
if (lib->mode == MODE_GPIO_SYS) { | |||
if (lib->sysFds[pin] != -1) { | |||
if (value == LOW) { | |||
if (write (lib->sysFds[pin], "0\n", 2) < 0) | |||
msg(MSG_ERR, | |||
"%s : %s\nEdit direction file to output mode for\n\t/sys/class/gpio/gpio%d/direction\n", | |||
__func__, strerror(errno), pin + EDGE_GPIO_PIN_BASE); | |||
} else { | |||
if (write (lib->sysFds[pin], "1\n", 2) < 0) | |||
msg(MSG_ERR, | |||
"%s : %s\nEdit direction file to output mode for\n\t/sys/class/gpio/gpio%d/direction\n", | |||
__func__, strerror(errno), pin + EDGE_GPIO_PIN_BASE); | |||
} | |||
} | |||
return; | |||
} | |||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0) | |||
return; | |||
bank = pin / 32; | |||
setClkState(pin, EDGE_CLK_ENABLE); | |||
switch (value) { | |||
case LOW: | |||
*(gpio[bank] + (EDGE_GPIO_SET_OFFSET >> 2)) &= ~(1 << gpioToShiftReg(pin)); | |||
break; | |||
case HIGH: | |||
*(gpio[bank] + (EDGE_GPIO_SET_OFFSET >> 2)) |= (1 << gpioToShiftReg(pin)); | |||
break; | |||
default: | |||
break; | |||
} | |||
setClkState(pin, EDGE_CLK_DISABLE); | |||
} | |||
/*----------------------------------------------------------------------------*/ | |||
static int _analogRead (int pin) | |||
{ | |||
char value[5] = {0,}; | |||
if (lib->mode == MODE_GPIO_SYS) | |||
return -1; | |||
/* wiringPi ADC number = pin 25, pin 29 */ | |||
switch (pin) { | |||
#if defined(ARDUINO) | |||
/* To work with physical analog channel numbering */ | |||
case 1: case 25: | |||
pin = 0; | |||
break; | |||
case 0: case 29: | |||
pin = 1; | |||
break; | |||
#else | |||
case 0: case 25: | |||
pin = 0; | |||
break; | |||
case 1: case 29: | |||
pin = 1; | |||
break; | |||
#endif | |||
default: | |||
return 0; | |||
} | |||
if (adcFds [pin] == -1) | |||
return 0; | |||
lseek(adcFds [pin], 0L, SEEK_SET); | |||
if (read(adcFds [pin], &value[0], 4) < 0) { | |||
msg(MSG_WARN, "%s: Error occurs when it reads from ADC file descriptor. \n", __func__); | |||
return -1; | |||
} | |||
return atoi(value); | |||
} | |||
/*----------------------------------------------------------------------------*/ | |||
static void _digitalWriteByte (const int value) | |||
{ | |||
union reg_bitfield gpioBits3; | |||
if (lib->mode == MODE_GPIO_SYS) { | |||
return; | |||
} | |||
// Enable clock for GPIO 1 bank | |||
setClkState(96, EDGE_CLK_ENABLE); | |||
/* Read data register */ | |||
gpioBits3.wvalue = *(gpio[3] + (EDGE_GPIO_GET_OFFSET >> 2)); | |||
/* Wiring PI GPIO0 = EDGE GPIO3_D.0 */ | |||
gpioBits3.bits.bit0 = (value & 0x01); | |||
/* Wiring PI GPIO1 = EDGE GPIO3_D.1 */ | |||
gpioBits3.bits.bit1 = (value & 0x02); | |||
/* Wiring PI GPIO2 = EDGE GPIO3_D.2 */ | |||
gpioBits3.bits.bit2 = (value & 0x04); | |||
/* Wiring PI GPIO3 = EDGE GPIO3_D.3 */ | |||
gpioBits3.bits.bit3 = (value & 0x08); | |||
/* Wiring PI GPIO4 = EDGE GPIO3_D.4 */ | |||
gpioBits3.bits.bit4 = (value & 0x10); | |||
/* Wiring PI GPIO5 = EDGE GPIO3_D.5 */ | |||
gpioBits3.bits.bit5 = (value & 0x20); | |||
/* Wiring PI GPIO6 = EDGE GPIO3_D.6 */ | |||
gpioBits3.bits.bit6 = (value & 0x40); | |||
/* Wiring PI GPIO7 = EDGE GPIO3_D.7 */ | |||
gpioBits3.bits.bit7 = (value & 0x80); | |||
/* Update data register */ | |||
*(gpio[3] + (EDGE_GPIO_SET_OFFSET >> 2)) = gpioBits3.wvalue; | |||
setClkState(96, EDGE_CLK_DISABLE); | |||
} | |||
/*----------------------------------------------------------------------------*/ | |||
static unsigned int _digitalReadByte (void) | |||
{ | |||
union reg_bitfield gpioBits3; | |||
unsigned int value = 0; | |||
if (lib->mode == MODE_GPIO_SYS) { | |||
return -1; | |||
} | |||
// Enable clock for GPIO 1 bank | |||
setClkState(96, EDGE_CLK_ENABLE); | |||
/* Read data register */ | |||
gpioBits3.wvalue = *(gpio[3] + (EDGE_GPIO_GET_OFFSET >> 2)); | |||
setClkState(96, EDGE_CLK_DISABLE); | |||
/* Wiring PI GPIO0 = EDGE GPIO3_D.0 */ | |||
if (gpioBits3.bits.bit0) | |||
value |= 0x01; | |||
/* Wiring PI GPIO1 = EDGE GPIO3_D.1 */ | |||
if (gpioBits3.bits.bit1) | |||
value |= 0x02; | |||
/* Wiring PI GPIO2 = EDGE GPIO3_D.2 */ | |||
if (gpioBits3.bits.bit2) | |||
value |= 0x04; | |||
/* Wiring PI GPIO3 = EDGE GPIO3_D.3 */ | |||
if (gpioBits3.bits.bit3) | |||
value |= 0x08; | |||
/* Wiring PI GPIO4 = EDGE GPIO3_D.4 */ | |||
if (gpioBits3.bits.bit4) | |||
value |= 0x10; | |||
/* Wiring PI GPIO5 = EDGE GPIO3_D.5 */ | |||
if (gpioBits3.bits.bit5) | |||
value |= 0x20; | |||
/* Wiring PI GPIO6 = EDGE GPIO3_D.6 */ | |||
if (gpioBits3.bits.bit6) | |||
value |= 0x40; | |||
/* Wiring PI GPIO7 = EDGE GPIO3_D.7 */ | |||
if (gpioBits3.bits.bit7) | |||
value |= 0x80; | |||
return value; | |||
} | |||
/*----------------------------------------------------------------------------*/ | |||
static void init_gpio_mmap (void) | |||
{ | |||
int fd = -1; | |||
void *mapped_cru[2], *mapped_grf[2], *mapped_gpio[5]; | |||
/* GPIO mmap setup */ | |||
if (!getuid()) { | |||
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0) | |||
msg (MSG_ERR, | |||
"wiringPiSetup: Unable to open /dev/mem: %s\n", | |||
strerror (errno)); | |||
} else { | |||
if (access("/dev/gpiomem",0) == 0) { | |||
if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0) | |||
msg (MSG_ERR, | |||
"wiringPiSetup: Unable to open /dev/gpiomem: %s\n", | |||
strerror (errno)); | |||
} else | |||
msg (MSG_ERR, | |||
"wiringPiSetup: /dev/gpiomem doesn't exist. Please try again with sudo.\n"); | |||
} | |||
if (fd < 0) { | |||
msg(MSG_ERR, "wiringPiSetup: Cannot open memory area for GPIO use. \n"); | |||
} else { | |||
// GPIO{0, 1} | |||
//#define EDGE_PMUCRU_BASE 0xFF750000 | |||
mapped_cru[0] = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, EDGE_PMUCRU_BASE); | |||
// GPIO{2, 3, 4} | |||
//#define EDGE_CRU_BASE 0xFF760000 | |||
mapped_cru[1] = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, EDGE_CRU_BASE); | |||
// GPIO{0, 1} | |||
//#define EDGE_PMU_BASE 0xFF320000 | |||
mapped_grf[0] = mmap(0, EDGE_GRF_BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, EDGE_PMUGRF_BASE); | |||
// GPIO{2, 3, 4} | |||
//#define EDGE_GRF_BASE 0xFF770000 | |||
mapped_grf[1] = mmap(0, EDGE_GRF_BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, EDGE_GRF_BASE); | |||
// GPIO1_A. 0,1,2,3,4,7 | |||
// GPIO1_B. 0,1,2,3,4,5 | |||
// GPIO1_C. 2,4,5,6 | |||
// GPIO1_D. 0 | |||
//#define EDGE_GPIO1_BASE 0xFF730000 | |||
mapped_gpio[1] = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, EDGE_GPIO_1_BASE); | |||
// GPIO2_C. 0_B,1_B | |||
//#define EDGE_GPIO2_BASE 0xFF780000 | |||
mapped_gpio[2] = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, EDGE_GPIO_2_BASE); | |||
// GPIO4_C. 5,6 | |||
// GPIO4_D. 0,4,5,6 | |||
//#define EDGE_GPIO4_BASE 0xFF790000 | |||
mapped_gpio[4] = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, EDGE_GPIO_4_BASE); | |||
// Reserved | |||
mapped_gpio[0] = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, EDGE_GPIO_0_BASE); | |||
mapped_gpio[3] = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, EDGE_GPIO_3_BASE); | |||
if ((mapped_cru[0] == MAP_FAILED) || (mapped_cru[1] == MAP_FAILED)) { | |||
msg (MSG_ERR, | |||
"wiringPiSetup: mmap (CRU) failed: %s\n", | |||
strerror (errno)); | |||
} else { | |||
cru[0] = (uint32_t *) mapped_cru[0]; | |||
cru[1] = (uint32_t *) mapped_cru[1]; | |||
} | |||
if ((mapped_grf[0] == MAP_FAILED) || (mapped_grf[1] == MAP_FAILED)) { | |||
msg (MSG_ERR, | |||
"wiringPiSetup: mmap (GRF) failed: %s\n", | |||
strerror (errno)); | |||
} else { | |||
grf[0] = (uint32_t *) mapped_grf[0]; | |||
grf[1] = (uint32_t *) mapped_grf[1]; | |||
} | |||
if ( (mapped_gpio[0] == MAP_FAILED) || | |||
(mapped_gpio[1] == MAP_FAILED) || | |||
(mapped_gpio[2] == MAP_FAILED) || | |||
(mapped_gpio[3] == MAP_FAILED) || | |||
(mapped_gpio[4] == MAP_FAILED)) { | |||
msg (MSG_ERR, | |||
"wiringPiSetup: mmap (GPIO) failed: %s\n", | |||
strerror (errno)); | |||
} else { | |||
gpio[0] = (uint32_t *) mapped_gpio[0]; | |||
gpio[1] = (uint32_t *) mapped_gpio[1]; | |||
gpio[2] = (uint32_t *) mapped_gpio[2]; | |||
gpio[3] = (uint32_t *) mapped_gpio[3]; | |||
gpio[4] = (uint32_t *) mapped_gpio[4]; | |||
} | |||
} | |||
} | |||
/*----------------------------------------------------------------------------*/ | |||
static void init_adc_fds (void) | |||
{ | |||
const char *AIN0_NODE, *AIN1_NODE; | |||
struct utsname uname_buf; | |||
/* ADC node setup */ | |||
uname(&uname_buf); | |||
AIN0_NODE = "/sys/devices/platform/ff100000.saradc/iio:device0/in_voltage2_raw"; | |||
AIN1_NODE = "/sys/devices/platform/ff100000.saradc/iio:device0/in_voltage3_raw"; | |||
adcFds[0] = open(AIN0_NODE, O_RDONLY); | |||
adcFds[1] = open(AIN1_NODE, O_RDONLY); | |||
} | |||
/*----------------------------------------------------------------------------*/ | |||
void init_khadas_edge (struct libkhadas *libwiring) | |||
{ | |||
init_gpio_mmap(); | |||
init_adc_fds(); | |||
/* wiringPi Core function initialize */ | |||
libwiring->getModeToGpio = _getModeToGpio; | |||
libwiring->pinMode = _pinMode; | |||
libwiring->getAlt = _getAlt; | |||
libwiring->pullUpDnControl = _pullUpDnControl; | |||
libwiring->digitalRead = _digitalRead; | |||
libwiring->digitalWrite = _digitalWrite; | |||
libwiring->analogRead = _analogRead; | |||
libwiring->digitalWriteByte = _digitalWriteByte; | |||
libwiring->digitalReadByte = _digitalReadByte; | |||
/* specify pin base number */ | |||
libwiring->pinBase = EDGE_GPIO_PIN_BASE; | |||
/* global variable setup */ | |||
lib = libwiring; | |||
} | |||
/*----------------------------------------------------------------------------*/ | |||
/*----------------------------------------------------------------------------*/ |
@@ -0,0 +1,80 @@ | |||
/*----------------------------------------------------------------------------*/ | |||
/* | |||
WiringPi KHADAS-EDGE Board Header file | |||
*/ | |||
/*----------------------------------------------------------------------------*/ | |||
#ifndef __KHADAS_EDGE_H__ | |||
#define __KHADAS_EDGE_H__ | |||
/*----------------------------------------------------------------------------*/ | |||
// Common mmap block size for KHADAS-EDGE GRF register | |||
#define EDGE_GRF_BLOCK_SIZE 0xF000 | |||
// Common offset for GPIO registers from each GPIO bank's base address | |||
#define EDGE_GPIO_CON_OFFSET 0x04 // GPIO_SWPORTA_DDR | |||
#define EDGE_GPIO_SET_OFFSET 0x00 // GPIO_SWPORTA_DR | |||
#define EDGE_GPIO_GET_OFFSET 0x50 // GPIO_EXT_PORTA | |||
#define EDGE_FUNC_GPIO 0b00 // Bit for IOMUX GPIO mode | |||
// GPIO{0, 1} | |||
#define EDGE_PMUGRF_BASE 0xFF320000 | |||
#define EDGE_PMUGRF_IOMUX_OFFSET 0x0000 // GRF_GPIO0A_IOMUX | |||
#define EDGE_PMUGRF_PUPD_OFFSET 0x0040 // PMUGRF_GPIO0A_P | |||
// GPIO{2, 3, 4} | |||
#define EDGE_GRF_BASE 0xFF770000 | |||
#define EDGE_GRF_IOMUX_OFFSET 0xE000 // GRF_GPIO2A_IOMUX | |||
#define EDGE_GRF_PUPD_OFFSET 0xE040 // GRF_GPIO2A_P | |||
// Offset to control GPIO clock | |||
// Make 31:16 bit HIGH to enable the writing corresponding bit | |||
#define EDGE_PMUCRU_BASE 0xFF750000 | |||
#define EDGE_PMUCRU_GPIO_CLK_OFFSET 0x0104 // PMUCRU_CLKGATE_COEDGE | |||
#define EDGE_CRU_BASE 0xFF760000 | |||
#define EDGE_CRU_GPIO_CLK_OFFSET 0x037C // CRU_CLKGATE_CON31 | |||
#define EDGE_CLK_ENABLE 0b0 | |||
#define EDGE_CLK_DISABLE 0b1 | |||
// Only for Linux kernel for now. Edit to 0 for Android | |||
#ifndef __ANDROID__ | |||
#define EDGE_GPIO_PIN_BASE 1000 | |||
#else | |||
#define EDGE_GPIO_PIN_BASE 0 | |||
#endif | |||
// GPIO1_A. 0,1,2,3,4,7 | |||
// GPIO1_B. 0,1,2,3,4,5 | |||
// GPIO1_C. 2,4,5,6 | |||
// GPIO1_D. 0 | |||
#define EDGE_GPIO_1_BASE 0xFF730000 | |||
// GPIO2_C. 0_B,1_B | |||
#define EDGE_GPIO_2_BASE 0xFF780000 | |||
// GPIO4_C. 5,6 | |||
// GPIO4_D. 0,4,5,6 | |||
#define EDGE_GPIO_4_BASE 0xFF790000 | |||
// Reserved | |||
// GPIO{0, 3} | |||
#define EDGE_GPIO_0_BASE 0xFF720000 | |||
#define EDGE_GPIO_3_BASE 0xFF788000 | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
extern void init_khadas_edge (struct libkhadas *libwiring); | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
/*----------------------------------------------------------------------------*/ | |||
#endif /* __KHADAS_EDGE_H__ */ | |||
/*----------------------------------------------------------------------------*/ |
@@ -93,7 +93,7 @@ | |||
const int *pinToGpio, *phyToGpio; | |||
/* ADC file descriptor */ | |||
static char *adcFds[2]; | |||
//static char *adcFds[2]; | |||
/* GPIO mmap control */ | |||
static volatile uint32_t *gpio, *gpio1; | |||
@@ -129,7 +129,7 @@ static unsigned int _digitalReadByte (void); | |||
/* board init function */ | |||
/*------------------------------------------------------------------------------------------*/ | |||
static int init_gpio_mmap (void); | |||
static void init_adc_fds (void); | |||
//static void init_adc_fds (void); | |||
void init_khadas_vim1(struct libkhadas *libwiring); | |||
/*------------------------------------------------------------------------------------------*/ | |||
@@ -511,13 +511,13 @@ static void _digitalWrite(int pin, int value) | |||
/*------------------------------------------------------------------------------------------*/ | |||
static int _analogRead (int pin) | |||
static int _analogRead (int UNU pin) | |||
{ | |||
return -1; | |||
} | |||
/*------------------------------------------------------------------------------------------*/ | |||
static void _digitalWriteByte(const int value) | |||
static void _digitalWriteByte(const int UNU value) | |||
{ | |||
return; | |||
} | |||
@@ -556,12 +556,13 @@ static int init_gpio_mmap(void) | |||
return msg (MSG_ERR, | |||
"wiringPiSetup: mmap (GPIO) failed: %s\n", | |||
strerror (errno)); | |||
return 0; | |||
} | |||
/*------------------------------------------------------------------------------------------*/ | |||
/*------------------------------------------------------------------------------------------ | |||
static void init_adc_fds(void) | |||
{ | |||
} | |||
}*/ | |||
/*------------------------------------------------------------------------------------------*/ | |||
void init_khadas_vim1(struct libkhadas *libwiring) | |||
{ | |||
@@ -15,6 +15,7 @@ | |||
#include <asm/ioctl.h> | |||
#include <sys/mman.h> | |||
#include <sys/utsname.h> | |||
#include <string.h> | |||
#include "softPwm.h" | |||
#include "softTone.h" | |||
@@ -92,7 +93,7 @@ static const int phyToGpio_rev[64] = { | |||
const int *pinToGpio, *phyToGpio; | |||
/* ADC file descriptor */ | |||
static char *adcFds[2]; | |||
//static char *adcFds[2]; | |||
/* GPIO mmap control */ | |||
static volatile uint32_t *gpio,*gpio1; | |||
@@ -129,7 +130,7 @@ static unsigned int _digitalReadByte (void); | |||
/* board init function */ | |||
/*--------------------------------------------------------------------------------------*/ | |||
static int init_gpio_mmap (void); | |||
static void init_adc_fds (void); | |||
//static void init_adc_fds (void); | |||
void init_khadas_vim2(struct libkhadas *libwiring); | |||
/*--------------------------------------------------------------------------------------*/ | |||
@@ -527,13 +528,13 @@ static void _digitalWrite(int pin, int value) | |||
} | |||
/*------------------------------------------------------------------------------------------*/ | |||
static int _analogRead (int pin) | |||
static int _analogRead (int UNU pin) | |||
{ | |||
return -1; | |||
} | |||
/*-------------------------------------------------------------------------------------------*/ | |||
static void _digitalWriteByte(const int value) | |||
static void _digitalWriteByte(const int UNU value) | |||
{ | |||
return; | |||
} | |||
@@ -571,12 +572,14 @@ static int init_gpio_mmap(void) | |||
return msg (MSG_ERR, | |||
"wiringPiSetup: mmap (GPIO) failed: %s\n", | |||
strerror (errno)); | |||
return 0; | |||
} | |||
/*------------------------------------------------------------------------------------------*/ | |||
/*------------------------------------------------------------------------------------------ | |||
static void init_adc_fds(void) | |||
{ | |||
} | |||
*/ | |||
/*------------------------------------------------------------------------------------------*/ | |||
void init_khadas_vim2(struct libkhadas *libwiring) | |||
@@ -5,7 +5,7 @@ | |||
/*------------------------------------------------------------------------------------------*/ | |||
/*------------------------------------------------------------------------------------------*/ | |||
#ifndef __HKADAS_VIM2_H__ | |||
#ifndef __KHADAS_VIM2_H__ | |||
#define __KHADAS_VIM2_H__ | |||
/*------------------------------------------------------------------------------------------*/ | |||
@@ -93,7 +93,7 @@ static const int phyToGpio_rev[64] = { | |||
const int *pinToGpio, *phyToGpio; | |||
/* ADC file descriptor */ | |||
static char *adcFds[2]; | |||
//static char *adcFds[2]; | |||
/* GPIO mmap control */ | |||
static volatile uint32_t *gpio,*gpio1; | |||
@@ -119,7 +119,7 @@ static int gpioToMuxReg (int pin); | |||
/*--------------------------------------------------------------------------------------*/ | |||
static int _getModeToGpio (int mode, int pin); | |||
static void _setPadDrive (int pin, int value); | |||
static void _getPadDrive (int pin); | |||
static int _getPadDrive (int pin); | |||
static void _pinMode (int pin, int mode); | |||
static int _getAlt (int pin); | |||
static int _getPUPD (int pin); | |||
@@ -134,7 +134,7 @@ static unsigned int _digitalReadByte (void); | |||
/* board init function */ | |||
/*--------------------------------------------------------------------------------------*/ | |||
static int init_gpio_mmap (void); | |||
static void init_adc_fds (void); | |||
//static void init_adc_fds (void); | |||
void init_khadas_vim3(struct libkhadas *libwiring); | |||
/*--------------------------------------------------------------------------------------*/ | |||
@@ -268,6 +268,7 @@ static int gpioToMuxReg(int pin) | |||
case VIM3_GPIOAO_PIN_START + 8 ...VIM3_GPIOAO_PIN_END: | |||
return VIM3_GPIOAO_MUX_1_REG_OFFSET; | |||
} | |||
return VIM3_GPIOAO_MUX_1_REG_OFFSET; | |||
} | |||
/*------------------------------------------------------------------------------------------*/ | |||
@@ -328,15 +329,15 @@ static void _setPadDrive(int pin, int value) | |||
} | |||
/*-----------------------------------------------------------------------------------------*/ | |||
static void _getPadDrive(int pin) | |||
static int _getPadDrive(int pin) | |||
{ | |||
int ds, shift; | |||
if(lib->mode == MODE_GPIO_SYS) | |||
return; | |||
return -1; | |||
if((pin = _getModeToGpio(lib->mode, pin)) < 0) | |||
return; | |||
return -1; | |||
ds = gpioToDSReg(pin); | |||
shift = gpioToShiftReg(pin); | |||
@@ -566,13 +567,13 @@ static void _digitalWrite(int pin, int value) | |||
} | |||
/*------------------------------------------------------------------------------------------*/ | |||
static int _analogRead (int pin) | |||
static int _analogRead (int UNU pin) | |||
{ | |||
return -1; | |||
} | |||
/*-------------------------------------------------------------------------------------------*/ | |||
static void _digitalWriteByte(const int value) | |||
static void _digitalWriteByte(const int UNU value) | |||
{ | |||
return; | |||
} | |||
@@ -610,12 +611,13 @@ static int init_gpio_mmap(void) | |||
return msg (MSG_ERR, | |||
"wiringPiSetup: mmap (GPIO) failed: %s\n", | |||
strerror (errno)); | |||
return 0; | |||
} | |||
/*------------------------------------------------------------------------------------------*/ | |||
/*------------------------------------------------------------------------------------------ | |||
static void init_adc_fds(void) | |||
{ | |||
} | |||
}*/ | |||
/*------------------------------------------------------------------------------------------*/ | |||
void init_khadas_vim3(struct libkhadas *libwiring) | |||
@@ -5,7 +5,7 @@ | |||
/*------------------------------------------------------------------------------------------*/ | |||
/*------------------------------------------------------------------------------------------*/ | |||
#ifndef __HKADAS_VIM3_H__ | |||
#ifndef __KHADAS_VIM3_H__ | |||
#define __KHADAS_VIM3_H__ | |||
/*------------------------------------------------------------------------------------------*/ | |||
@@ -30,6 +30,11 @@ | |||
#include "max31855.h" | |||
#if defined ANDROID | |||
#define __bswap_16(x) bswap_16(x) | |||
#define __bswap_32(x) bswap_32(x) | |||
#endif | |||
static int myAnalogRead (struct wiringPiNodeStruct *node, int pin) | |||
{ | |||
uint32_t spiData ; | |||
@@ -174,7 +174,15 @@ void softPwmStop (int pin) | |||
{ | |||
if (range [pin] != 0) | |||
{ | |||
#ifdef ANDROID | |||
int status; | |||
if ( (status = pthread_kill(pin, SIGUSR1)) != 0) | |||
{ | |||
printf("Error cancelling thread %d", pin); | |||
} | |||
#else | |||
pthread_cancel (threads [pin]) ; | |||
#endif | |||
pthread_join (threads [pin], NULL) ; | |||
range [pin] = 0 ; | |||
digitalWrite (pin, LOW) ; | |||
@@ -142,7 +142,15 @@ void softToneStop (int pin) | |||
{ | |||
if (threads [pin] != 0) | |||
{ | |||
pthread_cancel (threads [pin]) ; | |||
#ifdef ANDROID | |||
int status; | |||
if ( (status = pthread_kill(pin, SIGUSR1)) != 0) | |||
{ | |||
printf("Error cancelling thread %d", pin); | |||
} | |||
#else | |||
pthread_cancel (threads [pin]) ; | |||
#endif | |||
pthread_join (threads [pin], NULL) ; | |||
threads [pin] = 0 ; | |||
digitalWrite (pin, LOW) ; | |||
@@ -32,6 +32,7 @@ | |||
#include "khadas_vim1.h" | |||
#include "khadas_vim2.h" | |||
#include "khadas_vim3.h" | |||
#include "khadas_edge.h" | |||
/*--------------------------------------------------------------------------------------*/ | |||
/* Const string define */ | |||
@@ -42,6 +43,7 @@ const char *piModelNames [16] = { | |||
"KHADAS-VIM1", | |||
"KHADAS-VIM2", | |||
"KHADAS-VIM3", | |||
"KHADAS-EDGE", | |||
}; | |||
const char *piRevisionNames [16] = { | |||
@@ -99,6 +101,13 @@ const int piMemorySize [8] = { | |||
static volatile int pinPass = -1; | |||
static pthread_mutex_t pinMutex ; | |||
/*----------------------------------------------------------------------------*/ | |||
#ifdef __ANDROID__ | |||
int pthread_cancel(pthread_t h) { | |||
return pthread_kill(h, 0); | |||
} | |||
#endif /* __ANDROID__ */ | |||
/*----------------------------------------------------------------------------*/ | |||
//Debugging & return codes | |||
int wiringPiDebug = FALSE; | |||
int wiringPiReturnCodes = FALSE; | |||
@@ -157,18 +166,18 @@ static void warn_msg(const char *func) | |||
/*------------------------------------------------------------------------------------------*/ | |||
/* Unsupport Function list on KHADAs */ | |||
/*------------------------------------------------------------------------------------------*/ | |||
static void piGpioLayoutOps (const char *why) {warn_msg(__func__);return;} | |||
void pwmSetMode (int mode) {warn_msg(__func__);return;} | |||
void pwmSetRange (unsigned int range) {warn_msg(__func__);return;} | |||
void pwmSetClock (int divisor) {warn_msg(__func__);return;} | |||
void gpioClockSet (int pin, int freq) {warn_msg(__func__);return;} | |||
static void UNU piGpioLayoutOps (const char UNU *why) {warn_msg(__func__);return;} | |||
void pwmSetMode (int UNU mode) {warn_msg(__func__);return;} | |||
void pwmSetRange (unsigned int UNU range) { warn_msg(__func__); return; } | |||
void pwmSetClock (int UNU divisor) { warn_msg(__func__); return; } | |||
void gpioClockSet (int UNU pin, int UNU freq) { warn_msg(__func__); return; } | |||
/* core unsupport function */ | |||
void pinModeAlt (int pin, int mode) {warn_msg(__func__);return;} | |||
void pwmWrite (int pin, int value) {warn_msg(__func__);return;} | |||
void analogWrite (int pin, int value) {warn_msg(__func__);return;} | |||
void pwmToneWrite (int pin, int freq) {warn_msg(__func__);return;} | |||
void digitalWriteByte2 (const int vaule) {warn_msg(__func__);return;} | |||
void pinModeAlt (int UNU pin, int UNU mode) { warn_msg(__func__); return; } | |||
void pwmWrite (int UNU pin, int UNU value) { warn_msg(__func__); return; } | |||
void analogWrite (int UNU pin, int UNU value) { warn_msg(__func__); return; } | |||
void pwmToneWrite (int UNU pin, int UNU freq) { warn_msg(__func__); return; } | |||
void digitalWriteByte2 (const int UNU value) { warn_msg(__func__); return; } | |||
unsigned int digitalReadByte2 (void) {warn_msg(__func__); return -1;} | |||
/*------------------------------------------------------------------------------------------*/ | |||
@@ -177,15 +186,15 @@ unsigned int digitalReadByte2 (void) {warn_msg(__func__); return -1;} | |||
/*------------------------------------------------------------------------------------------*/ | |||
struct wiringPiNodeStruct *wiringPiNodes = NULL; | |||
struct wiringPiNodeStruct *wiringPiFindNode(int pin) {return NULL;} | |||
struct wiringPiNodeStruct *wiringPiFindNode(int UNU pin) {return NULL;} | |||
static void pinModeDummy (UNU struct wiringPiNodeStruct *node, UNU int pin, UNU int mode) | |||
{return;} | |||
static void pullUpDnControlDummy(UNU struct wiringPiNodeStruct *node, UNU int pin, UNU int pud) | |||
{return;} | |||
static unsigned int digitalRead8Dummy (UNU struct wiringPiNodeStruct *node, UNU int UNU pin) | |||
static unsigned int UNU digitalRead8Dummy (UNU struct wiringPiNodeStruct *node, UNU int UNU pin) | |||
{return 0;} | |||
static void digitalWrite8Demmy (UNU struct wiringPiNodeStruct *node, UNU int pin,UNU int value) | |||
static void UNU digitalWrite8Demmy (UNU struct wiringPiNodeStruct *node, UNU int pin,UNU int value) | |||
{return;} | |||
static int digitalReadDummy (UNU struct wiringPiNodeStruct *node, UNU int UNU pin) | |||
{return LOW;} | |||
@@ -194,8 +203,8 @@ static void pwmWriteDummy (UNU struct wiringPiNodeStruct *node, UNU int pin, UN | |||
{return;} | |||
static int analogReadDummy (UNU struct wiringPiNodeStruct *node, UNU int pin) | |||
{return 0;} | |||
static int analogWriteDummy (UNU struct wiringPiNodeStruct *node,UNU int pin, UNU int value) | |||
{return 0;} | |||
static void analogWriteDummy (UNU struct wiringPiNodeStruct *node, UNU int pin, UNU int value) | |||
{return;} | |||
struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) | |||
{ | |||
@@ -219,8 +228,8 @@ struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) | |||
node->pinMode = pinModeDummy; | |||
node->pullUpDnControl = pullUpDnControlDummy; | |||
node->digitalRead = digitalReadDummy; | |||
node->digitalWrite = digitalWriteDummy; | |||
node->pwmWrite = pwmWriteDummy; | |||
node->digitalWrite = digitalWriteDummy ; | |||
node->pwmWrite = pwmWriteDummy ; | |||
node->analogRead = analogReadDummy; | |||
node->analogWrite = analogWriteDummy; | |||
node->next = wiringPiNodes; | |||
@@ -256,7 +265,6 @@ int piGpioLayout(void) | |||
{ | |||
FILE *cpuFd; | |||
char line[120]; | |||
char *c; | |||
static int gpioLayout = -1; | |||
if(-1 != gpioLayout) | |||
@@ -271,15 +279,21 @@ int piGpioLayout(void) | |||
if(0 == strncmp(line, "Hardware", 8)) | |||
break; | |||
if(0 != strncmp(line, "Hardware", 8) != 0) | |||
wiringPiFailure(WPI_FATAL, "No \"Hardware\" line"); | |||
if(0 != strncmp(line, "Hardware", 8) != 0){ | |||
//wiringPiFailure(WPI_FATAL, "No \"Hardware\" line"); | |||
libwiring.model = MODEL_KHADAS_EDGE; | |||
libwiring.maker = MAKER_ROCKCHIP; | |||
libwiring.mem = 4; | |||
libwiring.rev = 1; | |||
goto exit; | |||
} | |||
if(wiringPiDebug) | |||
printf ("piGpioLayout: Hardware: %s\n", line) ; | |||
if (!(strstr (line, "Khadas"))) | |||
wiringPiFailure (WPI_FATAL, "** This board is not KHADAS. **"); | |||
exit: | |||
rewind(cpuFd); | |||
gpioLayout = 1; | |||
@@ -485,7 +499,9 @@ int wiringPiISR (int pin, int mode, void (*function)(void)) | |||
const char *modeS; | |||
char fName [64]; | |||
char pinS [8]; | |||
#ifndef __ANDROID__ | |||
pid_t pid; | |||
#endif | |||
int count, i; | |||
char c; | |||
int GpioPin; | |||
@@ -519,6 +535,7 @@ int wiringPiISR (int pin, int mode, void (*function)(void)) | |||
sprintf (pinS, "%d", GpioPin); | |||
#ifndef __ANDROID__ | |||
if ((pid = fork ()) < 0) | |||
return wiringPiFailure ( | |||
WPI_FATAL, | |||
@@ -547,6 +564,36 @@ int wiringPiISR (int pin, int mode, void (*function)(void)) | |||
"wiringPiISR: Can't find gpio program\n"); | |||
}else | |||
wait (NULL) ; | |||
#else | |||
FILE *export, *direct, *edge; | |||
export = fopen("/sys/class/gpio/export", "w") ; | |||
fprintf (export, "%d\n", GpioPin) ; | |||
fclose (export) ; | |||
char fDirection[64]; | |||
sprintf (fDirection, "/sys/class/gpio/gpio%d/direction", GpioPin) ; | |||
while ((direct= fopen(fDirection, "w")) == NULL) { | |||
sleep(1); | |||
} | |||
fprintf (direct, "in\n") ; | |||
fclose (direct) ; | |||
char fEdge[64]; | |||
sprintf (fEdge, "/sys/class/gpio/gpio%d/edge", GpioPin) ; | |||
while ((edge= fopen(fEdge, "w")) == NULL) { | |||
sleep(1); | |||
} | |||
if (mode == INT_EDGE_FALLING) | |||
fprintf (edge, "falling\n"); | |||
else if (mode == INT_EDGE_RISING) | |||
fprintf (edge, "rising\n"); | |||
else if (mode == INT_EDGE_BOTH) | |||
fprintf (edge, "both\n"); | |||
else | |||
fprintf (edge, "none\n"); | |||
fclose (edge) ; | |||
#endif | |||
} | |||
// Now pre-open the /sys/class node - but it may already be open if | |||
@@ -733,6 +780,9 @@ int wiringPiSetup(void) | |||
case MODEL_KHADAS_VIM3: | |||
init_khadas_vim3(&libwiring); | |||
break; | |||
case MODEL_KHADAS_EDGE: | |||
init_khadas_edge(&libwiring); | |||
break; | |||
default: | |||
return wiringPiFailure (WPI_ALMOST,"wiringPiSetup: Unknown model\n"); | |||
} | |||
@@ -801,6 +851,9 @@ int wiringPiSetupSys (void) | |||
for (pin = 0 ; pin < 256 ; ++pin) | |||
{ | |||
switch(libwiring.model){ | |||
case MODEL_KHADAS_EDGE: | |||
sprintf (fName, "/sys/class/gpio/gpio%d/value", pin + libwiring.pinBase); | |||
break; | |||
default: | |||
sprintf (fName, "/sys/class/gpio/gpio%d/value", pin); | |||
break; | |||
@@ -48,6 +48,7 @@ | |||
#define MODEL_KHADAS_VIM1 1 | |||
#define MODEL_KHADAS_VIM2 2 | |||
#define MODEL_KHADAS_VIM3 3 | |||
#define MODEL_KHADAS_EDGE 4 | |||
#define MAKER_UNKNOWN 0 | |||
#define MAKER_AMLOGIC 1 | |||
@@ -113,7 +114,9 @@ extern const int piMemorySize [ 8] ; | |||
#define WPI_FATAL (1==1) | |||
#define WPI_ALMOST (1==2) | |||
#if !defined(ANDROID) | |||
#define PAGE_SIZE (4*1024) | |||
#endif | |||
#define BLOCK_SIZE (4*1024) | |||
#define MSG_ERR -1 | |||
@@ -310,7 +313,7 @@ extern void piLock (int key); | |||
extern void piUnlock (int key); | |||
//Schedulling priority | |||
//extern void piHiPri (unsigned int howLong); | |||
extern int piHiPri (const int pri); | |||
//From Arduino land | |||
extern void delay (unsigned int howLang); | |||
@@ -221,6 +221,7 @@ int wiringPiI2CSetup (const int devId) | |||
{ | |||
int rev ; | |||
const char *device ; | |||
int model, mem, maker, overVolted ; | |||
rev = piGpioLayout () ; | |||
@@ -228,6 +229,14 @@ int wiringPiI2CSetup (const int devId) | |||
device = "/dev/i2c-0" ; | |||
else | |||
device = "/dev/i2c-1" ; | |||
piBoardId (&model, &rev, &mem, &maker, &overVolted) ; | |||
switch(model) { | |||
case MODEL_KHADAS_EDGE: | |||
device = "/dev/i2c-2"; | |||
break; | |||
default: | |||
break; | |||
} | |||
return wiringPiI2CSetupInterface (device, devId) ; | |||
} |
@@ -41,6 +41,7 @@ | |||
static const char *spiDev0 = "/dev/spidev0.0" ; | |||
static const char *spiDev1 = "/dev/spidev0.1" ; | |||
static const char *spiDevType3 = "/dev/spidev3.0"; | |||
static const uint8_t spiBPW = 8 ; | |||
static const uint16_t spiDelay = 0 ; | |||
@@ -100,13 +101,22 @@ int wiringPiSPIDataRW (int channel, unsigned char *data, int len) | |||
int wiringPiSPISetupMode (int channel, int speed, int mode) | |||
{ | |||
int fd ; | |||
int model, rev, mem, maker, overVolted ; | |||
const char *device ; | |||
piBoardId (&model, &rev, &mem, &maker, &overVolted) ; | |||
mode &= 3 ; // Mode is 0, 1, 2 or 3 | |||
channel &= 1 ; // Channel is 0 or 1 | |||
if ((fd = open (channel == 0 ? spiDev0 : spiDev1, O_RDWR)) < 0) | |||
return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ; | |||
if (model == MODEL_KHADAS_EDGE) { | |||
device = spiDevType3; | |||
if ((fd = open (device, O_RDWR)) < 0) | |||
return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ; | |||
} | |||
else{ | |||
if ((fd = open (channel == 0 ? spiDev0 : spiDev1, O_RDWR)) < 0) | |||
return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ; | |||
} | |||
spiSpeeds [channel] = speed ; | |||
spiFds [channel] = fd ; | |||
@@ -61,8 +61,9 @@ | |||
#include "bmp180.h" | |||
#include "htu21d.h" | |||
#include "ds18b20.h" | |||
#if !defined ANDROID | |||
#include "rht03.h" | |||
#endif | |||
#include "wpiExtensions.h" | |||
extern int wiringPiDebug ; | |||
@@ -463,7 +464,7 @@ static int doExtensionPcf8591 (char *progName, int pinBase, char *params) | |||
********************************************************************************* | |||
*/ | |||
static int doExtensionPseudoPins (UNU char *progName, int pinBase, UNU char *params) | |||
static int UNU doExtensionPseudoPins (UNU char *progName, int pinBase, UNU char *params) | |||
{ | |||
pseudoPinsSetup (pinBase) ; | |||
@@ -517,6 +518,7 @@ static int doExtensionDs18b20 (char *progName, int pinBase, char *params) | |||
return ds18b20Setup (pinBase, serialNum) ; | |||
} | |||
#if !defined ANDROID | |||
/* | |||
@@ -535,7 +537,7 @@ static int doExtensionRht03 (char *progName, int pinBase, char *params) | |||
return rht03Setup (pinBase, piPin) ; | |||
} | |||
#endif | |||
/* | |||
* doExtensionMax31855: | |||
@@ -769,7 +771,7 @@ static int doExtensionDrcS (char *progName, int pinBase, char *params) | |||
return TRUE ; | |||
} | |||
#if !defined ANDROID | |||
/* | |||
* doExtensionDrcNet: | |||
* Interface to a DRC Network system | |||
@@ -822,7 +824,7 @@ static int doExtensionDrcNet (char *progName, int pinBase, char *params) | |||
return drcSetupNet (pinBase, pins, ipAddress, port, password) ; | |||
} | |||
#endif | |||
/* | |||
* Function list | |||
@@ -840,10 +842,14 @@ static struct extensionFunctionStruct extensionFunctions [] = | |||
{ "pcf8574", &doExtensionPcf8574 }, | |||
{ "pcf8591", &doExtensionPcf8591 }, | |||
{ "bmp180", &doExtensionBmp180 }, | |||
#if !defined ANDROID | |||
{ "pseudoPins", &doExtensionPseudoPins }, | |||
#endif | |||
{ "htu21d", &doExtensionHtu21d }, | |||
{ "ds18b20", &doExtensionDs18b20 }, | |||
#if !defined ANDROID | |||
{ "rht03", &doExtensionRht03 }, | |||
#endif | |||
{ "mcp3002", &doExtensionMcp3002 }, | |||
{ "mcp3004", &doExtensionMcp3004 }, | |||
{ "mcp4802", &doExtensionMcp4802 }, | |||
@@ -853,7 +859,9 @@ static struct extensionFunctionStruct extensionFunctions [] = | |||
{ "max5322", &doExtensionMax5322 }, | |||
{ "sn3218", &doExtensionSn3218 }, | |||
{ "drcs", &doExtensionDrcS }, | |||
#if !defined ANDROID | |||
{ "drcn", &doExtensionDrcNet }, | |||
#endif | |||
{ NULL, NULL }, | |||
} ; | |||