From 6ceb5882378177e25427bbb756d4132f3014315d Mon Sep 17 00:00:00 2001 From: Mr-Fishy Date: Wed, 19 Feb 2025 16:27:37 -0800 Subject: [PATCH 01/14] Added English Translated Documentation Page --- documentation/english/functions.md | 593 +++++++++++++++++++++++++++++ 1 file changed, 593 insertions(+) create mode 100644 documentation/english/functions.md diff --git a/documentation/english/functions.md b/documentation/english/functions.md new file mode 100644 index 0000000..aa0e69e --- /dev/null +++ b/documentation/english/functions.md @@ -0,0 +1,593 @@ +# Documentation WiringPi-library + +The WiringPi-library enables access to the GPIO pins of the Raspberry PI. In this documentation you will find information about the available functions and their use. +Since Version 3, extensions have now been carried out again at the interface.In the case of new implementations, you should rely on the current nine functions. +The old [GPIO Sysfs Interface for Userspace](https://www.kernel.org/doc/Documentation/gpio/sysfs.txt) is no longer supported. + +**Attention:** This documentation is still in progress and therefore incomplete. +The content of this documentation was created with care and to the best of our knowledge and belief. However, the authors do not guarantee the correctness, completeness and topicality of the information provided.The content of the documentation is used at your own risk. +No liability is generally assumed for damage caused by material or intangible nature caused by the use or non-use of the information provided or by the use of incorrect and incomplete information. + +## Installation + +Unfortunately, the WiringPi Library is not available directly in Raspberry Pi OS, which is why it has to be installed manually. +Either you can download a Debian package or translate it manually. +**Create Debian package:** + +```bash +sudo apt install git +git clone https://github.com/WiringPi/WiringPi.git +cd WiringPi +./build debian +mv debian-template/wiringpi-3.0-1.deb . +``` + +**Install Debian package:** + +```bash +sudo apt install ./wiringpi-3.0-1.deb +``` + +**Uninstall Debian package:** + +```bash +sudo apt purge wiringpi +``` + + +## PIN Numbering and Raspberry Pi Models + +GPIOs: https://pinout.xyz/pinout/wiringpi + +**Raspberry Pi Models with 40-Pin GPIO J8 Header:** + + | BCM | WPI | Name | Physical | Name | WPI | BCM | + |-----|-----|---------|:---------:|---------|-----|-----| + | | | 3V3 | 1 I 2 | 5V | | | + | 2 | 8 | SDA.1 | 3 I 4 | 5V | | | + | 3 | 9 | SCL.1 | 5 I 6 | GND | | | + | 4 | 7 | GPIO. 7 | 7 I 8 | TxD | 15 | 14 | + | | | GND | 9 I 10 | RxD | 16 | 15 | + | 17 | 0 | GPIO. 0 | 11 I 12 | GPIO. 1 | 1 | 18 | + | 27 | 2 | GPIO. 2 | 13 I 14 | GND | | | + | 22 | 3 | GPIO. 3 | 15 I 16 | GPIO. 4 | 4 | 23 | + | | | 3V3 | 17 I 18 | GPIO. 5 | 5 | 24 | + | 10 | 12 | MOSI | 19 I 20 | GND | | | + | 9 | 13 | MISO | 21 I 22 | GPIO. 6 | 6 | 25 | + | 11 | 14 | SCLK | 23 I 24 | CE0 | 10 | 8 | + | | | GND | 25 I 26 | CE1 | 11 | 7 | + | 0 | 30 | SDA.0 | 27 I 28 | SCL.0 | 31 | 1 | + | 5 | 21 | GPIO.21 | 29 I 30 | GND | | | + | 6 | 22 | GPIO.22 | 31 I 32 | GPIO.26 | 26 | 12 | + | 13 | 23 | GPIO.23 | 33 I 34 | GND | | | + | 19 | 24 | GPIO.24 | 35 I 36 | GPIO.27 | 27 | 16 | + | 26 | 25 | GPIO.25 | 37 I 38 | GPIO.28 | 28 | 20 | + | | | GND | 39 I 40 | GPIO.29 | 29 | 21 | + + +**Raspberry Pi 1B Rev. 2 with 26-Pin GPIO P1 Header:** + + | BCM | WPI | Name | Physical | Name | WPI | BCM | + |-----|-----|---------|:--------:|----------|-----|-----| + | | | 3V3 | 1 I 2 | 5V | | | + | 2 | 8 | SDA.1 | 3 I 4 | 5V | | | + | 3 | 9 | SCL.1 | 5 I 6 | GND | | | + | 4 | 7 | GPIO. 7 | 7 I 8 | TxD | 15 | 14 | + | | | GND | 9 I 10 | RxD | 16 | 15 | + | 17 | 0 | GPIO. 0 | 11 I 12 | GPIO. 1 | 1 | 18 | + | 27 | 2 | GPIO. 2 | 13 I 14 | GND | | | + | 22 | 3 | GPIO. 3 | 15 I 16 | GPIO. 4 | 4 | 23 | + | | | 3V3 | 17 I 18 | GPIO. 5 | 5 | 24 | + | 10 | 12 | MOSI | 19 I 20 | GND | | | + | 9 | 13 | MISO | 21 I 22 | GPIO. 6 | 6 | 25 | + | 11 | 14 | SCLK | 23 I 24 | CE0 | 10 | 8 | + | | | GND | 25 I 26 | CE1 | 11 | 7 | + + + +**Raspberry Pi 1B Rev. 1 with 26-Pin GPIO P1 Header:** + + | BCM | WPI | Name | Physical | Name | WPI | BCM | + |-----|-----|---------|:--------:|---------|-----|-----| + | | | 3V3 | 1 I 2 | 5V | | | + | 0 | 8 | SDA.0 | 3 I 4 | 5V | | | + | 1 | 9 | SCL.0 | 5 I 6 | GND | | | + | 4 | 7 | GPIO. 7 | 7 I 8 | TxD | 15 | 14 | + | | | GND | 9 I 10 | RxD | 16 | 15 | + | 17 | 0 | GPIO. 0 | 11 I 12 | GPIO. 1 | 1 | 18 | + | 21 | 2 | GPIO. 2 | 13 I 14 | GND | | | + | 22 | 3 | GPIO. 3 | 15 I 16 | GPIO. 4 | 4 | 23 | + | | | 3V3 | 17 I 18 | GPIO. 5 | 5 | 24 | + | 10 | 12 | MOSI | 19 I 20 | GND | | | + | 9 | 13 | MISO | 21 I 22 | GPIO. 6 | 6 | 25 | + | 11 | 14 | SCLK | 23 I 24 | CE0 | 10 | 8 | + | | | GND | 25 I 26 | CE1 | 11 | 7 | + + +**References** +Note the different PIN numbers and the I2C0 at Raspberry Pi 1b Rev. 1! + +## Initialization +At the beginning, the WiringPi Library must be initialized. +To do this, one of the following functions must be called up: + +Outdated functions (no longer use): + +``wiringPiSetup`` uses Wiringpi numbering (WPI) of the GPIO's and accesses the GPIO register directly. +``wiringPiSetupGpio`` uses BCM numbering of the GPIOs and accesses the GPIO registers directly. +``wiringPiSetupPhys`` uses physical PIN numbering of the GPIOs and accesses the GPIO register directly. +``wiringPiSetupSys`` uses BCM numbering and calls the new function ``wiringPiSetupGpioDevice`` from version 3.4 to ensure compatibility with new core. In version 2, the virtual file system/SYS/Class/GPIO was used. However, the GPIO's exports had to take place externally before the initialization! The function is outdated and should not be used! + +**From Version 3.4:** +``wiringPiSetupPinType`` decides whether WiringPi, BCM or physical PIN numbering is now used, based on the parameter pinType. So it combines the first 3 setup functions together. +``wiringPiSetupGpioDevice`` is the successor to the ``wiringPiSetupSys`` function and now uses "GPIO Character Device Userspace API" in version 1 (from kernel 5.10). More information can be found at [docs.kernel.org/driver-api/gpio/driver.html](https://docs.kernel.org/driver-api/gpio/driver.html) on the parameter pintype, it is again decided which pin numbering is used. +With this variant, the GPIO storage (DMA) is not accessed directly, but via a kernel interface that is available with user rights.The disadvantage is the scope of functions and low performance. + + + +### wiringPiSetup V2 (outdated) + +Inializating WiringPi in a classic way. +>>> +```C +int wiringPiSetupGpio(void) +``` + +``Return Value``: Error status + +> 0 ... No Error + +**Example:** + +```C +wiringPiSetupGpio(); +``` + +### wiringPiSetup V3 + +Initializing WiringPi. +>>> +```C +int wiringPiSetupPinType(enum WPIPinType pinType) +``` + +``pinType``: Type of PIN numbering... + + - `WPI_PIN_BCM` ... BCM-Numbering + + - `WPI_PIN_WPI` ... WiringPi-Numbering + + - `WPI_PIN_PHYS` ... Physical Numbering + +``Return Value``: Error status + +> 0 ... No Error +> -1 ... Invalid Parameter Error + +**Example:** + +```C +wiringPiSetupPinType(WPI_PIN_BCM); +``` + +## Basic Functions + +### pinMode + +Changes the mode of a GPIO pins. +>>> +```C +void pinMode(int pin, int mode) +``` + +``Pin``: The desired PIN (BCM, Wiringpi or PIN number). +``Mode``: The desired pin mode... + +- `INPUT` ... entrance + +- `OUTPUT` ... output + +- `PWM_OUTPUT` ... PWM output (frequency and pulse break ratio can be configured) + +- `PWM_MS_OUTPUT` ... PWM output with MS (Mark/Space) (from version 3) + +- `PWM_BAL_OUTPUT` ... PWM output with mode balanced) (from version 3) + +- `GPIO_CLOCK` ... Frequency output + +- `PM_OFF` ... Approval + +**Example:** + +```C +pinMode(17, OUTPUT); +``` + +**Support:** +`PM_OFF` resets the GPIO (Input) and releases it. PWM is ended. +Raspberry Pi 5 does not support the PWM Bal (Balanced) mode. The MS mode is activated at `PWM_OUTPUT`. +`GPIO_CLOCK` is currently not yet supported in Raspberry Pi 5 (RP1). + +**PWM Exit** +`PWM_OUTPUT` Activates the specified PWM output with the settings: + + - Mode: BAL-Balanced (Pi0-4), MS-Mark/Space (Pi 5) + + - Range: 1024 + + - Divider: 32 + +In order to make sure that the output starts without an active frequency, you should execute ``pwmWrite(PWM_GPIO, 0);`` before activating. +After that, the corresponding clock and range values ​​can be adapted, without a frequency already being output unintentionally. + +### pinMode + +### digitalWrite + +Set the value of a GPIO pin. +>>> +```C +void digitalWrite(int pin, int value) +``` + +``pin``: The desired Pin (BCM-, Wiringpi- or PIN number). +``value``: The logical value... + + - `HIGH` ... Value 1 (electrical ~ 3.3 V) + + - `LOW` ... Value 0 (electrical ~0 V / GND) + +**Example:** + +```C +pinMode(17, OUTPUT); +DigitalWrite(17, HIGH); +``` + +### pullUpDnControl + +Changes the internal pull-up / pull-down resistance. +>>> +```C +void pullUpDnControl (int pin, int pud) +``` + +``pin``: The desired Pin (BCM-, WiringPi-, or Pin-number). +``pud``: The resistance type... + + - `PUD_OFF` ... No resistance + + - `PUD_UP` ... Pull-Up resistance (~50 kOhm) + + - `PUD_DOWN` ... Pull-Down resistance (~50 kOhm) + +**Example:** + +```C +pullUpDnControl(17, PUD_DOWN); +``` + +### digitalRead + +Reads the value of one GPIO-Pin. +>>> +```C +int digitalRead(int pin) +``` + +``pin``: The desired Pin (BCM-, WiringPi-, or Pin-number). +``Return Value``: The logical value. + +> `HIGH` ... Value 1 +> `LOW` ... Value 0 + +**Example:** + +```C +pinMode(17, INPUT); +pullUpDnControl(17, PUD_DOWN); + +int value = digitalRead(17); + +if (value == HIGH) +{ + // Your Code +} +``` + +## Interrupts + +### wiringPiISR + +Register an Interrupt Service Routine (ISR) or function that is executed when switching edge. + +>>> +```C +int wiringPiISR(int pin, int mode, void (*function)(void)); +``` + +``pin``: The desired Pin (BCM-, WiringPi-, or Pin-number). +``mode``: Triggering edge mode... + + - `INT_EDGE_RISING` ... Rising edge + + - `INT_EDGE_FALLING` ... Falling edge + + - `INT_EDGE_BOTH` ... Rising and falling edge + +``*function``: Function pointer for ISR +``Return Value``: + +> 0 ... Successful + + + +For example see **wiringPiISRStop**. + + +### wiringPiISRStop + +Deregisters the Interrupt Service Routine (ISR) on a Pin. + +>>> +```C +int wiringPiISRStop (int pin) +``` + +``pin``: The desired Pin (BCM-, WiringPi-, or Pin-number). +``Return Value``: + +> 0 ... Successful + + + + +**Example:** + +```C +static volatile int edgeCounter; + +static void isr(void) { + edgeCounter++; +} + +int main (void) { + wiringPiSetupPinType(WPI_PIN_BCM); + edgeCounter = 0; + + wiringPiISR (17, INT_EDGE_RISING, &isr); + + Sleep(1000); + printf("%d rinsing edges\n", ); + + wiringPiISRStop(17); +} +``` + + +### waitForInterrupt + +Wait for a call to the Interrupt Service Routine (ISR) with timeout. + +>>> +```C +int waitForInterrupt (int pin, int mS) +``` + +``pin``: The desired Pin (BCM-, WiringPi-, or Pin-number). +``mS``: Timeout in milliseconds. +``Return Value``: Error +> 0 ... Successful +> -1 ... GPIO Device Chip not successfully opened +> -2 ... ISR was not registered (WiringPiISR must be called) + + +## Hardware Pulse Width Modulation (PWM) + +Available GPIOs: https://pinout.xyz/pinout/pwm + +### pwmWrite + +Changes the PWM value of the pin. Possible values ​​are 0 -> { PWM Range }. +>>> +```C +pwmWrite(int pin, int value) +``` + +``pin``: The desired Pin (BCM-, WiringPi-, or Pin-number). +``value``: PWM value + +### pwmSetRange + +Set the range for the PWM value of all PWM pins or PWM channels. +19200 / divisor / range applies to the calculation of the PWM frequency (m/s mode). +If ``pinMode(pin, PWM_OUTPUT)`` The value 1024 is automatically set for the divider. +>>> +```C +pwmSetRange (unsigned int range) +``` + +``range``: PWM Range + +### pwmSetMode + +Set the PWM mode for all PWM pins or PWM channels. +>>> +```C +pwmSetMode(int mode); +``` + +``mode``: PWM Mode + + - `PWM_MODE_MS` ... Mark / Space Mode (PWM Fixed Frequency) + + - `PWM_MODE_BAL` ... Balanced Mode (PWM Variable Frequency) + +**Support:** +Raspberry Pi 5 does not support the balanced mode! + + +### pwmSetClock + +Set the divider for the basic PWM. The base clock is standardized for all Raspberry Pi's to 1900 kHz. +19200 / divisor / range applies to the calculation of the PWM frequency (m/s mode). +If ``pinmode(pin, PWM_OUTPUT)`` The value 32 is automatically set for the divider. +>>> +```C +pwmSetClock(int divisor) +``` + +``divisor``: Divider (Raspberry Pi 4: 1-1456, all other 1-4095) + +- `0` ... Deactivates the PWM clock on Raspberry Pi 5, with other Pi's divisor `1` is used + +**Support:** +Due to its higher internal basic clock, the Raspberry Pi 4 only has a setting range of `1 - 1456`. +Otherwise, `0 - 4095` applies to a valid divider. + +**Example:** + +```C +int main (void) { + wiringPiSetupGpio() ; + + pwmSetRange(1024); + pwmSetClock(35); + + pwmWrite(18, 512); + + pinMode(18, PWM_MS_OUTPUT); + + double freq = 19200.0 / (double)pwmc / (double)pwmr; + + printf("PWM 50%% @ %g kHz", freq); + delay(250); + + pinMode(18, PM_OFF); +} +``` + + +## I2C - Bus + +``wiringPiI2CRawWrite`` and ``wiringPiI2CRawRead`` are the new functions of version 3 with which I2C data can now be sent and read. +The other writing and reading functions use the SMBUS protocol, which is usually used for I2C chips. + +### wiringPiI2CSetup + +Open the default I2C bus on the Raspberry Pi and addresses the specified device / slave. + +>>> +```C +wiringPiI2CSetup(const int devId) +``` + +``devId``: I2C-Gerät / Slave Adresse. +``Return Value``: File Handle to I2C-Bus + +> -1 ... Error or EXIT (Programm termination) + +**Example** +>>> +```C +int fd = wiringPiI2CSetup(0x20); +``` + +### wiringPiI2CSetupInterface + +Open the specimen I2C bus and address the specified I2C device / slave. +>>> +```C +wiringPiI2CSetupInterface(const char *device, int devId) +``` + +``devId``: I2C-Gerät / Slave Adresse. +``Return Value``: File Handle to I2C-Bus + +> -1 ... Error or EXIT (Programm termination) + +**Example** +>>> +```C +int fd = wiringPiI2CSetupInterface("/dev/i2c-1", 0x20); +``` + + +### wiringPiI2CWrite / wiringPiI2CWriteReg8 / wiringPiI2CWriteReg16 / wiringPiI2CWriteBlockData + +... + +### wiringPiI2CRawWrite + +Writing data about an I2C slave. +>>> +```C +int wiringPiI2CRawWrite(int fd, const uint8_t *values, uint8_t size) +``` + +``fd``: File Handle. +``values``: Source buffer. +``size``: Number of bytes of the source buffer that should be written. +``Return Value``: Number of bytes that were written. + +**Example** +>>> +```C +int fd = wiringPiI2CSetup(I2C_ADDR); + +if (fd > 0) { + uint8_t i2cvalue = 0x55; + int result = wiringPiI2CRawWrite(fd, &i2cvalue, 1); + + if (1 == result) { + // 1 byte from i2cvalue send to I2C_ADDR slave + } else { + // error + } +} +else { + // error +} +``` + +### wiringPiI2CRead / wiringPiI2CReadReg8 / wiringPiI2CReadReg16 / wiringPiI2CReadBlockData + +... + +### wiringPiI2CRawRead + +Reading data from an I2C slave. +>>> +```C +int wiringPiI2CRawRead(int fd, uint8_t *values, uint8_t size) +``` + +``fd``: File Handle. +``values``: Target buffer. +``size``: Number of bytes that are to be read into the target buffer. +``Return Value``: Number of bytes that were read. + +**Example** +>>> +```C +int fd = wiringPiI2CSetup(I2C_ADDR); + +if (fd > 0) { + uint8_t i2cvalue; + int result = wiringPiI2CRawRead(fd, &i2cvalue, 1); + + if (1 == result) { + // 1 byte received from I2C_ADDR and stored to i2cvalue + } else { + // error + } +} +else { + // error +} +``` + + +## SPI - Bus + +... \ No newline at end of file From efe6d6e09c3bbc48f928be7785e59ea6682400d5 Mon Sep 17 00:00:00 2001 From: mstroh Date: Thu, 20 Feb 2025 13:06:39 +0100 Subject: [PATCH 02/14] #324 typo --- documentation/deutsch/functions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/deutsch/functions.md b/documentation/deutsch/functions.md index 114faa3..589386f 100644 --- a/documentation/deutsch/functions.md +++ b/documentation/deutsch/functions.md @@ -1,7 +1,7 @@ # Dokumentation WiringPi-Bibliothek Die WiringPi-Bibliothek ermöglicht den Zugriff auf die GPIO-Pins des Raspberry Pi. In dieser Dokumentation finden Sie Informationen zu den verfügbaren Funktionen und deren Verwendung. -Seit Version 3 werden nun auch wieder Erweiterungen an der Schnittstelle vorgenommen. Bei Neuimplementierungen sollte man auf die aktuellen bzw. neunen Funktionen setzen. +Seit Version 3 werden nun auch wieder Erweiterungen an der Schnittstelle vorgenommen. Bei Neuimplementierungen sollte man auf die aktuellen bzw. neuen Funktionen setzen. Das alte [GPIO Sysfs Interface for Userspace](https://www.kernel.org/doc/Documentation/gpio/sysfs.txt) wird nun nicht mehr unterstützt. **ACHTUNG:** Diese Dokumemtation ist noch in Arbeit und somit unvollständig. @@ -564,4 +564,4 @@ if (fd>0) { ## SPI - Bus -... \ No newline at end of file +... From 36524ef082694ecbdc09c23f7fde16afcd3b0144 Mon Sep 17 00:00:00 2001 From: mstroh Date: Thu, 20 Feb 2025 13:08:37 +0100 Subject: [PATCH 03/14] #324 wrong translation --- documentation/english/functions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/english/functions.md b/documentation/english/functions.md index aa0e69e..58573ce 100644 --- a/documentation/english/functions.md +++ b/documentation/english/functions.md @@ -1,7 +1,7 @@ # Documentation WiringPi-library The WiringPi-library enables access to the GPIO pins of the Raspberry PI. In this documentation you will find information about the available functions and their use. -Since Version 3, extensions have now been carried out again at the interface.In the case of new implementations, you should rely on the current nine functions. +Since Version 3, extensions have now been carried out again at the interface.In the case of new implementations, you should rely on the current /new functions. The old [GPIO Sysfs Interface for Userspace](https://www.kernel.org/doc/Documentation/gpio/sysfs.txt) is no longer supported. **Attention:** This documentation is still in progress and therefore incomplete. @@ -590,4 +590,4 @@ else { ## SPI - Bus -... \ No newline at end of file +... From 8e02c4e75a35b95402d709ee64cf74d885476f2e Mon Sep 17 00:00:00 2001 From: mstroh Date: Fri, 28 Feb 2025 17:54:56 +0100 Subject: [PATCH 04/14] #324 Translation and space fixes --- documentation/english/functions.md | 57 +++++++++--------------------- 1 file changed, 17 insertions(+), 40 deletions(-) diff --git a/documentation/english/functions.md b/documentation/english/functions.md index 58573ce..ca3f613 100644 --- a/documentation/english/functions.md +++ b/documentation/english/functions.md @@ -10,8 +10,8 @@ No liability is generally assumed for damage caused by material or intangible na ## Installation -Unfortunately, the WiringPi Library is not available directly in Raspberry Pi OS, which is why it has to be installed manually. -Either you can download a Debian package or translate it manually. +Unfortunately, the WiringPi Library is not directly available in Raspberry Pi OS, so it must be installed manually. Either download a Debian package or create it manually. + **Create Debian package:** ```bash @@ -105,7 +105,7 @@ GPIOs: https://pinout.xyz/pinout/wiringpi **References** -Note the different PIN numbers and the I2C0 at Raspberry Pi 1b Rev. 1! +Note the different pin numbers and the I2C0 at Raspberry Pi 1B Rev. 1! ## Initialization At the beginning, the WiringPi Library must be initialized. @@ -118,10 +118,10 @@ Outdated functions (no longer use): ``wiringPiSetupPhys`` uses physical PIN numbering of the GPIOs and accesses the GPIO register directly. ``wiringPiSetupSys`` uses BCM numbering and calls the new function ``wiringPiSetupGpioDevice`` from version 3.4 to ensure compatibility with new core. In version 2, the virtual file system/SYS/Class/GPIO was used. However, the GPIO's exports had to take place externally before the initialization! The function is outdated and should not be used! -**From Version 3.4:** +**Since Version 3.4:** ``wiringPiSetupPinType`` decides whether WiringPi, BCM or physical PIN numbering is now used, based on the parameter pinType. So it combines the first 3 setup functions together. ``wiringPiSetupGpioDevice`` is the successor to the ``wiringPiSetupSys`` function and now uses "GPIO Character Device Userspace API" in version 1 (from kernel 5.10). More information can be found at [docs.kernel.org/driver-api/gpio/driver.html](https://docs.kernel.org/driver-api/gpio/driver.html) on the parameter pintype, it is again decided which pin numbering is used. -With this variant, the GPIO storage (DMA) is not accessed directly, but via a kernel interface that is available with user rights.The disadvantage is the scope of functions and low performance. +In this variant, there is no direct access to the GPIO memory (DMA) but rather through a kernel interface that is available with user permissions. The disadvantage is the limited functionality and low performance. @@ -152,11 +152,8 @@ int wiringPiSetupPinType(enum WPIPinType pinType) ``` ``pinType``: Type of PIN numbering... - - `WPI_PIN_BCM` ... BCM-Numbering - - `WPI_PIN_WPI` ... WiringPi-Numbering - - `WPI_PIN_PHYS` ... Physical Numbering ``Return Value``: Error status @@ -182,20 +179,13 @@ void pinMode(int pin, int mode) ``Pin``: The desired PIN (BCM, Wiringpi or PIN number). ``Mode``: The desired pin mode... - -- `INPUT` ... entrance - -- `OUTPUT` ... output - +- `INPUT` ... Input +- `OUTPUT` ... Output - `PWM_OUTPUT` ... PWM output (frequency and pulse break ratio can be configured) - -- `PWM_MS_OUTPUT` ... PWM output with MS (Mark/Space) (from version 3) - -- `PWM_BAL_OUTPUT` ... PWM output with mode balanced) (from version 3) - +- `PWM_MS_OUTPUT` ... PWM output with MS (Mark/Space) (since version 3) +- `PWM_BAL_OUTPUT` ... PWM output with mode balanced) (since version 3) - `GPIO_CLOCK` ... Frequency output - -- `PM_OFF` ... Approval +- `PM_OFF` ... Release **Example:** @@ -204,17 +194,14 @@ pinMode(17, OUTPUT); ``` **Support:** -`PM_OFF` resets the GPIO (Input) and releases it. PWM is ended. +`PM_OFF` resets the GPIO (Input) and releases it. PWM is stopped. Raspberry Pi 5 does not support the PWM Bal (Balanced) mode. The MS mode is activated at `PWM_OUTPUT`. `GPIO_CLOCK` is currently not yet supported in Raspberry Pi 5 (RP1). **PWM Exit** `PWM_OUTPUT` Activates the specified PWM output with the settings: - - Mode: BAL-Balanced (Pi0-4), MS-Mark/Space (Pi 5) - - Range: 1024 - - Divider: 32 In order to make sure that the output starts without an active frequency, you should execute ``pwmWrite(PWM_GPIO, 0);`` before activating. @@ -232,9 +219,7 @@ void digitalWrite(int pin, int value) ``pin``: The desired Pin (BCM-, Wiringpi- or PIN number). ``value``: The logical value... - - `HIGH` ... Value 1 (electrical ~ 3.3 V) - - `LOW` ... Value 0 (electrical ~0 V / GND) **Example:** @@ -254,11 +239,8 @@ void pullUpDnControl (int pin, int pud) ``pin``: The desired Pin (BCM-, WiringPi-, or Pin-number). ``pud``: The resistance type... - - `PUD_OFF` ... No resistance - - `PUD_UP` ... Pull-Up resistance (~50 kOhm) - - `PUD_DOWN` ... Pull-Down resistance (~50 kOhm) **Example:** @@ -299,7 +281,7 @@ if (value == HIGH) ### wiringPiISR -Register an Interrupt Service Routine (ISR) or function that is executed when switching edge. +Registers an Interrupt Service Routine (ISR) / function that is executed on edge detection. >>> ```C @@ -308,11 +290,8 @@ int wiringPiISR(int pin, int mode, void (*function)(void)); ``pin``: The desired Pin (BCM-, WiringPi-, or Pin-number). ``mode``: Triggering edge mode... - - `INT_EDGE_RISING` ... Rising edge - - `INT_EDGE_FALLING` ... Falling edge - - `INT_EDGE_BOTH` ... Rising and falling edge ``*function``: Function pointer for ISR @@ -367,7 +346,7 @@ int main (void) { ### waitForInterrupt -Wait for a call to the Interrupt Service Routine (ISR) with timeout. +Waits for a previously defined interrupt (wiringPiISR) on the GPIO pin. This function should not be used. >>> ```C @@ -418,9 +397,7 @@ pwmSetMode(int mode); ``` ``mode``: PWM Mode - - `PWM_MODE_MS` ... Mark / Space Mode (PWM Fixed Frequency) - - `PWM_MODE_BAL` ... Balanced Mode (PWM Variable Frequency) **Support:** @@ -431,7 +408,7 @@ Raspberry Pi 5 does not support the balanced mode! Set the divider for the basic PWM. The base clock is standardized for all Raspberry Pi's to 1900 kHz. 19200 / divisor / range applies to the calculation of the PWM frequency (m/s mode). -If ``pinmode(pin, PWM_OUTPUT)`` The value 32 is automatically set for the divider. +If ``pinmode(pin, PWM_OUTPUT)`` The value 32 is automatically set for the divider. >>> ```C pwmSetClock(int divisor) @@ -470,8 +447,7 @@ int main (void) { ## I2C - Bus -``wiringPiI2CRawWrite`` and ``wiringPiI2CRawRead`` are the new functions of version 3 with which I2C data can now be sent and read. -The other writing and reading functions use the SMBUS protocol, which is usually used for I2C chips. +``wiringPiI2CRawWrite`` and ``wiringPiI2CRawRead`` are the new functions in version 3 that now allow direct sending and reading of I2C data. The other write and read functions use the SMBus protocol, which is commonly used with I2C chips. ### wiringPiI2CSetup @@ -495,7 +471,8 @@ int fd = wiringPiI2CSetup(0x20); ### wiringPiI2CSetupInterface -Open the specimen I2C bus and address the specified I2C device / slave. +Opens the specified I2C bus and addresses the specified I2C device / slave. + >>> ```C wiringPiI2CSetupInterface(const char *device, int devId) From 1322cb23dd3416b334e1c835e1ed2cba6e892b0b Mon Sep 17 00:00:00 2001 From: mstroh Date: Fri, 28 Feb 2025 17:58:06 +0100 Subject: [PATCH 05/14] #324 waitForInterrupt dont use --- documentation/deutsch/functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/deutsch/functions.md b/documentation/deutsch/functions.md index 589386f..74fa7d4 100644 --- a/documentation/deutsch/functions.md +++ b/documentation/deutsch/functions.md @@ -345,7 +345,7 @@ int main (void) { ### waitForInterrupt -Wartet auf einen Aufruf der Interrupt Service Routine (ISR) mit Timeout. +Wartet auf einen zuvor definierten Interrupt (wiringPiISR) am GPIO Pin. Diese Funktion sollte nicht verwendet werden. >>> ```C From 15de0cab8792ea4277197587c86d4226703ab552 Mon Sep 17 00:00:00 2001 From: mstroh Date: Fri, 28 Feb 2025 17:58:57 +0100 Subject: [PATCH 06/14] #324 --- documentation/deutsch/functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/deutsch/functions.md b/documentation/deutsch/functions.md index 74fa7d4..318da7d 100644 --- a/documentation/deutsch/functions.md +++ b/documentation/deutsch/functions.md @@ -11,7 +11,7 @@ Für Schäden materieller oder immaterieller Art, die durch die Nutzung oder Nic ## Installation Leider steht die WiringPi Library nicht direkt in Raspberry Pi OS zur Verfügung, darum muss sie manuelle installiert weden. -Entweder man lädt sich ein Debian-Paket herunter oder übersetzt es manuell. +Entweder man lädt sich ein Debian-Paket herunter oder erstellt es manuell. **Debian-Paket erstellen:** From b09713ea10e773a53df4e470be230240a0518d26 Mon Sep 17 00:00:00 2001 From: mstroh Date: Fri, 28 Feb 2025 18:02:17 +0100 Subject: [PATCH 07/14] #324 Translation corrections --- documentation/english/functions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/english/functions.md b/documentation/english/functions.md index ca3f613..3c1e1c3 100644 --- a/documentation/english/functions.md +++ b/documentation/english/functions.md @@ -1,7 +1,7 @@ # Documentation WiringPi-library -The WiringPi-library enables access to the GPIO pins of the Raspberry PI. In this documentation you will find information about the available functions and their use. -Since Version 3, extensions have now been carried out again at the interface.In the case of new implementations, you should rely on the current /new functions. +The WiringPi-library enables access to the GPIO pins of the Raspberry Pi. In this documentation you will find information about the available functions and their use. +Since Version 3, extensions to the interface have been made again. In the case of new implementations, you should rely on the current / new functions. The old [GPIO Sysfs Interface for Userspace](https://www.kernel.org/doc/Documentation/gpio/sysfs.txt) is no longer supported. **Attention:** This documentation is still in progress and therefore incomplete. From ea7c8ffe1348af08f3e9e3bc662125b14961fbf2 Mon Sep 17 00:00:00 2001 From: mstroh Date: Fri, 28 Feb 2025 18:02:57 +0100 Subject: [PATCH 08/14] #324 --- documentation/english/functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/english/functions.md b/documentation/english/functions.md index 3c1e1c3..4a6a461 100644 --- a/documentation/english/functions.md +++ b/documentation/english/functions.md @@ -1,7 +1,7 @@ # Documentation WiringPi-library The WiringPi-library enables access to the GPIO pins of the Raspberry Pi. In this documentation you will find information about the available functions and their use. -Since Version 3, extensions to the interface have been made again. In the case of new implementations, you should rely on the current / new functions. +Since Version 3, extensions to the interface have been made again. In the case of new implementations, you should rely on the current / new functions. The old [GPIO Sysfs Interface for Userspace](https://www.kernel.org/doc/Documentation/gpio/sysfs.txt) is no longer supported. **Attention:** This documentation is still in progress and therefore incomplete. From 7bde79fba916b503c785951f18ae8a1d798972e7 Mon Sep 17 00:00:00 2001 From: mstroh Date: Fri, 28 Feb 2025 18:26:44 +0100 Subject: [PATCH 09/14] #324 SPI german --- documentation/deutsch/functions.md | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/documentation/deutsch/functions.md b/documentation/deutsch/functions.md index 318da7d..55cb1c2 100644 --- a/documentation/deutsch/functions.md +++ b/documentation/deutsch/functions.md @@ -564,4 +564,37 @@ if (fd>0) { ## SPI - Bus +Funktionen die mit ``wiringPiSPIx`` beginnen sind neu in der Version 3, mit ihnen kann auch die SPI-Bus Nummer angegeben werden. +Dies ist vorallem nützlich für das Compute Module das über mehere SPI-Busse (0-3) verfügt. +Die alten Funktionen bleiben erhalten beziehen sich allerdings immer auf den SPI Bus 0 der am 40-GPIO Anschluss verfügbar ist. + + +### wiringPiSPISetup + +Öffnet den default SPI-Bus am Raspberry Pi und adressiert das angegebene Gerät / Slave. + +>>> +```C +int wiringPiSPISetup (int channel, int speed) +``` + +``channel``: SPI Kanal (0 oder 1). +``speed``: SPI Taktrate. +``Rückgabewert``: Datei Handle zum SPI-Bus +> -1 ... Fehler bzw. EXIT (Programm Beendigung) + +**Beispiel** +>>> +```C +const int spiChannel = 1; +const int spiSpeedInit = 250000; // Hz +int hSPI; + +if ((hSPI = wiringPiSPISetup (spiChannel, spiSpeed)) < 0) { + FailAndExitWithErrno("wiringPiSPISetup", hSPI); +} + ... + +wiringPiSPIClose(spiChannel); +``` From f0db02b6382b910dcffad2b286c09b4372eea5ba Mon Sep 17 00:00:00 2001 From: mstroh Date: Sat, 1 Mar 2025 11:27:47 +0100 Subject: [PATCH 10/14] #324 Full SPI Bus documentation german --- documentation/deutsch/functions.md | 93 +++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 9 deletions(-) diff --git a/documentation/deutsch/functions.md b/documentation/deutsch/functions.md index 55cb1c2..56b4387 100644 --- a/documentation/deutsch/functions.md +++ b/documentation/deutsch/functions.md @@ -452,7 +452,7 @@ Die anderen Schreib- und Lese-Funktionen verwenden das SMBus-Protokoll, das übl ### wiringPiI2CSetup -Öffnet den default I2C-Bus am Raspberry Pi und adressiert das angegebene Gerät / Slave. +Öffnet den default I2C-Bus und adressiert das angegebene Gerät / Slave. >>> ```C @@ -496,7 +496,6 @@ int fd = wiringPiI2CSetupInterface("/dev/i2c-1", 0x20); ### wiringPiI2CRawWrite - Schreiben von Daten zu einem I2C-Slave. >>> @@ -565,22 +564,26 @@ if (fd>0) { ## SPI - Bus Funktionen die mit ``wiringPiSPIx`` beginnen sind neu in der Version 3, mit ihnen kann auch die SPI-Bus Nummer angegeben werden. -Dies ist vorallem nützlich für das Compute Module das über mehere SPI-Busse (0-3) verfügt. +Dies ist vorallem nützlich für das Compute Module das über mehere SPI-Busse (0-7) verfügt. Die alten Funktionen bleiben erhalten beziehen sich allerdings immer auf den SPI Bus 0 der am 40-GPIO Anschluss verfügbar ist. -### wiringPiSPISetup +### wiringPiSPISetup / wiringPiSPISetupMode / wiringPiSPIxSetupMode -Öffnet den default SPI-Bus am Raspberry Pi und adressiert das angegebene Gerät / Slave. +Öffnet den default SPI-Bus. >>> ```C int wiringPiSPISetup (int channel, int speed) +int wiringPiSPISetup (int channel, int speed, int mode) +int wiringPiSPIxSetupMode(const int number, const int channel, const int speed, const int mode) ``` -``channel``: SPI Kanal (0 oder 1). +``number``: SPI Nummer (typisch 0, bei Compute Modul 0-7). +``channel``: SPI Kanal (typisch 0 oder 1, bei Compute Modul 0-3). ``speed``: SPI Taktrate. -``Rückgabewert``: Datei Handle zum SPI-Bus +``mode``: SPI Modus (https://www.kernel.org/doc/Documentation/spi/spidev). +``Rückgabewert``: Datei Handle zum SPI-Bus > -1 ... Fehler bzw. EXIT (Programm Beendigung) **Beispiel** @@ -591,10 +594,82 @@ const int spiSpeedInit = 250000; // Hz int hSPI; if ((hSPI = wiringPiSPISetup (spiChannel, spiSpeed)) < 0) { - FailAndExitWithErrno("wiringPiSPISetup", hSPI); + //error } -... +//operate SPI + +wiringPiSPIClose(spiChannel); +``` + +### wiringPiSPIDataRW / wiringPiSPIxDataRW + +Eine synchrone Schreibe- und Leseoperation am geöffneten SPI Bus wird duchgeführt. Dabei werden die gesendetet Daten von dem empfangenen überschrieben. + +>>> +```C +int wiringPiSPIDataRW (int channel, unsigned char *data, int len) +int wiringPiSPIxDataRW (const int number, const int channel, unsigned char *data, const int len) +``` + +``number``: SPI Nummer (typisch 0, bei Compute Modul 0-7). +``channel``: SPI Kanal (typisch 0 oder 1, bei Compute Modul 0-3). +``data``: Datenpuffer +``len``: Größe des ``data`` Puffes bzw der Daten. +``Rückgabewert``: Rückgabewert des ``ioctl`` Befehls (https://man7.org/linux/man-pages/man2/ioctl.2.html) +<0 ... Fehler, siehe ``errno`` für Fehlernummer + +**Beispiel** +>>> +```C +const int spiChannel = 1; +const int spiSpeedInit = 250000; // Hz +int hSPI; + +if ((hSPI = wiringPiSPIxSetupMode (0, spiChannel, spiSpeed, 0)) < 0) { + //error +} +unsigned char spiData[3]; +int returnvalue + +spiData[0] = 0b11010000; +spiData[1] = 0; +spiData[2] = 0; +returnvalue = wiringPiSPIxDataRW(0, spiChannel, spiData, 3); +if (returnvalue<=0) { + printf("SPI transfer error: %d\n", errno); +} + +wiringPiSPIxClose(0, spiChannel); +``` + +### wiringPiSPIGetFd / wiringPiSPIxGetFd + +Liefert den Datei Handel zum geöffneten SPI-Bus. Um z.B. eigene SPI-Funktion aufrufen zu können. + +>>> +```C +int wiringPiSPIGetFd(int channel) +int wiringPiSPIxGetFd(const int number, int channel) +``` + +``number``: SPI Nummer (typisch 0, bei Compute Modul 0-7). +``channel``: SPI Kanal (typisch 0 oder 1, bei Compute Modul 0-3). +``Rückgabewert``: Datei Handle zum SPI-Bus +> -1 ... Ungültig bzw. nicht geöffnet + +**Beispiel** +>>> +```C +const int spiChannel = 1; +const int spiSpeedInit = 250000; // Hz +int hSPI; + +if ((hSPI = wiringPiSPISetup (spiChannel, spiSpeed)) < 0) { + //error +} + +int fd_spi = wiringPiSPIGetFd(spiChannel); wiringPiSPIClose(spiChannel); ``` From f0e1f0e521eb833dbd783e6eebe1736371857051 Mon Sep 17 00:00:00 2001 From: mstroh Date: Sat, 1 Mar 2025 11:34:40 +0100 Subject: [PATCH 11/14] #324 --- documentation/deutsch/functions.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/documentation/deutsch/functions.md b/documentation/deutsch/functions.md index 56b4387..95bd1ff 100644 --- a/documentation/deutsch/functions.md +++ b/documentation/deutsch/functions.md @@ -505,7 +505,7 @@ int wiringPiI2CRawWrite(int fd, const uint8_t *values, uint8_t size) ``fd``: Datei Handle. ``values``: Quellpuffer. -``size``: Anzahl der Bytes die com Quellpuffer geschrieben werden sollen. +``size``: Anzahl der Bytes die vom Quellpuffer geschrieben werden sollen. ``Rückgabewert``: Anzahl der Bytes die geschrieben wurden. **Beispiel** @@ -570,7 +570,7 @@ Die alten Funktionen bleiben erhalten beziehen sich allerdings immer auf den SPI ### wiringPiSPISetup / wiringPiSPISetupMode / wiringPiSPIxSetupMode -Öffnet den default SPI-Bus. +Öffnet den angegebenen SPI-Bus. >>> ```C @@ -579,8 +579,8 @@ int wiringPiSPISetup (int channel, int speed, int mode) int wiringPiSPIxSetupMode(const int number, const int channel, const int speed, const int mode) ``` -``number``: SPI Nummer (typisch 0, bei Compute Modul 0-7). -``channel``: SPI Kanal (typisch 0 oder 1, bei Compute Modul 0-3). +``number``: SPI Nummer (typisch 0, bei Compute Modul 0-7). +``channel``: SPI Kanal (typisch 0 oder 1, bei Compute Modul 0-3). ``speed``: SPI Taktrate. ``mode``: SPI Modus (https://www.kernel.org/doc/Documentation/spi/spidev). ``Rückgabewert``: Datei Handle zum SPI-Bus @@ -612,11 +612,11 @@ int wiringPiSPIDataRW (int channel, unsigned char *data, int len) int wiringPiSPIxDataRW (const int number, const int channel, unsigned char *data, const int len) ``` -``number``: SPI Nummer (typisch 0, bei Compute Modul 0-7). -``channel``: SPI Kanal (typisch 0 oder 1, bei Compute Modul 0-3). +``number``: SPI Nummer (typisch 0, bei Compute Modul 0-7). +``channel``: SPI Kanal (typisch 0 oder 1, bei Compute Modul 0-3). ``data``: Datenpuffer -``len``: Größe des ``data`` Puffes bzw der Daten. -``Rückgabewert``: Rückgabewert des ``ioctl`` Befehls (https://man7.org/linux/man-pages/man2/ioctl.2.html) +``len``: Größe von ``data`` Puffer bzw. der Daten. +``Rückgabewert``: Rückgabewert des ``ioctl`` Befehls (https://man7.org/linux/man-pages/man2/ioctl.2.html) <0 ... Fehler, siehe ``errno`` für Fehlernummer **Beispiel** @@ -630,7 +630,7 @@ if ((hSPI = wiringPiSPIxSetupMode (0, spiChannel, spiSpeed, 0)) < 0) { //error } unsigned char spiData[3]; -int returnvalue +int returnvalue; spiData[0] = 0b11010000; spiData[1] = 0; @@ -653,8 +653,8 @@ int wiringPiSPIGetFd(int channel) int wiringPiSPIxGetFd(const int number, int channel) ``` -``number``: SPI Nummer (typisch 0, bei Compute Modul 0-7). -``channel``: SPI Kanal (typisch 0 oder 1, bei Compute Modul 0-3). +``number``: SPI Nummer (typisch 0, bei Compute Modul 0-7). +``channel``: SPI Kanal (typisch 0 oder 1, bei Compute Modul 0-3). ``Rückgabewert``: Datei Handle zum SPI-Bus > -1 ... Ungültig bzw. nicht geöffnet From b681bc7479f9da0ef0ea67b719e63c1fc16ccb42 Mon Sep 17 00:00:00 2001 From: mstroh Date: Sat, 1 Mar 2025 11:48:23 +0100 Subject: [PATCH 12/14] #324 Full SPI function translation --- documentation/english/functions.md | 109 ++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/documentation/english/functions.md b/documentation/english/functions.md index 4a6a461..16e7d09 100644 --- a/documentation/english/functions.md +++ b/documentation/english/functions.md @@ -567,4 +567,111 @@ else { ## SPI - Bus -... +Functions that start with ``wiringPiSPIx`` are new since version 3, allowing the SPI bus number to be specified. This is especially useful for the Compute Module, which has multiple SPI buses (0-7). The old functions remain available, but they always refer to SPI bus 0, which is available on the 40 pin GPIO connector. + + +### wiringPiSPISetup / wiringPiSPISetupMode / wiringPiSPIxSetupMode + +Opens the specified SPI bus. + +>>> +```C +int wiringPiSPISetup (int channel, int speed) +int wiringPiSPISetup (int channel, int speed, int mode) +int wiringPiSPIxSetupMode(const int number, const int channel, const int speed, const int mode) +``` + +``number``: SPI muber (typically 0, on Compute Module 0-7). +``channel``: SPI channel (typically 0 or 1, on Compute Module 0-3.). +``speed``: SPI clock. +``mode``: SPI mode (https://www.kernel.org/doc/Documentation/spi/spidev). +``Return Value``: File handle to the SPI bus +> -1 ... Error or EXIT (Programm termination) + +**Example** +>>> +```C +const int spiChannel = 1; +const int spiSpeedInit = 250000; // Hz +int hSPI; + +if ((hSPI = wiringPiSPISetup (spiChannel, spiSpeed)) < 0) { + //error +} + +//operate SPI + +wiringPiSPIClose(spiChannel); +``` + +### wiringPiSPIDataRW / wiringPiSPIxDataRW + +A synchronous fullduplex write and read operation is performed on the opened SPI bus. In the process, the sent data is overwritten by the received data. + +>>> +```C +int wiringPiSPIDataRW (int channel, unsigned char *data, int len) +int wiringPiSPIxDataRW (const int number, const int channel, unsigned char *data, const int len) +``` + +``number``: SPI muber (typically 0, on Compute Module 0-7). +``channel``: SPI channel (typically 0 or 1, on Compute Module 0-3.). +``data``: Buffer +``len``: Size of ``data`` buffer or data size. +``Return Value``: Return Value of ``ioctl`` function (https://man7.org/linux/man-pages/man2/ioctl.2.html) +<0 ... Error, see ``errno`` for error number. + +**Example** +>>> +```C +const int spiChannel = 1; +const int spiSpeedInit = 250000; // Hz +int hSPI; + +if ((hSPI = wiringPiSPIxSetupMode (0, spiChannel, spiSpeed, 0)) < 0) { + //error +} +unsigned char spiData[3]; +int returnvalue; + +spiData[0] = 0b11010000; +spiData[1] = 0; +spiData[2] = 0; +returnvalue = wiringPiSPIxDataRW(0, spiChannel, spiData, 3); +if (returnvalue<=0) { + printf("SPI transfer error: %d\n", errno); +} + +wiringPiSPIxClose(0, spiChannel); +``` + +### wiringPiSPIGetFd / wiringPiSPIxGetFd + +Returns the file handle to the opened SPI bus. + +>>> +```C +int wiringPiSPIGetFd(int channel) +int wiringPiSPIxGetFd(const int number, int channel) +``` + +``number``: SPI muber (typically 0, on Compute Module 0-7). +``channel``: SPI channel (typically 0 or 1, on Compute Module 0-3.). +``Return Value``: File handle to the SPI bus +> -1 ... Invalid or not opened + +**Example** +>>> +```C +const int spiChannel = 1; +const int spiSpeedInit = 250000; // Hz +int hSPI; + +if ((hSPI = wiringPiSPISetup (spiChannel, spiSpeed)) < 0) { + //error +} + +int fd_spi = wiringPiSPIGetFd(spiChannel); + +wiringPiSPIClose(spiChannel); +``` From 63a145b0c748f0d90c0a5b70ca421bb66384be61 Mon Sep 17 00:00:00 2001 From: mstroh Date: Sat, 1 Mar 2025 11:50:16 +0100 Subject: [PATCH 13/14] #324 --- documentation/english/functions.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/documentation/english/functions.md b/documentation/english/functions.md index 16e7d09..a277e80 100644 --- a/documentation/english/functions.md +++ b/documentation/english/functions.md @@ -582,7 +582,7 @@ int wiringPiSPIxSetupMode(const int number, const int channel, const int speed, ``` ``number``: SPI muber (typically 0, on Compute Module 0-7). -``channel``: SPI channel (typically 0 or 1, on Compute Module 0-3.). +``channel``: SPI channel (typically 0 or 1, on Compute Module 0-3). ``speed``: SPI clock. ``mode``: SPI mode (https://www.kernel.org/doc/Documentation/spi/spidev). ``Return Value``: File handle to the SPI bus @@ -615,7 +615,7 @@ int wiringPiSPIxDataRW (const int number, const int channel, unsigned char *data ``` ``number``: SPI muber (typically 0, on Compute Module 0-7). -``channel``: SPI channel (typically 0 or 1, on Compute Module 0-3.). +``channel``: SPI channel (typically 0 or 1, on Compute Module 0-3). ``data``: Buffer ``len``: Size of ``data`` buffer or data size. ``Return Value``: Return Value of ``ioctl`` function (https://man7.org/linux/man-pages/man2/ioctl.2.html) @@ -656,7 +656,7 @@ int wiringPiSPIxGetFd(const int number, int channel) ``` ``number``: SPI muber (typically 0, on Compute Module 0-7). -``channel``: SPI channel (typically 0 or 1, on Compute Module 0-3.). +``channel``: SPI channel (typically 0 or 1, on Compute Module 0-3). ``Return Value``: File handle to the SPI bus > -1 ... Invalid or not opened From deb675d785de3e4928636caba9f8389cb43db51c Mon Sep 17 00:00:00 2001 From: mstroh Date: Sat, 1 Mar 2025 11:55:28 +0100 Subject: [PATCH 14/14] #324 Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 7125be7..26d4a6e 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,12 @@ pi@wiringdemo:~ $ gpio readall ``` +## Documentation + +[German](https://github.com/WiringPi/WiringPi/blob/docu/documentation/deutsch/functions.md) +[English](https://github.com/WiringPi/WiringPi/blob/docu/documentation/english/functions.md) + + ## Installing You can either build it yourself or use the prebuilt binaries: