MCPcopy Create free account
hub / github.com/WiringPi/WiringPi / requestLineV2

Function requestLineV2

wiringPi/wiringPi.c:1799–1857  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1797
1798
1799int requestLineV2(int pin, const unsigned int lineRequestFlags) {
1800 struct gpio_v2_line_request req;
1801 struct gpio_v2_line_config config;
1802 int ret;
1803
1804 if (lineFds[pin]>=0) {
1805 if (lineRequestFlags == lineFlags[pin]) {
1806 //already requested
1807 return lineFds[pin];
1808 } else {
1809 //different request -> rerequest
1810 releaseLine(pin);
1811 }
1812 }
1813
1814 //requested line
1815 if (wiringPiGpioDeviceGetFd()<0) {
1816 return -1; // error
1817 }
1818
1819 memset(&req, 0, sizeof(req));
1820 memset(&config, 0, sizeof(config));
1821 if (lineRequestFlags & WPI_FLAG_INPUT) {
1822 config.flags |= GPIO_V2_LINE_FLAG_INPUT;
1823 }
1824 if (lineRequestFlags & WPI_FLAG_OUTPUT) {
1825 config.flags |= GPIO_V2_LINE_FLAG_OUTPUT;
1826 }
1827 if (lineRequestFlags & WPI_FLAG_BIAS_OFF) {
1828 config.flags |= GPIO_V2_LINE_FLAG_BIAS_DISABLED;
1829 }
1830 if (lineRequestFlags & WPI_FLAG_BIAS_UP) {
1831 config.flags |= GPIO_V2_LINE_FLAG_BIAS_PULL_UP;
1832 }
1833 if (lineRequestFlags & WPI_FLAG_BIAS_DOWN) {
1834 config.flags |= GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN;
1835 }
1836 if (wiringPiDebug) {
1837 printf ("requestLine flags v2: %llu\n", config.flags);
1838 }
1839 strcpy(req.consumer, "wiringpi_gpio_req");
1840
1841 req.offsets[0] = pin;
1842 req.num_lines = 1;
1843 req.config = config;
1844
1845 ret = ioctl(chipFd, GPIO_V2_GET_LINE_IOCTL, &req);
1846
1847 if (ret || req.fd<0) {
1848 ReportDeviceError("get line handle v2", pin, "RequestLine", ret);
1849 return -1; // error
1850 }
1851
1852 lineFlags[pin] = lineRequestFlags;
1853 lineFds[pin] = req.fd;
1854 if (wiringPiDebug)
1855 printf ("requestLine succeeded: pin:%d, flags: 0x%u, fd :%d\n", pin, lineRequestFlags, lineFds[pin]) ;
1856 return lineFds[pin];

Callers 1

pinModeFlagsDeviceFunction · 0.85

Calls 3

releaseLineFunction · 0.85
wiringPiGpioDeviceGetFdFunction · 0.85
ReportDeviceErrorFunction · 0.85

Tested by

no test coverage detected