#include #include #include #include #include #include #include #include "spi.h" #include "servo.h" static struct spi_message spi_message; static struct spi_result spi_result; static int spi_fd; static uint8_t spi_mode; static uint32_t spi_speed; void spi_open(uint8_t mode, uint32_t speed) { spi_fd=open("/dev/spidev1.0",O_RDWR); if(spi_fd==-1) { perror("spidev1.0"); exit(20); } } void spi_close() { close(spi_fd); } void spi_update_servos() { int i; spi_result.status=SPI_BUSY; // assume busy while(spi_result.status) { if((spi_result.status==SPI_ERR)||(spi_result.status=SPI_DONE)) { spi_message.cmd=CMD_FINISH; write(spi_fd,&spi_message,1); } else if((spi_result.status==SPI_WAIT)) { spi_message.cmd=CMD_CONTINUE; write(spi_fd,&spi_message,1); } read(spi_fd,&spi_result,1); } spi_message.cmd=CMD_SET_SERVOS; spi_message.length=sizeof(servo_pwm); memcpy(spi_message.data,servo_pwm,sizeof(servo_pwm)); spi_message.checksum=0x00; for(i=0;i