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

Function wiringPiSPIxSetupMode

wiringPi/wiringPiSPI.c:156–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154
155
156int wiringPiSPIxSetupMode(const int number, const int channel, const int speed, const int mode)
157{
158 int fd ;
159 char spiDev [32] ;
160
161 RETURN_ON_LIMIT_FAIL
162 if (mode<0 || mode>3) { // Mode is 0, 1, 2 or 3 original
163 fprintf (stderr, "wiringPiSPI: Invalid mode (%d, valid range 0-%d)", mode, 3);
164 return -EINVAL;
165 }
166
167 snprintf (spiDev, 31, "/dev/spidev%d.%d", number, channel) ;
168 if ((fd = open (spiDev, O_RDWR)) < 0) {
169 return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device %s: %s\n", spiDev, strerror (errno)) ;
170 }
171 spiSpeeds [number][channel] = speed ;
172 spiFds [number][channel] = fd ;
173
174// Set SPI parameters.
175
176 if (ioctl (fd, SPI_IOC_WR_MODE, &mode) < 0)
177 return wiringPiFailure (WPI_ALMOST, "SPI mode change failure: %s\n", strerror (errno)) ;
178
179 if (ioctl (fd, SPI_IOC_WR_BITS_PER_WORD, &spiBPW) < 0)
180 return wiringPiFailure (WPI_ALMOST, "SPI BPW change failure: %s\n", strerror (errno)) ;
181
182 if (ioctl (fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed) < 0)
183 return wiringPiFailure (WPI_ALMOST, "SPI speed change failure: %s\n", strerror (errno)) ;
184
185 return fd ;
186}
187
188
189int wiringPiSPISetupMode (int channel, int speed, int mode) {

Callers 5

wiringPiSPISetupModeFunction · 0.85
wiringPiSPIxSetupFunction · 0.85
wiringPiSPISetupFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 1

wiringPiFailureFunction · 0.85

Tested by 2

mainFunction · 0.68
mainFunction · 0.68