int main (int argc, char *argv [])
{
- int i ;
+ int i = 0 ;
wiringPiSetup () ;
max31855Setup (200, 0) ;
for (;;)
{
- printf ("%6d, %6d, %6d, %6d ::::", analogRead (200), analogRead (201), analogRead (202), analogRead (203)) ;
- printf ("%6d, %6d, %6d, %6d\n", analogRead (400), analogRead (401), analogRead (402), analogRead (403)) ;
+ if (i == 0)
+ {
+ printf ("+------+------+------+------++------+------+------+------+\n") ;
+ printf ("| Raw | Err | C | F || Raw | Err | C | F |\n") ;
+ printf ("+------+------+------+------++------+------+------+------+\n") ;
+ }
+
+ printf ("| %4d | %4d | %4d | %4d |", analogRead (200), analogRead (201), analogRead (202), analogRead (203)) ;
+ printf ("| %4d | %4d | %4d | %4d |\n", analogRead (400), analogRead (401), analogRead (402), analogRead (403)) ;
delay (500) ;
+
+ if (++i == 10)
+ i = 0 ;
+
}
}
This loads the spi drivers into the kernel and changes the permissions
on the associated /dev/ entries so that the current user has access to
them. It used to have the ability to change the buffer size from the
-default of 4096 bytes to an arbitary value, however for some time the
+default of 4096 bytes to an arbitrary value, however for some time the
Pi Foundation have compiled the SPI device driver into the kernel and
this has fixed the buffer size. The way to change it now is to edit
the /boot/cmdline.txt file and add on spdev.bufsiz=8192 to set it to
pin numbers are \fBalways\fR native BCM_GPIO numbers and never wiringPi
pin numbers.
+As of kernels 4.1.7, a user-level GPIO access mechanism is available,
+however wiringPi will not use this by default - because at this time
+there appears to be issues when trying to program the PWM or clock output
+hardware. If you can live without PWM or GPIO clocks and you want to use
+the GPIO from a non-root program, then you need to make sure that the
+module \fIbcm2835_gpiomem\fR is loaded at boot time. This should happen
+automatically when you enable the device tree in raspi-config. You may
+also need some additional information in /etc/udev/rules.d/ to change the
+mode and ownership of the /dev/gpiomem file. Finally, you need to set
+the environment variable \fIWIRINGPI_GPIOMEM\fR. This will go-away
+in future releases once the /dev/gpiomem interface is fully operational.
+
.SH "SEE ALSO"
.LP
#define ENV_DEBUG "WIRINGPI_DEBUG"
#define ENV_CODES "WIRINGPI_CODES"
+#define ENV_GPIOMEM "WIRINGPI_GPIOMEM"
// Mask for the bottom 64 pins which belong to the Raspberry Pi
int wiringPiDebug = FALSE ;
int wiringPiReturnCodes = FALSE ;
+// Use /dev/gpiomem ?
+
+int wiringPiTryGpioMem = FALSE ;
+
// sysFds:
// Map a file descriptor from the /sys/class/gpio/gpioX/value
if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO))
{
+ if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now
+ return ;
+
if ((group < 0) || (group > 2))
return ;
{
if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO))
{
+ if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now
+ return ;
+
*(pwm + PWM0_RANGE) = range ; delayMicroseconds (10) ;
*(pwm + PWM1_RANGE) = range ; delayMicroseconds (10) ;
}
if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO))
{
+ if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now
+ return ;
+
if (wiringPiDebug)
printf ("Setting to: %d. Current: 0x%08X\n", divisor, *(clk + PWMCLK_DIV)) ;
else if (wiringPiMode != WPI_MODE_GPIO)
return ;
+ if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now
+ return ;
+
divi = 19200000 / freq ;
divr = 19200000 % freq ;
divf = (int)((double)divr * 4096.0 / 19200000.0) ;
softToneCreate (origPin) ;
else if (mode == PWM_TONE_OUTPUT)
{
+ if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now
+ return ;
+
pinMode (origPin, PWM_OUTPUT) ; // Call myself to enable PWM mode
pwmSetMode (PWM_MODE_MS) ;
}
else if (mode == PWM_OUTPUT)
{
+ if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now
+ return ;
+
if ((alt = gpioToPwmALT [pin]) == 0) // Not a hardware capable PWM pin
return ;
}
else if (mode == GPIO_CLOCK)
{
+ if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now
+ return ;
+
if ((alt = gpioToGpClkALT0 [pin]) == 0) // Not a GPIO_CLOCK pin
return ;
if ((pin & PI_GPIO_MASK) == 0) // On-Board Pin
{
+ if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now
+ return ;
+
/**/ if (wiringPiMode == WPI_MODE_PINS)
pin = pinToGpio [pin] ;
else if (wiringPiMode == WPI_MODE_PHYS)
{
int range ;
+ if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now
+ return ;
+
if (freq == 0)
pwmWrite (pin, 0) ; // Off
else
if (getenv (ENV_CODES) != NULL)
wiringPiReturnCodes = TRUE ;
+ if (getenv (ENV_GPIOMEM) != NULL)
+ wiringPiTryGpioMem = TRUE ;
+
if (wiringPiDebug)
+ {
printf ("wiringPi: wiringPiSetup called\n") ;
+ if (wiringPiTryGpioMem)
+ printf ("wiringPi: Using /dev/gpiomem\n") ;
+ }
boardRev = piBoardRev () ;
// See if /dev/gpiomem exists and we can open it...
- if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) >= 0)
+ if (wiringPiTryGpioMem)
+ {
+ if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
+ return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/gpiomem: %s\n", strerror (errno)) ;
RASPBERRY_PI_PERI_BASE = 0 ;
+ }
// ... otherwise fall back to the original /dev/mem which requires root level access