Driver updates for varible length array.

This commit is contained in:
Benjamin Perseghetti
2022-06-08 14:13:14 -04:00
parent e41766256d
commit b158e23842
4 changed files with 37 additions and 16 deletions
+2 -3
View File
@@ -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
+3 -3
View File
@@ -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 ]
+25 -7
View File
@@ -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");
}
}
+7 -3
View File
@@ -31,6 +31,10 @@
*
****************************************************************************/
/* Authors: Landon Haugh (landon.haugh@nxp.com)
* Benjamin Perseghetti (benjamin.perseghetti@nxp.com)
*/
#pragma once
#include <px4_platform_common/defines.h>
@@ -84,7 +88,7 @@ private:
(ParamInt<px4::params::SYS_AUTOCONFIG>) _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;
};