wiringPi: Clean warning messages from gcc
Signed-off-by: Joshua Yang <joshua.yang@hardkernel.com>
This commit is contained in:
@@ -208,7 +208,6 @@ static void doUnLoad (int UNU argc, char *argv [])
|
|||||||
static void doI2Cdetect (UNU int argc, char *argv [])
|
static void doI2Cdetect (UNU int argc, char *argv [])
|
||||||
{
|
{
|
||||||
int model, rev, mem, maker, overVolted, port;
|
int model, rev, mem, maker, overVolted, port;
|
||||||
const char *device = NULL;
|
|
||||||
char *c, *command ;
|
char *c, *command ;
|
||||||
|
|
||||||
piBoardId(&model, &rev, &mem, &maker, &overVolted);
|
piBoardId(&model, &rev, &mem, &maker, &overVolted);
|
||||||
@@ -216,15 +215,12 @@ static void doI2Cdetect (UNU int argc, char *argv [])
|
|||||||
switch (model) {
|
switch (model) {
|
||||||
case MODEL_ODROID_C1: case MODEL_ODROID_C2:
|
case MODEL_ODROID_C1: case MODEL_ODROID_C2:
|
||||||
case MODEL_ODROID_XU3:
|
case MODEL_ODROID_XU3:
|
||||||
device = "/dev/i2c-1";
|
|
||||||
port = 1;
|
port = 1;
|
||||||
break;
|
break;
|
||||||
case MODEL_ODROID_N1:
|
case MODEL_ODROID_N1:
|
||||||
device = "/dev/i2c-4";
|
|
||||||
port = 4;
|
port = 4;
|
||||||
break;
|
break;
|
||||||
case MODEL_ODROID_N2:
|
case MODEL_ODROID_N2:
|
||||||
device = "/dev/i2c-3";
|
|
||||||
port = 3;
|
port = 3;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -239,7 +235,6 @@ static void doI2Cdetect (UNU int argc, char *argv [])
|
|||||||
case MAKER_AMLOGIC:
|
case MAKER_AMLOGIC:
|
||||||
if (!moduleLoaded (AML_MODULE_I2C)) {
|
if (!moduleLoaded (AML_MODULE_I2C)) {
|
||||||
fprintf (stderr, "%s: The I2C kernel module(s) are not loaded.\n", argv [0]) ;
|
fprintf (stderr, "%s: The I2C kernel module(s) are not loaded.\n", argv [0]) ;
|
||||||
return ;
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -1028,7 +1023,8 @@ static void doVersion (char *argv [])
|
|||||||
// Output Kernel idea of board type
|
// Output Kernel idea of board type
|
||||||
if (stat ("/proc/device-tree/model", &statBuf) == 0) {
|
if (stat ("/proc/device-tree/model", &statBuf) == 0) {
|
||||||
if ((fd = fopen ("/proc/device-tree/model", "r")) != NULL) {
|
if ((fd = fopen ("/proc/device-tree/model", "r")) != NULL) {
|
||||||
fgets (name, 80, fd) ;
|
if (fgets (name, 80, fd) == NULL)
|
||||||
|
fprintf(stderr, "Unable to read from the file descriptor: %s \n", strerror(errno));
|
||||||
fclose (fd) ;
|
fclose (fd) ;
|
||||||
printf (" *--> %s\n", name) ;
|
printf (" *--> %s\n", name) ;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -415,7 +415,7 @@ void ReadallOdroid (int model, int rev, const char *physNames[])
|
|||||||
void doReadall (void)
|
void doReadall (void)
|
||||||
{
|
{
|
||||||
int model, rev, mem, maker, overVolted;
|
int model, rev, mem, maker, overVolted;
|
||||||
const char (*physNames)[];
|
char *physNames;
|
||||||
|
|
||||||
// External readall
|
// External readall
|
||||||
if (wiringPiNodes != NULL) {
|
if (wiringPiNodes != NULL) {
|
||||||
@@ -428,32 +428,32 @@ void doReadall (void)
|
|||||||
switch (model) {
|
switch (model) {
|
||||||
case MODEL_ODROID_C1:
|
case MODEL_ODROID_C1:
|
||||||
printf (" +------+-----+----------+------+---+----+---- Model ODROID-C1 ----+----+---+------+----------+-----+------+\n") ;
|
printf (" +------+-----+----------+------+---+----+---- Model ODROID-C1 ----+----+---+------+----------+-----+------+\n") ;
|
||||||
physNames = physNamesOdroidC1;
|
physNames = (char *) physNamesOdroidC1;
|
||||||
break;
|
break;
|
||||||
case MODEL_ODROID_C2:
|
case MODEL_ODROID_C2:
|
||||||
printf (" +------+-----+----------+------+---+----+---- Model ODROID-C2 ----+----+---+------+----------+-----+------+\n") ;
|
printf (" +------+-----+----------+------+---+----+---- Model ODROID-C2 ----+----+---+------+----------+-----+------+\n") ;
|
||||||
if (rev == 1)
|
if (rev == 1)
|
||||||
physNames = physNamesOdroidC2_Rev1;
|
physNames = (char *) physNamesOdroidC2_Rev1;
|
||||||
else
|
else
|
||||||
physNames = physNamesOdroidC2_Rev2;
|
physNames = (char *) physNamesOdroidC2_Rev2;
|
||||||
break;
|
break;
|
||||||
case MODEL_ODROID_XU3:
|
case MODEL_ODROID_XU3:
|
||||||
printf (" +------+-----+----------+------+---+----+--- Model ODROID-XU3/4 ---+----+---+------+----------+-----+------+\n") ;
|
printf (" +------+-----+----------+------+---+----+--- Model ODROID-XU3/4 ---+----+---+------+----------+-----+------+\n") ;
|
||||||
physNames = physNamesOdroidXU3;
|
physNames = (char *) physNamesOdroidXU3;
|
||||||
break;
|
break;
|
||||||
case MODEL_ODROID_N1:
|
case MODEL_ODROID_N1:
|
||||||
printf (" +------+-----+----------+------+---+----+---- Model ODROID-N1 ----+----+---+------+----------+-----+------+\n") ;
|
printf (" +------+-----+----------+------+---+----+---- Model ODROID-N1 ----+----+---+------+----------+-----+------+\n") ;
|
||||||
physNames = physNamesOdroidN1;
|
physNames = (char *) physNamesOdroidN1;
|
||||||
break;
|
break;
|
||||||
case MODEL_ODROID_N2:
|
case MODEL_ODROID_N2:
|
||||||
printf (" +------+-----+----------+------+---+----+---- Model ODROID-N2 ----+----+---+------+----------+-----+------+\n") ;
|
printf (" +------+-----+----------+------+---+----+---- Model ODROID-N2 ----+----+---+------+----------+-----+------+\n") ;
|
||||||
physNames = physNamesOdroidN2;
|
physNames = (char *) physNamesOdroidN2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf ("Oops - unable to determine board type... model: %d\n", model) ;
|
printf ("Oops - unable to determine board type... model: %d\n", model) ;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ReadallOdroid(model, rev, physNames);
|
ReadallOdroid(model, rev, (const char **) physNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#include <wiringPi.h>
|
#include <wiringPi.h>
|
||||||
@@ -47,7 +49,9 @@ void waitForConversion (int fd, unsigned char *buffer, int n)
|
|||||||
{
|
{
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
read (fd, buffer, n) ;
|
if (read(fd, buffer, n) < 0) {
|
||||||
|
fprintf(stderr, "Unable to read from the file descriptor: %s \n", strerror(errno));
|
||||||
|
}
|
||||||
if ((buffer [n-1] & 0x80) == 0)
|
if ((buffer [n-1] & 0x80) == 0)
|
||||||
break ;
|
break ;
|
||||||
delay (1) ;
|
delay (1) ;
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ static const int phyToGpio[64] = {
|
|||||||
//
|
//
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* ADC file descriptor */
|
/* ADC file descriptor */
|
||||||
static char *adcFds[2];
|
static int adcFds[2];
|
||||||
|
|
||||||
/* GPIO mmap control */
|
/* GPIO mmap control */
|
||||||
static volatile uint32_t *gpio;
|
static volatile uint32_t *gpio;
|
||||||
@@ -110,14 +110,14 @@ static int gpioToGPFSELReg (int pin);
|
|||||||
// wiringPi core function
|
// wiringPi core function
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int _getModeToGpio (int mode, int pin);
|
static int _getModeToGpio (int mode, int pin);
|
||||||
static void _pinMode (int pin, int mode);
|
static int _pinMode (int pin, int mode);
|
||||||
static int _getAlt (int pin);
|
static int _getAlt (int pin);
|
||||||
static int _getPUPD (int pin);
|
static int _getPUPD (int pin);
|
||||||
static void _pullUpDnControl (int pin, int pud);
|
static int _pullUpDnControl (int pin, int pud);
|
||||||
static int _digitalRead (int pin);
|
static int _digitalRead (int pin);
|
||||||
static void _digitalWrite (int pin, int value);
|
static int _digitalWrite (int pin, int value);
|
||||||
static int _analogRead (int pin);
|
static int _analogRead (int pin);
|
||||||
static void _digitalWriteByte (const int value);
|
static int _digitalWriteByte (const unsigned int value);
|
||||||
static unsigned int _digitalReadByte (void);
|
static unsigned int _digitalReadByte (void);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -262,15 +262,15 @@ static int _getModeToGpio (int mode, int pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _pinMode (int pin, int mode)
|
static int _pinMode (int pin, int mode)
|
||||||
{
|
{
|
||||||
int fsel, shift, origPin = pin;
|
int fsel, shift, origPin = pin;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
softPwmStop (origPin);
|
softPwmStop (origPin);
|
||||||
softToneStop (origPin);
|
softToneStop (origPin);
|
||||||
@@ -281,20 +281,22 @@ static void _pinMode (int pin, int mode)
|
|||||||
switch (mode) {
|
switch (mode) {
|
||||||
case INPUT:
|
case INPUT:
|
||||||
*(gpio + fsel) = (*(gpio + fsel) | (1 << shift));
|
*(gpio + fsel) = (*(gpio + fsel) | (1 << shift));
|
||||||
break;
|
break;
|
||||||
case OUTPUT:
|
case OUTPUT:
|
||||||
*(gpio + fsel) = (*(gpio + fsel) & ~(1 << shift));
|
*(gpio + fsel) = (*(gpio + fsel) & ~(1 << shift));
|
||||||
break;
|
break;
|
||||||
case SOFT_PWM_OUTPUT:
|
case SOFT_PWM_OUTPUT:
|
||||||
softPwmCreate (origPin, 0, 100);
|
softPwmCreate (origPin, 0, 100);
|
||||||
break;
|
break;
|
||||||
case SOFT_TONE_OUTPUT:
|
case SOFT_TONE_OUTPUT:
|
||||||
softToneCreate (origPin);
|
softToneCreate (origPin);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
msg(MSG_WARN, "%s : Unknown Mode %d\n", __func__, mode);
|
msg(MSG_WARN, "%s : Unknown Mode %d\n", __func__, mode);
|
||||||
break;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -304,10 +306,10 @@ static int _getAlt (int pin)
|
|||||||
int mode = 0;
|
int mode = 0;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return 2;
|
return -1;
|
||||||
|
|
||||||
fsel = gpioToGPFSELReg(pin);
|
fsel = gpioToGPFSELReg(pin);
|
||||||
shift = gpioToShiftReg(pin);
|
shift = gpioToShiftReg(pin);
|
||||||
@@ -426,10 +428,10 @@ static int _getPUPD (int pin)
|
|||||||
int puen, pupd, shift;
|
int puen, pupd, shift;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
puen = gpioToPUENReg(pin);
|
puen = gpioToPUENReg(pin);
|
||||||
pupd = gpioToPUPDReg(pin);
|
pupd = gpioToPUPDReg(pin);
|
||||||
@@ -442,15 +444,15 @@ static int _getPUPD (int pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _pullUpDnControl (int pin, int pud)
|
static int _pullUpDnControl (int pin, int pud)
|
||||||
{
|
{
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
shift = gpioToShiftReg(pin);
|
shift = gpioToShiftReg(pin);
|
||||||
|
|
||||||
@@ -468,6 +470,8 @@ static void _pullUpDnControl (int pin, int pud)
|
|||||||
} else // Disable Pull/Pull-down resister
|
} else // Disable Pull/Pull-down resister
|
||||||
*(gpio + gpioToPUENReg(pin)) =
|
*(gpio + gpioToPUENReg(pin)) =
|
||||||
(*(gpio + gpioToPUENReg(pin)) & ~(1 << shift));
|
(*(gpio + gpioToPUENReg(pin)) & ~(1 << shift));
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -477,16 +481,19 @@ static int _digitalRead (int pin)
|
|||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS) {
|
if (lib->mode == MODE_GPIO_SYS) {
|
||||||
if (lib->sysFds[pin] == -1)
|
if (lib->sysFds[pin] == -1)
|
||||||
return LOW ;
|
return -1;
|
||||||
|
|
||||||
lseek (lib->sysFds[pin], 0L, SEEK_SET);
|
lseek (lib->sysFds[pin], 0L, SEEK_SET);
|
||||||
read (lib->sysFds[pin], &c, 1);
|
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;
|
return (c == '0') ? LOW : HIGH;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
if ((*(gpio + gpioToGPLEVReg(pin)) & (1 << gpioToShiftReg(pin))) != 0)
|
if ((*(gpio + gpioToGPLEVReg(pin)) & (1 << gpioToShiftReg(pin))) != 0)
|
||||||
return HIGH ;
|
return HIGH ;
|
||||||
@@ -495,34 +502,39 @@ static int _digitalRead (int pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _digitalWrite (int pin, int value)
|
static int _digitalWrite (int pin, int value)
|
||||||
{
|
{
|
||||||
if (lib->mode == MODE_GPIO_SYS) {
|
if (lib->mode == MODE_GPIO_SYS) {
|
||||||
if (lib->sysFds[pin] != -1) {
|
if (lib->sysFds[pin] != -1) {
|
||||||
if (value == LOW)
|
if (value == LOW) {
|
||||||
write (lib->sysFds[pin], "0\n", 2);
|
if (write(lib->sysFds[pin], "0\n", 2) < 0)
|
||||||
else
|
msg(MSG_WARN, "%s: Failed with reading from sysfs GPIO node. \n", __func__);
|
||||||
write (lib->sysFds[pin], "1\n", 2);
|
} else {
|
||||||
|
if (write(lib->sysFds[pin], "1\n", 2) < 0)
|
||||||
|
msg(MSG_WARN, "%s: Failed with reading from sysfs GPIO node. \n", __func__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if (value == LOW)
|
if (value == LOW)
|
||||||
*(gpio + gpioToGPSETReg(pin)) &= ~(1 << gpioToShiftReg(pin));
|
*(gpio + gpioToGPSETReg(pin)) &= ~(1 << gpioToShiftReg(pin));
|
||||||
else
|
else
|
||||||
*(gpio + gpioToGPSETReg(pin)) |= (1 << gpioToShiftReg(pin));
|
*(gpio + gpioToGPSETReg(pin)) |= (1 << gpioToShiftReg(pin));
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int _analogRead (int pin)
|
static int _analogRead (int pin)
|
||||||
{
|
{
|
||||||
unsigned char value[5] = {0,};
|
char value[5] = {0,};
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
/* wiringPi ADC number = pin 25, pin 29 */
|
/* wiringPi ADC number = pin 25, pin 29 */
|
||||||
switch (pin) {
|
switch (pin) {
|
||||||
@@ -548,14 +560,17 @@ static int _analogRead (int pin)
|
|||||||
if (adcFds [pin] == -1)
|
if (adcFds [pin] == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
lseek (adcFds [pin], 0L, SEEK_SET);
|
lseek(adcFds [pin], 0L, SEEK_SET);
|
||||||
read (adcFds [pin], &value[0], 4);
|
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);
|
return atoi(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _digitalWriteByte (const int value)
|
static int _digitalWriteByte (const unsigned int value)
|
||||||
{
|
{
|
||||||
union reg_bitfield gpiox, gpioy;
|
union reg_bitfield gpiox, gpioy;
|
||||||
|
|
||||||
@@ -581,6 +596,8 @@ static void _digitalWriteByte (const int value)
|
|||||||
|
|
||||||
*(gpio + C1_GPIOX_OUTP_REG_OFFSET) = gpiox.wvalue;
|
*(gpio + C1_GPIOX_OUTP_REG_OFFSET) = gpiox.wvalue;
|
||||||
*(gpio + C1_GPIOY_OUTP_REG_OFFSET) = gpioy.wvalue;
|
*(gpio + C1_GPIOY_OUTP_REG_OFFSET) = gpioy.wvalue;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -623,33 +640,37 @@ static unsigned int _digitalReadByte (void)
|
|||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void init_gpio_mmap (void)
|
static void init_gpio_mmap (void)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd = -1;
|
||||||
|
void *mapped;
|
||||||
|
|
||||||
/* GPIO mmap setup */
|
/* GPIO mmap setup */
|
||||||
if (!getuid()) {
|
if (!getuid()) {
|
||||||
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
||||||
return msg (MSG_ERR,
|
msg (MSG_ERR,
|
||||||
"wiringPiSetup: Unable to open /dev/mem: %s\n",
|
"wiringPiSetup: Unable to open /dev/mem: %s\n",
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
} else {
|
} else {
|
||||||
if (access("/dev/gpiomem",0) == 0) {
|
if (access("/dev/gpiomem",0) == 0) {
|
||||||
if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
||||||
return msg (MSG_ERR,
|
msg (MSG_ERR,
|
||||||
"wiringPiSetup: Unable to open /dev/gpiomem: %s\n",
|
"wiringPiSetup: Unable to open /dev/gpiomem: %s\n",
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
} else
|
} else
|
||||||
return msg (MSG_ERR,
|
msg (MSG_ERR,
|
||||||
"wiringPiSetup: /dev/gpiomem doesn't exist. Please try again with sudo.\n");
|
"wiringPiSetup: /dev/gpiomem doesn't exist. Please try again with sudo.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// #define C1_GPIO_BASE 0xC1108000
|
if (fd < 0) {
|
||||||
gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
|
msg(MSG_ERR, "wiringPiSetup: Cannot open memory area for GPIO use. \n");
|
||||||
MAP_SHARED, fd, C1_GPIO_BASE) ;
|
} else {
|
||||||
|
// #define C1_GPIO_BASE 0xC1108000
|
||||||
|
mapped = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, C1_GPIO_BASE);
|
||||||
|
|
||||||
if ((int32_t)gpio == -1)
|
if (mapped == MAP_FAILED)
|
||||||
return msg (MSG_ERR,
|
msg(MSG_ERR, "wiringPiSetup: mmap (GPIO) failed: %s \n", strerror (errno));
|
||||||
"wiringPiSetup: mmap (GPIO) failed: %s\n",
|
else
|
||||||
strerror (errno));
|
gpio = (uint32_t *) mapped;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -143,10 +143,10 @@ static const int phyToGpio_rev2[64] = {
|
|||||||
const int *pinToGpio, *phyToGpio;
|
const int *pinToGpio, *phyToGpio;
|
||||||
|
|
||||||
/* ADC file descriptor */
|
/* ADC file descriptor */
|
||||||
static char *adcFds[2];
|
static int adcFds[2];
|
||||||
|
|
||||||
/* GPIO mmap control */
|
/* GPIO mmap control */
|
||||||
static volatile uint32_t *gpio, *gpio1;
|
static volatile uint32_t *gpio;
|
||||||
|
|
||||||
/* wiringPi Global library */
|
/* wiringPi Global library */
|
||||||
static struct libodroid *lib = NULL;
|
static struct libodroid *lib = NULL;
|
||||||
@@ -165,14 +165,14 @@ static int gpioToGPFSELReg (int pin);
|
|||||||
// wiringPi core function
|
// wiringPi core function
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int _getModeToGpio (int mode, int pin);
|
static int _getModeToGpio (int mode, int pin);
|
||||||
static void _pinMode (int pin, int mode);
|
static int _pinMode (int pin, int mode);
|
||||||
static int _getAlt (int pin);
|
static int _getAlt (int pin);
|
||||||
static int _getPUPD (int pin);
|
static int _getPUPD (int pin);
|
||||||
static void _pullUpDnControl (int pin, int pud);
|
static int _pullUpDnControl (int pin, int pud);
|
||||||
static int _digitalRead (int pin);
|
static int _digitalRead (int pin);
|
||||||
static void _digitalWrite (int pin, int value);
|
static int _digitalWrite (int pin, int value);
|
||||||
static int _analogRead (int pin);
|
static int _analogRead (int pin);
|
||||||
static void _digitalWriteByte (const int value);
|
static int _digitalWriteByte (const unsigned int value);
|
||||||
static unsigned int _digitalReadByte (void);
|
static unsigned int _digitalReadByte (void);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -316,15 +316,15 @@ static int _getModeToGpio (int mode, int pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _pinMode (int pin, int mode)
|
static int _pinMode (int pin, int mode)
|
||||||
{
|
{
|
||||||
int fsel, shift, origPin = pin;
|
int fsel, shift, origPin = pin;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
softPwmStop (origPin);
|
softPwmStop (origPin);
|
||||||
softToneStop (origPin);
|
softToneStop (origPin);
|
||||||
@@ -335,20 +335,22 @@ static void _pinMode (int pin, int mode)
|
|||||||
switch (mode) {
|
switch (mode) {
|
||||||
case INPUT:
|
case INPUT:
|
||||||
*(gpio + fsel) = (*(gpio + fsel) | (1 << shift));
|
*(gpio + fsel) = (*(gpio + fsel) | (1 << shift));
|
||||||
break;
|
break;
|
||||||
case OUTPUT:
|
case OUTPUT:
|
||||||
*(gpio + fsel) = (*(gpio + fsel) & ~(1 << shift));
|
*(gpio + fsel) = (*(gpio + fsel) & ~(1 << shift));
|
||||||
break;
|
break;
|
||||||
case SOFT_PWM_OUTPUT:
|
case SOFT_PWM_OUTPUT:
|
||||||
softPwmCreate (origPin, 0, 100);
|
softPwmCreate (origPin, 0, 100);
|
||||||
break;
|
break;
|
||||||
case SOFT_TONE_OUTPUT:
|
case SOFT_TONE_OUTPUT:
|
||||||
softToneCreate (origPin);
|
softToneCreate (origPin);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
msg(MSG_WARN, "%s : Unknown Mode %d\n", __func__, mode);
|
msg(MSG_WARN, "%s : Unknown Mode %d\n", __func__, mode);
|
||||||
break;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -358,10 +360,10 @@ static int _getAlt (int pin)
|
|||||||
int mode = 0;
|
int mode = 0;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return 2;
|
return -1;
|
||||||
|
|
||||||
fsel = gpioToGPFSELReg(pin);
|
fsel = gpioToGPFSELReg(pin);
|
||||||
shift = gpioToShiftReg(pin);
|
shift = gpioToShiftReg(pin);
|
||||||
@@ -496,10 +498,10 @@ static int _getPUPD (int pin)
|
|||||||
int puen, pupd, shift;
|
int puen, pupd, shift;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
puen = gpioToPUENReg(pin);
|
puen = gpioToPUENReg(pin);
|
||||||
pupd = gpioToPUPDReg(pin);
|
pupd = gpioToPUPDReg(pin);
|
||||||
@@ -512,15 +514,15 @@ static int _getPUPD (int pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _pullUpDnControl (int pin, int pud)
|
static int _pullUpDnControl (int pin, int pud)
|
||||||
{
|
{
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
shift = gpioToShiftReg(pin);
|
shift = gpioToShiftReg(pin);
|
||||||
|
|
||||||
@@ -538,6 +540,8 @@ static void _pullUpDnControl (int pin, int pud)
|
|||||||
} else // Disable Pull/Pull-down resister
|
} else // Disable Pull/Pull-down resister
|
||||||
*(gpio + gpioToPUENReg(pin)) =
|
*(gpio + gpioToPUENReg(pin)) =
|
||||||
(*(gpio + gpioToPUENReg(pin)) & ~(1 << shift));
|
(*(gpio + gpioToPUENReg(pin)) & ~(1 << shift));
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -547,16 +551,19 @@ static int _digitalRead (int pin)
|
|||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS) {
|
if (lib->mode == MODE_GPIO_SYS) {
|
||||||
if (lib->sysFds[pin] == -1)
|
if (lib->sysFds[pin] == -1)
|
||||||
return LOW ;
|
return -1;
|
||||||
|
|
||||||
lseek (lib->sysFds[pin], 0L, SEEK_SET);
|
lseek (lib->sysFds[pin], 0L, SEEK_SET);
|
||||||
read (lib->sysFds[pin], &c, 1);
|
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;
|
return (c == '0') ? LOW : HIGH;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
if ((*(gpio + gpioToGPLEVReg(pin)) & (1 << gpioToShiftReg(pin))) != 0)
|
if ((*(gpio + gpioToGPLEVReg(pin)) & (1 << gpioToShiftReg(pin))) != 0)
|
||||||
return HIGH ;
|
return HIGH ;
|
||||||
@@ -565,34 +572,39 @@ static int _digitalRead (int pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _digitalWrite (int pin, int value)
|
static int _digitalWrite (int pin, int value)
|
||||||
{
|
{
|
||||||
if (lib->mode == MODE_GPIO_SYS) {
|
if (lib->mode == MODE_GPIO_SYS) {
|
||||||
if (lib->sysFds[pin] != -1) {
|
if (lib->sysFds[pin] != -1) {
|
||||||
if (value == LOW)
|
if (value == LOW) {
|
||||||
write (lib->sysFds[pin], "0\n", 2);
|
if (write(lib->sysFds[pin], "0\n", 2) < 0)
|
||||||
else
|
msg(MSG_WARN, "%s: Failed with reading from sysfs GPIO node. \n", __func__);
|
||||||
write (lib->sysFds[pin], "1\n", 2);
|
} else {
|
||||||
|
if (write(lib->sysFds[pin], "1\n", 2) < 0)
|
||||||
|
msg(MSG_WARN, "%s: Failed with reading from sysfs GPIO node. \n", __func__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if (value == LOW)
|
if (value == LOW)
|
||||||
*(gpio + gpioToGPSETReg(pin)) &= ~(1 << gpioToShiftReg(pin));
|
*(gpio + gpioToGPSETReg(pin)) &= ~(1 << gpioToShiftReg(pin));
|
||||||
else
|
else
|
||||||
*(gpio + gpioToGPSETReg(pin)) |= (1 << gpioToShiftReg(pin));
|
*(gpio + gpioToGPSETReg(pin)) |= (1 << gpioToShiftReg(pin));
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int _analogRead (int pin)
|
static int _analogRead (int pin)
|
||||||
{
|
{
|
||||||
unsigned char value[5] = {0,};
|
char value[5] = {0,};
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
/* wiringPi ADC number = pin 25, pin 29 */
|
/* wiringPi ADC number = pin 25, pin 29 */
|
||||||
switch (pin) {
|
switch (pin) {
|
||||||
@@ -618,14 +630,17 @@ static int _analogRead (int pin)
|
|||||||
if (adcFds [pin] == -1)
|
if (adcFds [pin] == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
lseek (adcFds [pin], 0L, SEEK_SET);
|
lseek(adcFds [pin], 0L, SEEK_SET);
|
||||||
read (adcFds [pin], &value[0], 4);
|
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);
|
return atoi(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _digitalWriteByte (const int value)
|
static int _digitalWriteByte (const unsigned int value)
|
||||||
{
|
{
|
||||||
union reg_bitfield gpiox;
|
union reg_bitfield gpiox;
|
||||||
|
|
||||||
@@ -649,6 +664,8 @@ static void _digitalWriteByte (const int value)
|
|||||||
gpiox.bits.bit21 = (value & 0x80);
|
gpiox.bits.bit21 = (value & 0x80);
|
||||||
|
|
||||||
*(gpio + C2_GPIOX_OUTP_REG_OFFSET) = gpiox.wvalue;
|
*(gpio + C2_GPIOX_OUTP_REG_OFFSET) = gpiox.wvalue;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -660,33 +677,39 @@ static unsigned int _digitalReadByte (void)
|
|||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void init_gpio_mmap (void)
|
static void init_gpio_mmap (void)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd = -1;
|
||||||
|
void *mapped;
|
||||||
|
|
||||||
/* GPIO mmap setup */
|
/* GPIO mmap setup */
|
||||||
if (!getuid()) {
|
if (!getuid()) {
|
||||||
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
||||||
return msg (MSG_ERR,
|
msg (MSG_ERR,
|
||||||
"wiringPiSetup: Unable to open /dev/mem: %s\n",
|
"wiringPiSetup: Unable to open /dev/mem: %s\n",
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
} else {
|
} else {
|
||||||
if (access("/dev/gpiomem",0) == 0) {
|
if (access("/dev/gpiomem",0) == 0) {
|
||||||
if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
||||||
return msg (MSG_ERR,
|
msg (MSG_ERR,
|
||||||
"wiringPiSetup: Unable to open /dev/gpiomem: %s\n",
|
"wiringPiSetup: Unable to open /dev/gpiomem: %s\n",
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
} else
|
} else
|
||||||
return msg (MSG_ERR,
|
msg (MSG_ERR,
|
||||||
"wiringPiSetup: /dev/gpiomem doesn't exist. Please try again with sudo.\n");
|
"wiringPiSetup: /dev/gpiomem doesn't exist. Please try again with sudo.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
//#define C2_GPIO_BASE 0xC8834000
|
|
||||||
gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
|
|
||||||
MAP_SHARED, fd, C2_GPIO_BASE) ;
|
|
||||||
|
|
||||||
if ((int32_t)gpio == -1)
|
|
||||||
return msg (MSG_ERR,
|
if (fd < 0) {
|
||||||
"wiringPiSetup: mmap (GPIO) failed: %s\n",
|
msg(MSG_ERR, "wiringPiSetup: Cannot open memory area for GPIO use. \n");
|
||||||
strerror (errno));
|
} else {
|
||||||
|
//#define C2_GPIO_BASE 0xC8834000
|
||||||
|
mapped = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, C2_GPIO_BASE);
|
||||||
|
|
||||||
|
if (mapped == MAP_FAILED)
|
||||||
|
msg(MSG_ERR, "wiringPiSetup: mmap (GPIO) failed: %s \n", strerror (errno));
|
||||||
|
else
|
||||||
|
gpio = (uint32_t *) mapped;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ static const int phyToGpio[64] = {
|
|||||||
//
|
//
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* ADC file descriptor */
|
/* ADC file descriptor */
|
||||||
static char *adcFds[2];
|
static int adcFds[2];
|
||||||
|
|
||||||
/* GPIO mmap control. Actual GPIO bank number. */
|
/* GPIO mmap control. Actual GPIO bank number. */
|
||||||
static volatile uint32_t *gpio[5];
|
static volatile uint32_t *gpio[5];
|
||||||
@@ -114,13 +114,13 @@ static void setIomuxMode (int pin, int mode);
|
|||||||
// wiringPi core function
|
// wiringPi core function
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int _getModeToGpio (int mode, int pin);
|
static int _getModeToGpio (int mode, int pin);
|
||||||
static void _pinMode (int pin, int mode);
|
static int _pinMode (int pin, int mode);
|
||||||
static int _getAlt (int pin);
|
static int _getAlt (int pin);
|
||||||
static void _pullUpDnControl (int pin, int pud);
|
static int _pullUpDnControl (int pin, int pud);
|
||||||
static int _digitalRead (int pin);
|
static int _digitalRead (int pin);
|
||||||
static void _digitalWrite (int pin, int value);
|
static int _digitalWrite (int pin, int value);
|
||||||
static int _analogRead (int pin);
|
static int _analogRead (int pin);
|
||||||
static void _digitalWriteByte (const int value);
|
static int _digitalWriteByte (const unsigned int value);
|
||||||
static unsigned int _digitalReadByte (void);
|
static unsigned int _digitalReadByte (void);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -263,16 +263,16 @@ static void setIomuxMode (int pin, int mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _pinMode (int pin, int mode)
|
static int _pinMode (int pin, int mode)
|
||||||
{
|
{
|
||||||
int origPin, bank;
|
int origPin, bank;
|
||||||
unsigned long UNU flags;
|
unsigned long UNU flags;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
origPin = pin;
|
origPin = pin;
|
||||||
bank = pin / 32;
|
bank = pin / 32;
|
||||||
@@ -298,10 +298,12 @@ static void _pinMode (int pin, int mode)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
msg(MSG_WARN, "%s : Unknown Mode %d\n", __func__, mode);
|
msg(MSG_WARN, "%s : Unknown Mode %d\n", __func__, mode);
|
||||||
break;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
setClkState (pin, N1_CLK_DISABLE);
|
setClkState (pin, N1_CLK_DISABLE);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -312,10 +314,10 @@ static int _getAlt (int pin)
|
|||||||
uint8_t ret = 0;
|
uint8_t ret = 0;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return 2;
|
return -1;
|
||||||
|
|
||||||
bank = pin / 32;
|
bank = pin / 32;
|
||||||
group = (pin - bank * 32) / 8;
|
group = (pin - bank * 32) / 8;
|
||||||
@@ -347,16 +349,16 @@ static int _getAlt (int pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _pullUpDnControl (int pin, int pud)
|
static int _pullUpDnControl (int pin, int pud)
|
||||||
{
|
{
|
||||||
uint32_t offset, target;
|
uint32_t offset, target;
|
||||||
uint8_t bank, group;
|
uint8_t bank, group;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return 2;
|
return -1;
|
||||||
|
|
||||||
bank = pin / 32;
|
bank = pin / 32;
|
||||||
group = (pin - bank * 32) / 8;
|
group = (pin - bank * 32) / 8;
|
||||||
@@ -441,6 +443,8 @@ static void _pullUpDnControl (int pin, int pud)
|
|||||||
}
|
}
|
||||||
|
|
||||||
setClkState(pin, N1_CLK_DISABLE);
|
setClkState(pin, N1_CLK_DISABLE);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -451,16 +455,19 @@ static int _digitalRead (int pin)
|
|||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS) {
|
if (lib->mode == MODE_GPIO_SYS) {
|
||||||
if (lib->sysFds[pin] == -1)
|
if (lib->sysFds[pin] == -1)
|
||||||
return LOW;
|
return -1;
|
||||||
|
|
||||||
lseek (lib->sysFds[pin], 0L, SEEK_SET);
|
lseek (lib->sysFds[pin], 0L, SEEK_SET);
|
||||||
read (lib->sysFds[pin], &c, 1);
|
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;
|
return (c == '0') ? LOW : HIGH;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
bank = pin / 32;
|
bank = pin / 32;
|
||||||
setClkState(pin, N1_CLK_ENABLE);
|
setClkState(pin, N1_CLK_ENABLE);
|
||||||
@@ -472,7 +479,7 @@ static int _digitalRead (int pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _digitalWrite (int pin, int value)
|
static int _digitalWrite (int pin, int value)
|
||||||
{
|
{
|
||||||
int bank;
|
int bank;
|
||||||
|
|
||||||
@@ -490,11 +497,11 @@ static void _digitalWrite (int pin, int value)
|
|||||||
__func__, strerror(errno), pin + N1_GPIO_PIN_BASE);
|
__func__, strerror(errno), pin + N1_GPIO_PIN_BASE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
bank = pin / 32;
|
bank = pin / 32;
|
||||||
setClkState(pin, N1_CLK_ENABLE);
|
setClkState(pin, N1_CLK_ENABLE);
|
||||||
@@ -511,15 +518,17 @@ static void _digitalWrite (int pin, int value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
setClkState(pin, N1_CLK_DISABLE);
|
setClkState(pin, N1_CLK_DISABLE);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int _analogRead (int pin)
|
static int _analogRead (int pin)
|
||||||
{
|
{
|
||||||
unsigned char value[5] = {0,};
|
char value[5] = {0,};
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
/* wiringPi ADC number = pin 25, pin 29 */
|
/* wiringPi ADC number = pin 25, pin 29 */
|
||||||
switch (pin) {
|
switch (pin) {
|
||||||
@@ -545,19 +554,22 @@ static int _analogRead (int pin)
|
|||||||
if (adcFds [pin] == -1)
|
if (adcFds [pin] == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
lseek (adcFds [pin], 0L, SEEK_SET);
|
lseek(adcFds [pin], 0L, SEEK_SET);
|
||||||
read (adcFds [pin], &value[0], 4);
|
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);
|
return atoi(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _digitalWriteByte (const int value)
|
static int _digitalWriteByte (const unsigned int value)
|
||||||
{
|
{
|
||||||
union reg_bitfield gpioBits1;
|
union reg_bitfield gpioBits1;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS) {
|
if (lib->mode == MODE_GPIO_SYS) {
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable clock for GPIO 1 bank
|
// Enable clock for GPIO 1 bank
|
||||||
@@ -587,6 +599,8 @@ static void _digitalWriteByte (const int value)
|
|||||||
*(gpio[1] + (N1_GPIO_SET_OFFSET >> 2)) = gpioBits1.wvalue;
|
*(gpio[1] + (N1_GPIO_SET_OFFSET >> 2)) = gpioBits1.wvalue;
|
||||||
|
|
||||||
setClkState(32, N1_CLK_DISABLE);
|
setClkState(32, N1_CLK_DISABLE);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -638,90 +652,98 @@ static unsigned int _digitalReadByte (void)
|
|||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void init_gpio_mmap (void)
|
static void init_gpio_mmap (void)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd = -1;
|
||||||
|
void *mapped_cru[2], *mapped_grf[2], *mapped_gpio[5];
|
||||||
|
|
||||||
/* GPIO mmap setup */
|
/* GPIO mmap setup */
|
||||||
if (!getuid()) {
|
if (!getuid()) {
|
||||||
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
||||||
return msg (MSG_ERR,
|
msg (MSG_ERR,
|
||||||
"wiringPiSetup: Unable to open /dev/mem: %s\n",
|
"wiringPiSetup: Unable to open /dev/mem: %s\n",
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
} else {
|
} else {
|
||||||
if (access("/dev/gpiomem",0) == 0) {
|
if (access("/dev/gpiomem",0) == 0) {
|
||||||
if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
||||||
return msg (MSG_ERR,
|
msg (MSG_ERR,
|
||||||
"wiringPiSetup: Unable to open /dev/gpiomem: %s\n",
|
"wiringPiSetup: Unable to open /dev/gpiomem: %s\n",
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
} else
|
} else
|
||||||
return msg (MSG_ERR,
|
msg (MSG_ERR,
|
||||||
"wiringPiSetup: /dev/gpiomem doesn't exist. Please try again with sudo.\n");
|
"wiringPiSetup: /dev/gpiomem doesn't exist. Please try again with sudo.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// GPIO{0, 1}
|
if (fd < 0) {
|
||||||
//#define ODROIDN1_PMUCRU_BASE 0xFF750000
|
msg(MSG_ERR, "wiringPiSetup: Cannot open memory area for GPIO use. \n");
|
||||||
cru[0] = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
|
} else {
|
||||||
MAP_SHARED, fd, N1_PMUCRU_BASE) ;
|
// GPIO{0, 1}
|
||||||
|
//#define ODROIDN1_PMUCRU_BASE 0xFF750000
|
||||||
|
mapped_cru[0] = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, N1_PMUCRU_BASE);
|
||||||
|
|
||||||
// GPIO{2, 3, 4}
|
// GPIO{2, 3, 4}
|
||||||
//#define ODROIDN1_CRU_BASE 0xFF760000
|
//#define ODROIDN1_CRU_BASE 0xFF760000
|
||||||
cru[1] = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
|
mapped_cru[1] = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, N1_CRU_BASE);
|
||||||
MAP_SHARED, fd, N1_CRU_BASE) ;
|
|
||||||
|
|
||||||
// GPIO{0, 1}
|
// GPIO{0, 1}
|
||||||
//#define ODROIDN1_PMU_BASE 0xFF320000
|
//#define ODROIDN1_PMU_BASE 0xFF320000
|
||||||
grf[0] = (uint32_t *)mmap(0, N1_GRF_BLOCK_SIZE, PROT_READ|PROT_WRITE,
|
mapped_grf[0] = mmap(0, N1_GRF_BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, N1_PMUGRF_BASE);
|
||||||
MAP_SHARED, fd, N1_PMUGRF_BASE) ;
|
|
||||||
|
|
||||||
// GPIO{2, 3, 4}
|
// GPIO{2, 3, 4}
|
||||||
//#define ODROIDN1_GRF_BASE 0xFF770000
|
//#define ODROIDN1_GRF_BASE 0xFF770000
|
||||||
grf[1] = (uint32_t *)mmap(0, N1_GRF_BLOCK_SIZE, PROT_READ|PROT_WRITE,
|
mapped_grf[1] = mmap(0, N1_GRF_BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, N1_GRF_BASE);
|
||||||
MAP_SHARED, fd, N1_GRF_BASE) ;
|
|
||||||
|
|
||||||
// GPIO1_A. 0,1,2,3,4,7
|
// GPIO1_A. 0,1,2,3,4,7
|
||||||
// GPIO1_B. 0,1,2,3,4,5
|
// GPIO1_B. 0,1,2,3,4,5
|
||||||
// GPIO1_C. 2,4,5,6
|
// GPIO1_C. 2,4,5,6
|
||||||
// GPIO1_D. 0
|
// GPIO1_D. 0
|
||||||
//#define ODROIDN1_GPIO1_BASE 0xFF730000
|
//#define ODROIDN1_GPIO1_BASE 0xFF730000
|
||||||
gpio[1] = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
|
mapped_gpio[1] = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, N1_GPIO_1_BASE);
|
||||||
MAP_SHARED, fd, N1_GPIO_1_BASE) ;
|
|
||||||
|
|
||||||
// GPIO2_C. 0_B,1_B
|
// GPIO2_C. 0_B,1_B
|
||||||
//#define ODROIDN1_GPIO2_BASE 0xFF780000
|
//#define ODROIDN1_GPIO2_BASE 0xFF780000
|
||||||
gpio[2] = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
|
mapped_gpio[2] = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, N1_GPIO_2_BASE);
|
||||||
MAP_SHARED, fd, N1_GPIO_2_BASE) ;
|
|
||||||
|
|
||||||
// GPIO4_C. 5,6
|
// GPIO4_C. 5,6
|
||||||
// GPIO4_D. 0,4,5,6
|
// GPIO4_D. 0,4,5,6
|
||||||
//#define ODROIDN1_GPIO4_BASE 0xFF790000
|
//#define ODROIDN1_GPIO4_BASE 0xFF790000
|
||||||
gpio[4] = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
|
mapped_gpio[4] = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, N1_GPIO_4_BASE);
|
||||||
MAP_SHARED, fd, N1_GPIO_4_BASE) ;
|
|
||||||
|
|
||||||
// Reserved
|
// Reserved
|
||||||
gpio[0] = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
|
mapped_gpio[0] = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, N1_GPIO_0_BASE);
|
||||||
MAP_SHARED, fd, N1_GPIO_0_BASE) ;
|
mapped_gpio[3] = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, N1_GPIO_3_BASE);
|
||||||
gpio[3] = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
|
|
||||||
MAP_SHARED, fd, N1_GPIO_3_BASE) ;
|
|
||||||
|
|
||||||
if (((int32_t)cru[0] == -1) || ((int32_t)cru[1] == -1)) {
|
if ((mapped_cru[0] == MAP_FAILED) || (mapped_cru[1] == MAP_FAILED)) {
|
||||||
return msg (MSG_ERR,
|
msg (MSG_ERR,
|
||||||
"wiringPiSetup: mmap (CRU) failed: %s\n",
|
"wiringPiSetup: mmap (CRU) failed: %s\n",
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
}
|
} else {
|
||||||
|
cru[0] = (uint32_t *) mapped_cru[0];
|
||||||
|
cru[1] = (uint32_t *) mapped_cru[1];
|
||||||
|
}
|
||||||
|
|
||||||
if (((int32_t)grf[0] == -1) || ((int32_t)grf[1] == -1)) {
|
if ((mapped_grf[0] == MAP_FAILED) || (mapped_grf[1] == MAP_FAILED)) {
|
||||||
return msg (MSG_ERR,
|
msg (MSG_ERR,
|
||||||
"wiringPiSetup: mmap (GRF) failed: %s\n",
|
"wiringPiSetup: mmap (GRF) failed: %s\n",
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
}
|
} else {
|
||||||
|
grf[0] = (uint32_t *) mapped_grf[0];
|
||||||
|
grf[1] = (uint32_t *) mapped_grf[1];
|
||||||
|
}
|
||||||
|
|
||||||
if ( ((int32_t)gpio[0] == -1) ||
|
if ( (mapped_gpio[0] == MAP_FAILED) ||
|
||||||
((int32_t)gpio[1] == -1) ||
|
(mapped_gpio[1] == MAP_FAILED) ||
|
||||||
((int32_t)gpio[2] == -1) ||
|
(mapped_gpio[2] == MAP_FAILED) ||
|
||||||
((int32_t)gpio[3] == -1) ||
|
(mapped_gpio[3] == MAP_FAILED) ||
|
||||||
((int32_t)gpio[4] == -1)) {
|
(mapped_gpio[4] == MAP_FAILED)) {
|
||||||
return msg (MSG_ERR,
|
msg (MSG_ERR,
|
||||||
"wiringPiSetup: mmap (GPIO) failed: %s\n",
|
"wiringPiSetup: mmap (GPIO) failed: %s\n",
|
||||||
strerror (errno));
|
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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,10 +93,10 @@ static const int phyToGpio_rev1[64] = {
|
|||||||
const int *pinToGpio, *phyToGpio;
|
const int *pinToGpio, *phyToGpio;
|
||||||
|
|
||||||
/* ADC file descriptor */
|
/* ADC file descriptor */
|
||||||
static char *adcFds[2];
|
static int adcFds[2];
|
||||||
|
|
||||||
/* GPIO mmap control */
|
/* GPIO mmap control */
|
||||||
static volatile uint32_t *gpio, *gpio1;
|
static volatile uint32_t *gpio;
|
||||||
|
|
||||||
/* wiringPi Global library */
|
/* wiringPi Global library */
|
||||||
static struct libodroid *lib = NULL;
|
static struct libodroid *lib = NULL;
|
||||||
@@ -117,16 +117,16 @@ static int gpioToMuxReg (int pin);
|
|||||||
// wiringPi core function
|
// wiringPi core function
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int _getModeToGpio (int mode, int pin);
|
static int _getModeToGpio (int mode, int pin);
|
||||||
static void _setPadDrive (int pin, int value);
|
static int _setPadDrive (int pin, int value);
|
||||||
static int _getPadDrive (int pin);
|
static int _getPadDrive (int pin);
|
||||||
static void _pinMode (int pin, int mode);
|
static int _pinMode (int pin, int mode);
|
||||||
static int _getAlt (int pin);
|
static int _getAlt (int pin);
|
||||||
static int _getPUPD (int pin);
|
static int _getPUPD (int pin);
|
||||||
static void _pullUpDnControl (int pin, int pud);
|
static int _pullUpDnControl (int pin, int pud);
|
||||||
static int _digitalRead (int pin);
|
static int _digitalRead (int pin);
|
||||||
static void _digitalWrite (int pin, int value);
|
static int _digitalWrite (int pin, int value);
|
||||||
static int _analogRead (int pin);
|
static int _analogRead (int pin);
|
||||||
static void _digitalWriteByte (const int value);
|
static int _digitalWriteByte (const unsigned int value);
|
||||||
static unsigned int _digitalReadByte (void);
|
static unsigned int _digitalReadByte (void);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -292,19 +292,19 @@ static int _getModeToGpio (int mode, int pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _setPadDrive (int pin, int value)
|
static int _setPadDrive (int pin, int value)
|
||||||
{
|
{
|
||||||
int ds, shift;
|
int ds, shift;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if (value < 0 || value > 3) {
|
if (value < 0 || value > 3) {
|
||||||
msg(MSG_WARN, "%s : Invalid value %d (Must be 0 ~ 3)\n", __func__, value);
|
msg(MSG_WARN, "%s : Invalid value %d (Must be 0 ~ 3)\n", __func__, value);
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ds = gpioToDSReg(pin);
|
ds = gpioToDSReg(pin);
|
||||||
@@ -313,6 +313,8 @@ static void _setPadDrive (int pin, int value)
|
|||||||
|
|
||||||
*(gpio + ds) &= ~(0b11 << shift);
|
*(gpio + ds) &= ~(0b11 << shift);
|
||||||
*(gpio + ds) |= (value << shift);
|
*(gpio + ds) |= (value << shift);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -321,10 +323,10 @@ static int _getPadDrive (int pin)
|
|||||||
int ds, shift;
|
int ds, shift;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
ds = gpioToDSReg(pin);
|
ds = gpioToDSReg(pin);
|
||||||
shift = gpioToShiftReg(pin);
|
shift = gpioToShiftReg(pin);
|
||||||
@@ -334,15 +336,15 @@ static int _getPadDrive (int pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _pinMode (int pin, int mode)
|
static int _pinMode (int pin, int mode)
|
||||||
{
|
{
|
||||||
int fsel, shift, origPin = pin;
|
int fsel, shift, origPin = pin;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
softPwmStop (origPin);
|
softPwmStop (origPin);
|
||||||
softToneStop (origPin);
|
softToneStop (origPin);
|
||||||
@@ -353,20 +355,22 @@ static void _pinMode (int pin, int mode)
|
|||||||
switch (mode) {
|
switch (mode) {
|
||||||
case INPUT:
|
case INPUT:
|
||||||
*(gpio + fsel) = (*(gpio + fsel) | (1 << shift));
|
*(gpio + fsel) = (*(gpio + fsel) | (1 << shift));
|
||||||
break;
|
break;
|
||||||
case OUTPUT:
|
case OUTPUT:
|
||||||
*(gpio + fsel) = (*(gpio + fsel) & ~(1 << shift));
|
*(gpio + fsel) = (*(gpio + fsel) & ~(1 << shift));
|
||||||
break;
|
break;
|
||||||
case SOFT_PWM_OUTPUT:
|
case SOFT_PWM_OUTPUT:
|
||||||
softPwmCreate (origPin, 0, 100);
|
softPwmCreate (origPin, 0, 100);
|
||||||
break;
|
break;
|
||||||
case SOFT_TONE_OUTPUT:
|
case SOFT_TONE_OUTPUT:
|
||||||
softToneCreate (origPin);
|
softToneCreate (origPin);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
msg(MSG_WARN, "%s : Unknown Mode %d\n", __func__, mode);
|
msg(MSG_WARN, "%s : Unknown Mode %d\n", __func__, mode);
|
||||||
break;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -375,10 +379,10 @@ static int _getAlt (int pin)
|
|||||||
int fsel, mux, shift, target, mode;
|
int fsel, mux, shift, target, mode;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return 2;
|
return -1;
|
||||||
|
|
||||||
fsel = gpioToGPFSELReg(pin);
|
fsel = gpioToGPFSELReg(pin);
|
||||||
mux = gpioToMuxReg(pin);
|
mux = gpioToMuxReg(pin);
|
||||||
@@ -398,10 +402,10 @@ static int _getPUPD (int pin)
|
|||||||
int puen, pupd, shift;
|
int puen, pupd, shift;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
puen = gpioToPUENReg(pin);
|
puen = gpioToPUENReg(pin);
|
||||||
pupd = gpioToPUPDReg(pin);
|
pupd = gpioToPUPDReg(pin);
|
||||||
@@ -414,15 +418,15 @@ static int _getPUPD (int pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _pullUpDnControl (int pin, int pud)
|
static int _pullUpDnControl (int pin, int pud)
|
||||||
{
|
{
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
shift = gpioToShiftReg(pin);
|
shift = gpioToShiftReg(pin);
|
||||||
|
|
||||||
@@ -440,6 +444,8 @@ static void _pullUpDnControl (int pin, int pud)
|
|||||||
} else // Disable Pull/Pull-down resister
|
} else // Disable Pull/Pull-down resister
|
||||||
*(gpio + gpioToPUENReg(pin)) =
|
*(gpio + gpioToPUENReg(pin)) =
|
||||||
(*(gpio + gpioToPUENReg(pin)) & ~(1 << shift));
|
(*(gpio + gpioToPUENReg(pin)) & ~(1 << shift));
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -449,16 +455,19 @@ static int _digitalRead (int pin)
|
|||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS) {
|
if (lib->mode == MODE_GPIO_SYS) {
|
||||||
if (lib->sysFds[pin] == -1)
|
if (lib->sysFds[pin] == -1)
|
||||||
return LOW ;
|
return -1;
|
||||||
|
|
||||||
lseek (lib->sysFds[pin], 0L, SEEK_SET);
|
lseek (lib->sysFds[pin], 0L, SEEK_SET);
|
||||||
read (lib->sysFds[pin], &c, 1);
|
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;
|
return (c == '0') ? LOW : HIGH;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
if ((*(gpio + gpioToGPLEVReg(pin)) & (1 << gpioToShiftReg(pin))) != 0)
|
if ((*(gpio + gpioToGPLEVReg(pin)) & (1 << gpioToShiftReg(pin))) != 0)
|
||||||
return HIGH ;
|
return HIGH ;
|
||||||
@@ -467,34 +476,39 @@ static int _digitalRead (int pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _digitalWrite (int pin, int value)
|
static int _digitalWrite (int pin, int value)
|
||||||
{
|
{
|
||||||
if (lib->mode == MODE_GPIO_SYS) {
|
if (lib->mode == MODE_GPIO_SYS) {
|
||||||
if (lib->sysFds[pin] != -1) {
|
if (lib->sysFds[pin] != -1) {
|
||||||
if (value == LOW)
|
if (value == LOW) {
|
||||||
write (lib->sysFds[pin], "0\n", 2);
|
if (write(lib->sysFds[pin], "0\n", 2) < 0)
|
||||||
else
|
msg(MSG_WARN, "%s: Failed with reading from sysfs GPIO node. \n", __func__);
|
||||||
write (lib->sysFds[pin], "1\n", 2);
|
} else {
|
||||||
|
if (write(lib->sysFds[pin], "1\n", 2) < 0)
|
||||||
|
msg(MSG_WARN, "%s: Failed with reading from sysfs GPIO node. \n", __func__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if (value == LOW)
|
if (value == LOW)
|
||||||
*(gpio + gpioToGPSETReg(pin)) &= ~(1 << gpioToShiftReg(pin));
|
*(gpio + gpioToGPSETReg(pin)) &= ~(1 << gpioToShiftReg(pin));
|
||||||
else
|
else
|
||||||
*(gpio + gpioToGPSETReg(pin)) |= (1 << gpioToShiftReg(pin));
|
*(gpio + gpioToGPSETReg(pin)) |= (1 << gpioToShiftReg(pin));
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int _analogRead (int pin)
|
static int _analogRead (int pin)
|
||||||
{
|
{
|
||||||
unsigned char value[5] = {0,};
|
char value[5] = {0,};
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
/* wiringPi ADC number = pin 25, pin 29 */
|
/* wiringPi ADC number = pin 25, pin 29 */
|
||||||
switch (pin) {
|
switch (pin) {
|
||||||
@@ -520,14 +534,17 @@ static int _analogRead (int pin)
|
|||||||
if (adcFds [pin] == -1)
|
if (adcFds [pin] == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
lseek (adcFds [pin], 0L, SEEK_SET);
|
lseek(adcFds [pin], 0L, SEEK_SET);
|
||||||
read (adcFds [pin], &value[0], 4);
|
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);
|
return atoi(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _digitalWriteByte (const int value)
|
static int _digitalWriteByte (const unsigned int value)
|
||||||
{
|
{
|
||||||
union reg_bitfield gpiox;
|
union reg_bitfield gpiox;
|
||||||
union reg_bitfield gpioa;
|
union reg_bitfield gpioa;
|
||||||
@@ -554,6 +571,8 @@ static void _digitalWriteByte (const int value)
|
|||||||
|
|
||||||
*(gpio + N2_GPIOX_OUTP_REG_OFFSET) = gpiox.wvalue;
|
*(gpio + N2_GPIOX_OUTP_REG_OFFSET) = gpiox.wvalue;
|
||||||
*(gpio + N2_GPIOA_OUTP_REG_OFFSET) = gpioa.wvalue;
|
*(gpio + N2_GPIOA_OUTP_REG_OFFSET) = gpioa.wvalue;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -565,33 +584,37 @@ static unsigned int _digitalReadByte (void)
|
|||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void init_gpio_mmap (void)
|
static void init_gpio_mmap (void)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd = -1;
|
||||||
|
void *mapped;
|
||||||
|
|
||||||
/* GPIO mmap setup */
|
/* GPIO mmap setup */
|
||||||
if (!getuid()) {
|
if (!getuid()) {
|
||||||
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
||||||
return msg (MSG_ERR,
|
msg(MSG_ERR,
|
||||||
"wiringPiSetup: Unable to open /dev/mem: %s\n",
|
"wiringPiSetup: Unable to open /dev/mem: %s\n",
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
} else {
|
} else {
|
||||||
if (access("/dev/gpiomem",0) == 0) {
|
if (access("/dev/gpiomem",0) == 0) {
|
||||||
if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
||||||
return msg (MSG_ERR,
|
msg(MSG_ERR,
|
||||||
"wiringPiSetup: Unable to open /dev/gpiomem: %s\n",
|
"wiringPiSetup: Unable to open /dev/gpiomem: %s\n",
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
} else
|
} else
|
||||||
return msg (MSG_ERR,
|
msg(MSG_ERR,
|
||||||
"wiringPiSetup: /dev/gpiomem doesn't exist. Please try again with sudo.\n");
|
"wiringPiSetup: /dev/gpiomem doesn't exist. Please try again with sudo.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
//#define N2_GPIO_BASE 0xff634000
|
if (fd < 0) {
|
||||||
gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
|
msg(MSG_ERR, "wiringPiSetup: Cannot open memory area for GPIO use. \n");
|
||||||
MAP_SHARED, fd, N2_GPIO_BASE) ;
|
} else {
|
||||||
|
//#define N2_GPIO_BASE 0xff634000
|
||||||
|
mapped = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, N2_GPIO_BASE);
|
||||||
|
|
||||||
if ((int32_t)gpio == -1)
|
if (mapped == MAP_FAILED)
|
||||||
return msg (MSG_ERR,
|
msg(MSG_ERR, "wiringPiSetup: mmap (GPIO) failed: %s \n", strerror (errno));
|
||||||
"wiringPiSetup: mmap (GPIO) failed: %s\n",
|
else
|
||||||
strerror (errno));
|
gpio = (uint32_t *) mapped;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ static const int phyToGpio[64] = {
|
|||||||
//
|
//
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* ADC file descriptor */
|
/* ADC file descriptor */
|
||||||
static char *adcFds[2];
|
static int adcFds[2];
|
||||||
|
|
||||||
/* GPIO mmap control */
|
/* GPIO mmap control */
|
||||||
static volatile uint32_t *gpio, *gpio1;
|
static volatile uint32_t *gpio, *gpio1;
|
||||||
@@ -99,7 +99,6 @@ static struct libodroid *lib = NULL;
|
|||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
// Function prototype define
|
// Function prototype define
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int gpioToGPSETReg (int pin);
|
|
||||||
static int gpioToGPLEVReg (int pin);
|
static int gpioToGPLEVReg (int pin);
|
||||||
static int gpioToPUPDReg (int pin);
|
static int gpioToPUPDReg (int pin);
|
||||||
static int gpioToShiftReg (int pin);
|
static int gpioToShiftReg (int pin);
|
||||||
@@ -110,16 +109,16 @@ static int gpioToDSReg (int pin);
|
|||||||
// wiringPi core function
|
// wiringPi core function
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int _getModeToGpio (int mode, int pin);
|
static int _getModeToGpio (int mode, int pin);
|
||||||
static void _setPadDrive (int pin, int value);
|
static int _setPadDrive (int pin, int value);
|
||||||
static int _getPadDrive (int pin);
|
static int _getPadDrive (int pin);
|
||||||
static void _pinMode (int pin, int mode);
|
static int _pinMode (int pin, int mode);
|
||||||
static int _getAlt (int pin);
|
static int _getAlt (int pin);
|
||||||
static int _getPUPD (int pin);
|
static int _getPUPD (int pin);
|
||||||
static void _pullUpDnControl (int pin, int pud);
|
static int _pullUpDnControl (int pin, int pud);
|
||||||
static int _digitalRead (int pin);
|
static int _digitalRead (int pin);
|
||||||
static void _digitalWrite (int pin, int value);
|
static int _digitalWrite (int pin, int value);
|
||||||
static int _analogRead (int pin);
|
static int _analogRead (int pin);
|
||||||
static void _digitalWriteByte (const int value);
|
static int _digitalWriteByte (const unsigned int value);
|
||||||
static unsigned int _digitalReadByte (void);
|
static unsigned int _digitalReadByte (void);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -130,31 +129,6 @@ static void init_adc_fds (void);
|
|||||||
void init_odroidxu3 (struct libodroid *libwiring);
|
void init_odroidxu3 (struct libodroid *libwiring);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/*----------------------------------------------------------------------------*/
|
|
||||||
//
|
|
||||||
// offset to the GPIO Set regsiter
|
|
||||||
//
|
|
||||||
/*----------------------------------------------------------------------------*/
|
|
||||||
static int gpioToGPSETReg (int pin)
|
|
||||||
{
|
|
||||||
switch (pin) {
|
|
||||||
case XU3_GPIO_X1_START...XU3_GPIO_X1_END:
|
|
||||||
return (XU3_GPIO_X1_DAT_OFFSET >> 2);
|
|
||||||
case XU3_GPIO_X2_START...XU3_GPIO_X2_END:
|
|
||||||
return (XU3_GPIO_X2_DAT_OFFSET >> 2);
|
|
||||||
case XU3_GPIO_X3_START...XU3_GPIO_X3_END:
|
|
||||||
return (XU3_GPIO_X3_DAT_OFFSET >> 2);
|
|
||||||
case XU3_GPIO_A0_START...XU3_GPIO_A0_END:
|
|
||||||
return (XU3_GPIO_A0_DAT_OFFSET >> 2);
|
|
||||||
case XU3_GPIO_A2_START...XU3_GPIO_A2_END:
|
|
||||||
return (XU3_GPIO_A2_DAT_OFFSET >> 2);
|
|
||||||
case XU3_GPIO_B3_START...XU3_GPIO_B3_END:
|
|
||||||
return (XU3_GPIO_B3_DAT_OFFSET >> 2);
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
//
|
//
|
||||||
@@ -310,19 +284,19 @@ static int _getModeToGpio (int mode, int pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _setPadDrive (int pin, int value)
|
static int _setPadDrive (int pin, int value)
|
||||||
{
|
{
|
||||||
int ds, shift;
|
int ds, shift;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if (value < 0 || value > 3) {
|
if (value < 0 || value > 3) {
|
||||||
msg(MSG_WARN, "%s : Invalid value %d (Must be 0 ~ 3)\n", __func__, value);
|
msg(MSG_WARN, "%s : Invalid value %d (Must be 0 ~ 3)\n", __func__, value);
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ds = gpioToDSReg(pin);
|
ds = gpioToDSReg(pin);
|
||||||
@@ -335,6 +309,8 @@ static void _setPadDrive (int pin, int value)
|
|||||||
*(gpio1 + ds) &= ~(0b11 << shift);
|
*(gpio1 + ds) &= ~(0b11 << shift);
|
||||||
*(gpio1 + ds) |= (value << shift);
|
*(gpio1 + ds) |= (value << shift);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -343,10 +319,10 @@ static int _getPadDrive (int pin)
|
|||||||
int ds, shift;
|
int ds, shift;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
ds = gpioToDSReg(pin);
|
ds = gpioToDSReg(pin);
|
||||||
shift = gpioToShiftReg(pin) << 1;
|
shift = gpioToShiftReg(pin) << 1;
|
||||||
@@ -358,15 +334,15 @@ static int _getPadDrive (int pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _pinMode (int pin, int mode)
|
static int _pinMode (int pin, int mode)
|
||||||
{
|
{
|
||||||
int fsel, shift, origPin = pin;
|
int fsel, shift, origPin = pin;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
softPwmStop (origPin);
|
softPwmStop (origPin);
|
||||||
softToneStop (origPin);
|
softToneStop (origPin);
|
||||||
@@ -380,7 +356,7 @@ static void _pinMode (int pin, int mode)
|
|||||||
*(gpio + fsel) &= ~(0xF << shift);
|
*(gpio + fsel) &= ~(0xF << shift);
|
||||||
else
|
else
|
||||||
*(gpio1 + fsel) &= ~(0xF << shift);
|
*(gpio1 + fsel) &= ~(0xF << shift);
|
||||||
break;
|
break;
|
||||||
case OUTPUT:
|
case OUTPUT:
|
||||||
if(pin < 100) {
|
if(pin < 100) {
|
||||||
*(gpio + fsel) &= ~(0xF << shift);
|
*(gpio + fsel) &= ~(0xF << shift);
|
||||||
@@ -389,17 +365,19 @@ static void _pinMode (int pin, int mode)
|
|||||||
*(gpio1 + fsel) &= ~(0xF << shift);
|
*(gpio1 + fsel) &= ~(0xF << shift);
|
||||||
*(gpio1 + fsel) |= (0x1 << shift);
|
*(gpio1 + fsel) |= (0x1 << shift);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SOFT_PWM_OUTPUT:
|
case SOFT_PWM_OUTPUT:
|
||||||
softPwmCreate (origPin, 0, 100);
|
softPwmCreate (origPin, 0, 100);
|
||||||
break;
|
break;
|
||||||
case SOFT_TONE_OUTPUT:
|
case SOFT_TONE_OUTPUT:
|
||||||
softToneCreate (origPin);
|
softToneCreate (origPin);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
msg(MSG_WARN, "%s : Unknown Mode %d\n", __func__, mode);
|
msg(MSG_WARN, "%s : Unknown Mode %d\n", __func__, mode);
|
||||||
break;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -408,10 +386,10 @@ static int _getAlt (int pin)
|
|||||||
int fsel, shift, mode;
|
int fsel, shift, mode;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return 2;
|
return -1;
|
||||||
|
|
||||||
fsel = gpioToGPFSELReg(pin);
|
fsel = gpioToGPFSELReg(pin);
|
||||||
shift = gpioToShiftReg(pin) << 2;
|
shift = gpioToShiftReg(pin) << 2;
|
||||||
@@ -431,10 +409,10 @@ static int _getPUPD (int pin)
|
|||||||
int pupd, shift, pull;
|
int pupd, shift, pull;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
pupd = gpioToPUPDReg(pin);
|
pupd = gpioToPUPDReg(pin);
|
||||||
shift = gpioToShiftReg(pin) << 1;
|
shift = gpioToShiftReg(pin) << 1;
|
||||||
@@ -449,15 +427,15 @@ static int _getPUPD (int pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _pullUpDnControl (int pin, int pud)
|
static int _pullUpDnControl (int pin, int pud)
|
||||||
{
|
{
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
shift = gpioToShiftReg(pin) << 1;
|
shift = gpioToShiftReg(pin) << 1;
|
||||||
|
|
||||||
@@ -482,6 +460,8 @@ static void _pullUpDnControl (int pin, int pud)
|
|||||||
else
|
else
|
||||||
*(gpio1 + gpioToPUPDReg(pin)) &= ~(0x3 << shift);
|
*(gpio1 + gpioToPUPDReg(pin)) &= ~(0x3 << shift);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -491,16 +471,19 @@ static int _digitalRead (int pin)
|
|||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS) {
|
if (lib->mode == MODE_GPIO_SYS) {
|
||||||
if (lib->sysFds[pin] == -1)
|
if (lib->sysFds[pin] == -1)
|
||||||
return LOW ;
|
return -1;
|
||||||
|
|
||||||
lseek (lib->sysFds[pin], 0L, SEEK_SET);
|
lseek (lib->sysFds[pin], 0L, SEEK_SET);
|
||||||
read (lib->sysFds[pin], &c, 1);
|
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;
|
return (c == '0') ? LOW : HIGH;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
if (pin < 100)
|
if (pin < 100)
|
||||||
return *(gpio + gpioToGPLEVReg(pin)) & (1 << gpioToShiftReg(pin)) ? HIGH : LOW;
|
return *(gpio + gpioToGPLEVReg(pin)) & (1 << gpioToShiftReg(pin)) ? HIGH : LOW;
|
||||||
@@ -509,20 +492,23 @@ static int _digitalRead (int pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _digitalWrite (int pin, int value)
|
static int _digitalWrite (int pin, int value)
|
||||||
{
|
{
|
||||||
if (lib->mode == MODE_GPIO_SYS) {
|
if (lib->mode == MODE_GPIO_SYS) {
|
||||||
if (lib->sysFds[pin] != -1) {
|
if (lib->sysFds[pin] != -1) {
|
||||||
if (value == LOW)
|
if (value == LOW) {
|
||||||
write (lib->sysFds[pin], "0\n", 2);
|
if (write(lib->sysFds[pin], "0\n", 2) < 0)
|
||||||
else
|
msg(MSG_WARN, "%s: Failed with reading from sysfs GPIO node. \n", __func__);
|
||||||
write (lib->sysFds[pin], "1\n", 2);
|
} else {
|
||||||
|
if (write(lib->sysFds[pin], "1\n", 2) < 0)
|
||||||
|
msg(MSG_WARN, "%s: Failed with reading from sysfs GPIO node. \n", __func__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
if ((pin = _getModeToGpio(lib->mode, pin)) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if (pin < 100) {
|
if (pin < 100) {
|
||||||
if (value == LOW)
|
if (value == LOW)
|
||||||
@@ -535,15 +521,17 @@ static void _digitalWrite (int pin, int value)
|
|||||||
else
|
else
|
||||||
*(gpio1 + gpioToGPLEVReg(pin)) |= (1 << gpioToShiftReg(pin));
|
*(gpio1 + gpioToGPLEVReg(pin)) |= (1 << gpioToShiftReg(pin));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static int _analogRead (int pin)
|
static int _analogRead (int pin)
|
||||||
{
|
{
|
||||||
unsigned char value[5] = {0,};
|
char value[5] = {0,};
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS)
|
if (lib->mode == MODE_GPIO_SYS)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
/* wiringPi ADC number = pin 25, pin 29 */
|
/* wiringPi ADC number = pin 25, pin 29 */
|
||||||
switch (pin) {
|
switch (pin) {
|
||||||
@@ -569,19 +557,22 @@ static int _analogRead (int pin)
|
|||||||
if (adcFds [pin] == -1)
|
if (adcFds [pin] == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
lseek (adcFds [pin], 0L, SEEK_SET);
|
lseek(adcFds [pin], 0L, SEEK_SET);
|
||||||
read (adcFds [pin], &value[0], 4);
|
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);
|
return atoi(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void _digitalWriteByte (const int value)
|
static int _digitalWriteByte (const unsigned int value)
|
||||||
{
|
{
|
||||||
union reg_bitfield gpx1, gpx2, gpa0;
|
union reg_bitfield gpx1, gpx2, gpa0;
|
||||||
|
|
||||||
if (lib->mode == MODE_GPIO_SYS) {
|
if (lib->mode == MODE_GPIO_SYS) {
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
/* Read data register */
|
/* Read data register */
|
||||||
gpx1.wvalue = *(gpio + (XU3_GPIO_X1_DAT_OFFSET >> 2));
|
gpx1.wvalue = *(gpio + (XU3_GPIO_X1_DAT_OFFSET >> 2));
|
||||||
@@ -609,6 +600,8 @@ static void _digitalWriteByte (const int value)
|
|||||||
*(gpio + (XU3_GPIO_X1_DAT_OFFSET >> 2)) = gpx1.wvalue;
|
*(gpio + (XU3_GPIO_X1_DAT_OFFSET >> 2)) = gpx1.wvalue;
|
||||||
*(gpio + (XU3_GPIO_X2_DAT_OFFSET >> 2)) = gpx2.wvalue;
|
*(gpio + (XU3_GPIO_X2_DAT_OFFSET >> 2)) = gpx2.wvalue;
|
||||||
*(gpio1 + (XU3_GPIO_A0_DAT_OFFSET >> 2)) = gpa0.wvalue;
|
*(gpio1 + (XU3_GPIO_A0_DAT_OFFSET >> 2)) = gpa0.wvalue;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -656,35 +649,41 @@ static unsigned int _digitalReadByte (void)
|
|||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void init_gpio_mmap (void)
|
static void init_gpio_mmap (void)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd = -1;
|
||||||
|
void *mapped[2];
|
||||||
|
|
||||||
/* GPIO mmap setup */
|
/* GPIO mmap setup */
|
||||||
if (!getuid()) {
|
if (!getuid()) {
|
||||||
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
||||||
return msg (MSG_ERR,
|
msg (MSG_ERR,
|
||||||
"wiringPiSetup: Unable to open /dev/mem: %s\n",
|
"wiringPiSetup: Unable to open /dev/mem: %s\n",
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
} else {
|
} else {
|
||||||
if (access("/dev/gpiomem",0) == 0) {
|
if (access("/dev/gpiomem",0) == 0) {
|
||||||
if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
||||||
return msg (MSG_ERR,
|
msg (MSG_ERR,
|
||||||
"wiringPiSetup: Unable to open /dev/gpiomem: %s\n",
|
"wiringPiSetup: Unable to open /dev/gpiomem: %s\n",
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
} else
|
} else
|
||||||
return msg (MSG_ERR,
|
msg (MSG_ERR,
|
||||||
"wiringPiSetup: /dev/gpiomem doesn't exist. Please try again with sudo.\n");
|
"wiringPiSetup: /dev/gpiomem doesn't exist. Please try again with sudo.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
//#define ODROIDXU_GPX_BASE 0x13400000 // GPX0,1,2,3
|
if (fd < 0) {
|
||||||
gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
|
msg(MSG_ERR, "wiringPiSetup: Cannot open memory area for GPIO use. \n");
|
||||||
MAP_SHARED, fd, XU3_GPX_BASE) ;
|
} else {
|
||||||
//#define ODROIDXU_GPA_BASE 0x14010000 // GPA0,1,2, GPB0,1,2,3,4
|
//#define ODROIDXU_GPX_BASE 0x13400000 // GPX0,1,2,3
|
||||||
gpio1 = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE,
|
mapped[0] = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, XU3_GPX_BASE);
|
||||||
MAP_SHARED, fd, XU3_GPA_BASE) ;
|
//#define ODROIDXU_GPA_BASE 0x14010000 // GPA0,1,2, GPB0,1,2,3,4
|
||||||
if (((int32_t)gpio == -1) || ((int32_t)gpio1 == -1))
|
mapped[1] = mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, XU3_GPA_BASE);
|
||||||
return msg (MSG_ERR,
|
|
||||||
"wiringPiSetup: mmap (GPIO) failed: %s\n",
|
if (mapped[0] == MAP_FAILED || mapped[1] == MAP_FAILED) {
|
||||||
strerror (errno));
|
msg(MSG_ERR, "wiringPiSetup: mmap (GPIO) failed: %s \n", strerror (errno));
|
||||||
|
} else {
|
||||||
|
gpio = (uint32_t *) mapped[0];
|
||||||
|
gpio1 = (uint32_t *) mapped[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include "wiringPi.h"
|
#include "wiringPi.h"
|
||||||
#include "wiringPiI2C.h"
|
#include "wiringPiI2C.h"
|
||||||
@@ -41,7 +43,9 @@ static void myAnalogWrite (struct wiringPiNodeStruct *node, UNU int pin, int val
|
|||||||
unsigned char b [2] ;
|
unsigned char b [2] ;
|
||||||
b [0] = 0x40 ;
|
b [0] = 0x40 ;
|
||||||
b [1] = value & 0xFF ;
|
b [1] = value & 0xFF ;
|
||||||
write (node->fd, b, 2) ;
|
if (write(node->fd, b, 2) < 0) {
|
||||||
|
fprintf(stderr, "Unable to write to the file descriptor: %s \n", strerror(errno));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#define PSEUDO_PINS 64
|
#define PSEUDO_PINS 64
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -47,7 +48,7 @@
|
|||||||
|
|
||||||
static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
|
static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
|
||||||
{
|
{
|
||||||
int *ptr = (int *)node->data0 ;
|
int *ptr = (int *)(uintptr_t) node->data0 ;
|
||||||
int myPin = pin - node->pinBase ;
|
int myPin = pin - node->pinBase ;
|
||||||
|
|
||||||
return *(ptr + myPin) ;
|
return *(ptr + myPin) ;
|
||||||
@@ -56,7 +57,7 @@ static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
|
|||||||
|
|
||||||
static void myAnalogWrite (struct wiringPiNodeStruct *node, int pin, int value)
|
static void myAnalogWrite (struct wiringPiNodeStruct *node, int pin, int value)
|
||||||
{
|
{
|
||||||
int *ptr = (int *)node->data0 ;
|
int *ptr = (int *)(uintptr_t) node->data0 ;
|
||||||
int myPin = pin - node->pinBase ;
|
int myPin = pin - node->pinBase ;
|
||||||
|
|
||||||
*(ptr + myPin) = value ;
|
*(ptr + myPin) = value ;
|
||||||
@@ -86,7 +87,7 @@ int pseudoPinsSetup (const int pinBase)
|
|||||||
|
|
||||||
ptr = mmap (NULL, PSEUDO_PINS * sizeof (int), PROT_READ | PROT_WRITE, MAP_SHARED, node->fd, 0) ;
|
ptr = mmap (NULL, PSEUDO_PINS * sizeof (int), PROT_READ | PROT_WRITE, MAP_SHARED, node->fd, 0) ;
|
||||||
|
|
||||||
node->data0 = (unsigned int)ptr ;
|
node->data0 = (unsigned int)(uintptr_t) ptr ;
|
||||||
|
|
||||||
node->analogRead = myAnalogRead ;
|
node->analogRead = myAnalogRead ;
|
||||||
node->analogWrite = myAnalogWrite ;
|
node->analogWrite = myAnalogWrite ;
|
||||||
|
|||||||
@@ -366,7 +366,9 @@ int piGpioLayout (void)
|
|||||||
printf ("ERROR : file not found.(boardrev)\n");
|
printf ("ERROR : file not found.(boardrev)\n");
|
||||||
libwiring.rev = 1;
|
libwiring.rev = 1;
|
||||||
} else {
|
} else {
|
||||||
(void)read (fd, buf, sizeof(buf));
|
if (read(fd, buf, sizeof(buf)) < 0) {
|
||||||
|
fprintf(stderr, "Unable to read from the file descriptor: %s \n", strerror(errno));
|
||||||
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
libwiring.rev = atoi(buf) + 1;
|
libwiring.rev = atoi(buf) + 1;
|
||||||
}
|
}
|
||||||
@@ -467,7 +469,8 @@ int physPinToGpio (int physPin)
|
|||||||
void setPadDrive (int pin, int value)
|
void setPadDrive (int pin, int value)
|
||||||
{
|
{
|
||||||
if (libwiring.setPadDrive)
|
if (libwiring.setPadDrive)
|
||||||
return libwiring.setPadDrive(pin, value);
|
if (libwiring.setPadDrive(pin, value) < 0)
|
||||||
|
msg(MSG_WARN, "%s: Not available for pin %d. \n", __func__, pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -522,7 +525,8 @@ int getPUPD (int pin)
|
|||||||
void pinMode (int pin, int mode)
|
void pinMode (int pin, int mode)
|
||||||
{
|
{
|
||||||
if (libwiring.pinMode)
|
if (libwiring.pinMode)
|
||||||
return libwiring.pinMode(pin, mode);
|
if (libwiring.pinMode(pin, mode) < 0)
|
||||||
|
msg(MSG_WARN, "%s: Not available for pin %d. \n", __func__, pin);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -530,7 +534,8 @@ void pinMode (int pin, int mode)
|
|||||||
void pullUpDnControl (int pin, int pud)
|
void pullUpDnControl (int pin, int pud)
|
||||||
{
|
{
|
||||||
if (libwiring.pullUpDnControl)
|
if (libwiring.pullUpDnControl)
|
||||||
return libwiring.pullUpDnControl(pin, pud);
|
if (libwiring.pullUpDnControl(pin, pud) < 0)
|
||||||
|
msg(MSG_WARN, "%s: Not available for pin %d. \n", __func__, pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -546,7 +551,8 @@ int digitalRead (int pin)
|
|||||||
void digitalWrite (int pin, int value)
|
void digitalWrite (int pin, int value)
|
||||||
{
|
{
|
||||||
if (libwiring.digitalWrite)
|
if (libwiring.digitalWrite)
|
||||||
return libwiring.digitalWrite(pin, value);
|
if (libwiring.digitalWrite(pin, value) < 0)
|
||||||
|
msg(MSG_WARN, "%s: Not available for pin %d. \n", __func__, pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -562,7 +568,8 @@ int analogRead (int pin)
|
|||||||
void digitalWriteByte (const int value)
|
void digitalWriteByte (const int value)
|
||||||
{
|
{
|
||||||
if (libwiring.digitalWriteByte)
|
if (libwiring.digitalWriteByte)
|
||||||
return libwiring.digitalWriteByte(value);
|
if (libwiring.digitalWriteByte(value) < 0)
|
||||||
|
msg(MSG_WARN, "%s: Not available. \n", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
@@ -595,7 +602,9 @@ int waitForInterrupt (int pin, int mS)
|
|||||||
// A one character read appars to be enough.
|
// A one character read appars to be enough.
|
||||||
if (x > 0) {
|
if (x > 0) {
|
||||||
lseek (fd, 0, SEEK_SET) ; // Rewind
|
lseek (fd, 0, SEEK_SET) ; // Rewind
|
||||||
(void)read (fd, &c, 1) ; // Read & clear
|
if (read (fd, &c, 1) < 0) { // Read & clear
|
||||||
|
fprintf(stderr, "Unable to read from the file descriptor: %s \n", strerror(errno));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return x ;
|
return x ;
|
||||||
}
|
}
|
||||||
@@ -706,7 +715,9 @@ int wiringPiISR (int pin, int mode, void (*function)(void))
|
|||||||
// Clear any initial pending interrupt
|
// Clear any initial pending interrupt
|
||||||
ioctl (libwiring.sysFds [PIN_NUM_CALC_SYSFD(GpioPin)], FIONREAD, &count) ;
|
ioctl (libwiring.sysFds [PIN_NUM_CALC_SYSFD(GpioPin)], FIONREAD, &count) ;
|
||||||
for (i = 0 ; i < count ; ++i)
|
for (i = 0 ; i < count ; ++i)
|
||||||
(void)read (libwiring.sysFds [PIN_NUM_CALC_SYSFD(GpioPin)], &c, 1) ;
|
if (read(libwiring.sysFds [PIN_NUM_CALC_SYSFD(GpioPin)], &c, 1) < 0) {
|
||||||
|
fprintf(stderr, "Unable to read from the sysfs GPIO node: %s \n", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
libwiring.isrFunctions [PIN_NUM_CALC_SYSFD(GpioPin)] = function ;
|
libwiring.isrFunctions [PIN_NUM_CALC_SYSFD(GpioPin)] = function ;
|
||||||
|
|
||||||
|
|||||||
@@ -123,16 +123,16 @@ struct libodroid
|
|||||||
|
|
||||||
/* wiringPi core func */
|
/* wiringPi core func */
|
||||||
int (*getModeToGpio) (int mode, int pin);
|
int (*getModeToGpio) (int mode, int pin);
|
||||||
void (*setPadDrive) (int pin, int value);
|
int (*setPadDrive) (int pin, int value);
|
||||||
int (*getPadDrive) (int pin);
|
int (*getPadDrive) (int pin);
|
||||||
void (*pinMode) (int pin, int mode);
|
int (*pinMode) (int pin, int mode);
|
||||||
int (*getAlt) (int pin);
|
int (*getAlt) (int pin);
|
||||||
int (*getPUPD) (int pin);
|
int (*getPUPD) (int pin);
|
||||||
void (*pullUpDnControl) (int pin, int pud);
|
int (*pullUpDnControl) (int pin, int pud);
|
||||||
int (*digitalRead) (int pin);
|
int (*digitalRead) (int pin);
|
||||||
void (*digitalWrite) (int pin, int value);
|
int (*digitalWrite) (int pin, int value);
|
||||||
int (*analogRead) (int pin);
|
int (*analogRead) (int pin);
|
||||||
void (*digitalWriteByte) (const int value);
|
int (*digitalWriteByte) (const unsigned int value);
|
||||||
unsigned int (*digitalReadByte) (void);
|
unsigned int (*digitalReadByte) (void);
|
||||||
|
|
||||||
/* ISR Function pointer */
|
/* ISR Function pointer */
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -155,7 +156,8 @@ void serialClose (const int fd)
|
|||||||
|
|
||||||
void serialPutchar (const int fd, const unsigned char c)
|
void serialPutchar (const int fd, const unsigned char c)
|
||||||
{
|
{
|
||||||
write (fd, &c, 1) ;
|
if (write(fd, &c, 1) < 0)
|
||||||
|
fprintf(stderr, "Unable to send to the opened serial device: %s \n", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -167,7 +169,8 @@ void serialPutchar (const int fd, const unsigned char c)
|
|||||||
|
|
||||||
void serialPuts (const int fd, const char *s)
|
void serialPuts (const int fd, const char *s)
|
||||||
{
|
{
|
||||||
write (fd, s, strlen (s)) ;
|
if (write(fd, s, strlen(s)) < 0)
|
||||||
|
fprintf(stderr, "Unable to send to the opened serial device: %s \n", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user