git-svn-id: svn://db.shs.com.ru/pip@567 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -23,7 +23,7 @@ PISPI::PISPI(const PIString & path, uint speed, PIIODevice::DeviceMode mode) : P
|
||||
spi_mode = 0;
|
||||
spi_bits = 8;
|
||||
#ifndef WINDOWS
|
||||
fd = 0;
|
||||
PRIVATE->fd = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -36,18 +36,18 @@ void PISPI::setSpeed(uint speed_hz) {
|
||||
bool PISPI::openDevice() {
|
||||
#ifndef WINDOWS
|
||||
int ret = 0;
|
||||
fd = open(path().dataAscii(), O_RDWR);
|
||||
if (fd < 0) return false;
|
||||
ret = ioctl(fd, SPI_IOC_WR_MODE, &spi_mode);
|
||||
PRIVATE->fd = open(path().dataAscii(), O_RDWR);
|
||||
if (PRIVATE->fd < 0) return false;
|
||||
ret = ioctl(PRIVATE->fd, SPI_IOC_WR_MODE, &spi_mode);
|
||||
if (ret == -1) return false;
|
||||
ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &spi_bits);
|
||||
ret = ioctl(PRIVATE->fd, SPI_IOC_WR_BITS_PER_WORD, &spi_bits);
|
||||
if (ret == -1) return false;
|
||||
ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &spi_speed);
|
||||
ret = ioctl(PRIVATE->fd, SPI_IOC_WR_MAX_SPEED_HZ, &spi_speed);
|
||||
if (ret == -1) return false;
|
||||
piCout << "SPI open" << device << "speed:" << spi_speed/1000 << "KHz" << "mode" << spi_mode << "bits" << spi_bits;
|
||||
spi_ioc_tr.delay_usecs = 0;
|
||||
spi_ioc_tr.speed_hz = spi_speed;
|
||||
spi_ioc_tr.bits_per_word = spi_bits;
|
||||
piCout << "SPI open" << path() << "speed:" << spi_speed/1000 << "KHz" << "mode" << spi_mode << "bits" << spi_bits;
|
||||
PRIVATE->spi_ioc_tr.delay_usecs = 0;
|
||||
PRIVATE->spi_ioc_tr.speed_hz = spi_speed;
|
||||
PRIVATE->spi_ioc_tr.bits_per_word = spi_bits;
|
||||
return true;
|
||||
#else
|
||||
piCoutObj << "PISPI not implemented on windows";
|
||||
@@ -58,7 +58,7 @@ bool PISPI::openDevice() {
|
||||
|
||||
bool PISPI::closeDevice() {
|
||||
#ifndef WINDOWS
|
||||
if (fd) close(fd);
|
||||
if (PRIVATE->fd) close(PRIVATE->fd);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
@@ -78,13 +78,13 @@ int PISPI::writeDevice(const void * data, int max_size) {
|
||||
if (tx_buf.size_s() != max_size) {
|
||||
tx_buf.resize(max_size);
|
||||
rx_buf.resize(max_size);
|
||||
spi_ioc_tr.tx_buf = (ulong)(tx_buf.data());
|
||||
spi_ioc_tr.rx_buf = (ulong)(rx_buf.data());
|
||||
spi_ioc_tr.len = max_size;
|
||||
PRIVATE->spi_ioc_tr.tx_buf = (ulong)(tx_buf.data());
|
||||
PRIVATE->spi_ioc_tr.rx_buf = (ulong)(rx_buf.data());
|
||||
PRIVATE->spi_ioc_tr.len = max_size;
|
||||
}
|
||||
memcpy(tx_buf.data(), data, max_size);
|
||||
int ret;
|
||||
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &spi_ioc_tr);
|
||||
ret = ioctl(PRIVATE->fd, SPI_IOC_MESSAGE(1), &PRIVATE->spi_ioc_tr);
|
||||
if (ret < 1) {piCout << "init can't send spi message" << ret; return -1;}
|
||||
recv_buf.append(rx_buf);
|
||||
return max_size;
|
||||
|
||||
Reference in New Issue
Block a user