diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e62a90..babec09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,18 +4,17 @@ project(spidev-lib) set(CMAKE_CXX_FLAGS "-g -Wall") set(CMAKE_C_FLAGS "-g -Wall") -include_directories(src/) - - add_library(spidev-lib src/spidev_lib.c) -add_executable( - spi-testc sample/spidev-testc.c -) -target_link_libraries( spi-testc spidev-lib) +target_include_directories(spidev-lib PUBLIC src/) + +add_executable(spi-testc sample/spidev-testc.c) +target_link_libraries(spi-testc spidev-lib) add_library(spidev-lib++ src/spidev_lib++.cc) +target_include_directories(spidev-lib++ PUBLIC src/) + add_executable(spi-testcpp sample/spidev-testcpp.cc) -target_link_libraries( spi-testcpp spidev-lib++ ) +target_link_libraries(spi-testcpp spidev-lib++) add_dependencies(spi-testcpp spidev-lib++) add_dependencies(spi-testc spidev-lib) @@ -27,4 +26,3 @@ INSTALL(TARGETS spidev-lib spidev-lib++ ) INSTALL( FILES src/spidev_lib.h DESTINATION include) INSTALL( FILES src/spidev_lib++.h DESTINATION include) - diff --git a/src/spidev_lib++.cc b/src/spidev_lib++.cc index b6f95d8..6f3e8d0 100644 --- a/src/spidev_lib++.cc +++ b/src/spidev_lib++.cc @@ -76,7 +76,7 @@ bool SPI::setMode(uint8_t p_mode){ } -int SPI::xfer(uint8_t *p_txbuffer, uint8_t p_txlen, uint8_t *p_rxbuffer, uint8_t p_rxlen){ +int SPI::xfer(uint8_t *p_txbuffer, uint32_t p_txlen, uint8_t *p_rxbuffer, uint32_t p_rxlen){ struct spi_ioc_transfer spi_message[1]; memset(spi_message, 0, sizeof(spi_message)); @@ -86,7 +86,7 @@ int SPI::xfer(uint8_t *p_txbuffer, uint8_t p_txlen, uint8_t *p_rxbuffer, uint8_t return ioctl(m_spifd, SPI_IOC_MESSAGE(1), spi_message); } -int SPI::write(uint8_t *p_txbuffer,uint8_t p_txlen){ +int SPI::write(uint8_t *p_txbuffer, uint32_t p_txlen){ struct spi_ioc_transfer spi_message[1]; memset(spi_message, 0, sizeof(spi_message)); spi_message[0].tx_buf = (unsigned long)p_txbuffer; @@ -96,7 +96,7 @@ int SPI::write(uint8_t *p_txbuffer,uint8_t p_txlen){ } -int SPI::read(uint8_t *p_rxbuffer,uint8_t p_rxlen){ +int SPI::read(uint8_t *p_rxbuffer, uint32_t p_rxlen){ struct spi_ioc_transfer spi_message[1]; memset(spi_message, 0, sizeof(spi_message)); diff --git a/src/spidev_lib++.h b/src/spidev_lib++.h index 80683fb..c87b422 100644 --- a/src/spidev_lib++.h +++ b/src/spidev_lib++.h @@ -53,9 +53,9 @@ bool m_open; ~SPI(); bool begin(); bool end(); - int read(uint8_t *p_rxbuffer,uint8_t p_rxlen); - int write(uint8_t *p_txbuffer,uint8_t p_txlen); - int xfer(uint8_t *p_txbuffer, uint8_t p_txlen, uint8_t *p_rxbuffer, uint8_t p_rxlen); + int read(uint8_t *p_rxbuffer, uint32_t p_rxlen); + int write(uint8_t *p_txbuffer, uint32_t p_txlen); + int xfer(uint8_t *p_txbuffer, uint32_t p_txlen, uint8_t *p_rxbuffer, uint32_t p_rxlen); bool setSpeed(uint32_t p_speed); bool setMode(uint8_t p_mode); bool setBitPerWord(uint8_t p_bit); diff --git a/src/spidev_lib.c b/src/spidev_lib.c index 633cf6d..cbde94f 100644 --- a/src/spidev_lib.c +++ b/src/spidev_lib.c @@ -77,7 +77,7 @@ int spi_close(int fd) { return close(fd); } -int spi_xfer(int fd, uint8_t *tx_buffer, uint8_t tx_len, uint8_t *rx_buffer, uint8_t rx_len){ +int spi_xfer(int fd, uint8_t *tx_buffer, uint32_t tx_len, uint8_t *rx_buffer, uint32_t rx_len){ struct spi_ioc_transfer spi_message[1]; memset(spi_message, 0, sizeof(spi_message)); @@ -88,7 +88,7 @@ int spi_xfer(int fd, uint8_t *tx_buffer, uint8_t tx_len, uint8_t *rx_buffer, uin return ioctl(fd, SPI_IOC_MESSAGE(1), spi_message); } -int spi_read(int fd, uint8_t *rx_buffer, uint8_t rx_len){ +int spi_read(int fd, uint8_t *rx_buffer, uint32_t rx_len){ struct spi_ioc_transfer spi_message[1]; memset(spi_message, 0, sizeof(spi_message)); @@ -99,7 +99,7 @@ int spi_read(int fd, uint8_t *rx_buffer, uint8_t rx_len){ return ioctl(fd, SPI_IOC_MESSAGE(1), spi_message); } -int spi_write(int fd, uint8_t *tx_buffer, uint8_t tx_len){ +int spi_write(int fd, uint8_t *tx_buffer, uint32_t tx_len){ struct spi_ioc_transfer spi_message[1]; memset(spi_message, 0, sizeof(spi_message)); diff --git a/src/spidev_lib.h b/src/spidev_lib.h index cadc79f..f4b353e 100644 --- a/src/spidev_lib.h +++ b/src/spidev_lib.h @@ -39,9 +39,9 @@ typedef struct { int spi_open(char *device, spi_config_t config); int spi_close(int fd); -int spi_xfer(int fd, uint8_t *tx_buffer, uint8_t tx_len, uint8_t *rx_buffer, uint8_t rx_len); -int spi_read(int fd, uint8_t *rx_buffer, uint8_t rx_len); -int spi_write(int fd, uint8_t *tx_buffer, uint8_t tx_len); +int spi_xfer(int fd, uint8_t *tx_buffer, uint32_t tx_len, uint8_t *rx_buffer, uint32_t rx_len); +int spi_read(int fd, uint8_t *rx_buffer, uint32_t rx_len); +int spi_write(int fd, uint8_t *tx_buffer, uint32_t tx_len); #ifdef __cplusplus } #endif