diff --git a/boards/nxp/ucans32k146/pca9685.px4board b/boards/nxp/ucans32k146/pca9685.px4board index e266a314a9..179db4c118 100644 --- a/boards/nxp/ucans32k146/pca9685.px4board +++ b/boards/nxp/ucans32k146/pca9685.px4board @@ -1,8 +1,7 @@ CONFIG_DRIVERS_GPS=n CONFIG_CYPHAL_CANFD_SUPPORT=y -CONFIG_DRIVERS_PCA9685_UCAN=y CONFIG_CYPHAL_UORB_PCA_PWM_SUBSCRIBER=y -CONFIG_DRIVERS_SPI_LED=y CONFIG_CYPHAL_UORB_SPI_LED_SUBSCRIBER=y +CONFIG_DRIVERS_PCA9685_UCAN=y +CONFIG_DRIVERS_SPI_LED=y CONFIG_SYSTEMCMDS_UORB=y - diff --git a/msg/spi_led.msg b/msg/spi_led.msg index 5702b61695..ae0a791ac8 100644 --- a/msg/spi_led.msg +++ b/msg/spi_led.msg @@ -2,9 +2,9 @@ uint64 timestamp # time since system start (microseconds) -uint16 number_leds #total number of leds [0,1001] -uint8 offset_group #offset group (multiple of 13) of leds to control [0,77] -uint32[13] led_values #follows spi 32 bit LED schema for apa102 +uint16 number_leds #total number of leds [0,1000] +uint8 offset_group #offset group (multiple of 10) of leds to control [0,100] +uint32[10] led_values #follows spi 32 bit LED schema for apa102 # [ PAD 1's ][ BRIGHT 0:31 ][ BLU 0:255 ][ GRN 0:255 ][ RED 0:255 ] # [ 31 ... 29 ][ 28 ... 24 ][ 23 ... 16 ][ 15 ... 8 ][ 7 ... 0 ] diff --git a/src/drivers/spi_led/spi_led.cpp b/src/drivers/spi_led/spi_led.cpp index 0e917800bf..be0fd335a4 100644 --- a/src/drivers/spi_led/spi_led.cpp +++ b/src/drivers/spi_led/spi_led.cpp @@ -44,6 +44,8 @@ spi_led::~spi_led() { perf_free(_loop_perf); perf_free(_loop_interval_perf); + delete _buf; + delete _rbuf; } int spi_led::init() @@ -55,22 +57,23 @@ int spi_led::init() } // execute Run() on every spi_led publication + /* if (!_spi_led_sub.registerCallback()) { PX4_ERR("callback registration failed"); return false; } - + */ // alternatively, Run on fixed interval - // ScheduleOnInterval(5000_us); // 2000 us interval, 200 Hz rate + ScheduleOnInterval(100_ms); // 2000 us interval, 200 Hz rate return true; } void spi_led::Run() { + //printf("made it into run()\n"); + if (should_exit()) { - delete _buf; - delete _rbuf; ScheduleClear(); exit_and_cleanup(); return; @@ -80,26 +83,41 @@ void spi_led::Run() perf_count(_loop_interval_perf); if (_spi_led_sub.updated()) { - spi_led_s led_struct; + //printf("spi led sub updated\n"); + struct spi_led_s led_struct; if (_spi_led_sub.copy(&led_struct)) { + //printf("copied\n"); // DO WORK - uint32_t size = led_struct.number_leds + 2; + uint32_t size = led_struct.number_leds + (led_struct.number_leds % 10) + 2; if(size != _size) { _size = size; delete _buf; delete _rbuf; _buf = new uint32_t[size]; _rbuf = new uint32_t[size]; + printf("created buffers\n"); for(uint32_t i = 0; i < size; i++) { _buf[i] = 0x00000000; } _buf[size-1] = 0xFFFFFFFF; } - memcpy(_buf + (led_struct.offset_group*13)+1, &led_struct.led_values, 13); + for(uint32_t i = 0; i < 10; i++) { + _buf[i + (led_struct.offset_group*10) + 1] = led_struct.led_values[i]; + } + + printf("%p \n", _buf); + //memcpy(_buf + (led_struct.offset_group*10)+1, &led_struct.led_values, 10); + //printf("buf: "); + for(uint32_t i = 0; i < size; i++) { + //printf("0x%08" PRIx32 " ", _buf[i]); + } + //printf("\n"); + //printf("copied data\n"); transfer((uint8_t *)_buf, (uint8_t *)_rbuf, _size*4); + printf("transferred\n"); } } diff --git a/src/drivers/spi_led/spi_led.hpp b/src/drivers/spi_led/spi_led.hpp index 3a4a7bd207..7c31d1d631 100644 --- a/src/drivers/spi_led/spi_led.hpp +++ b/src/drivers/spi_led/spi_led.hpp @@ -31,6 +31,10 @@ * ****************************************************************************/ +/* Authors: Landon Haugh (landon.haugh@nxp.com) + * Benjamin Perseghetti (benjamin.perseghetti@nxp.com) + */ + #pragma once #include @@ -84,7 +88,7 @@ private: (ParamInt) _param_sys_autoconfig /**< another parameter */ ) - uint32_t *_buf; - uint32_t *_rbuf; - uint32_t _size; + uint32_t *_buf = new uint32_t[10]; + uint32_t *_rbuf = new uint32_t[10]; + uint32_t _size = 0; };