Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use 32 bits for lengths #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

6 changes: 3 additions & 3 deletions src/spidev_lib++.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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;
Expand All @@ -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));

Expand Down
6 changes: 3 additions & 3 deletions src/spidev_lib++.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/spidev_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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));

Expand All @@ -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));

Expand Down
6 changes: 3 additions & 3 deletions src/spidev_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down