generic spi_led rename.

This commit is contained in:
Benjamin Perseghetti 2022-06-08 09:56:30 -04:00
parent 163ad0af1f
commit b87897072e
15 changed files with 16 additions and 393 deletions

View File

@ -5,7 +5,7 @@
set UCAN146 1
param set-default UCAN1_PCA_PWM_S 500
param set-default UCAN1_APA102_SUB 501
param set-default UCAN1_SPI_LED_S 501
pca9685_ucan start -X

View File

@ -2,7 +2,7 @@ CONFIG_DRIVERS_GPS=n
CONFIG_CYPHAL_CANFD_SUPPORT=y
CONFIG_DRIVERS_PCA9685_UCAN=y
CONFIG_CYPHAL_UORB_PCA_PWM_SUBSCRIBER=y
CONFIG_DRIVERS_LIGHTS_APA102=y
CONFIG_CYPHAL_UORB_APA102_CONTROL_SUBSCRIBER=y
CONFIG_DRIVERS_SPI_LED=y
CONFIG_CYPHAL_UORB_SPI_LED_SUBSCRIBER=y
CONFIG_SYSTEMCMDS_UORB=y

View File

@ -50,7 +50,6 @@ set(msg_files
airspeed.msg
airspeed_validated.msg
airspeed_wind.msg
apa102_control.msg
autotune_attitude_control_status.msg
battery_status.msg
button_event.msg
@ -159,6 +158,7 @@ set(msg_files
sensor_selection.msg
sensors_status_imu.msg
sensors_status.msg
spi_led.msg
system_power.msg
takeoff_status.msg
task_stack_info.msg

View File

@ -95,8 +95,8 @@ if DRIVERS_CYPHAL
bool "uORB pca_pwm Subscriber"
default n
config CYPHAL_UORB_APA102_CONTROL_SUBSCRIBER
bool "uORB apa102_control Subscriber"
config CYPHAL_UORB_SPI_LED_SUBSCRIBER
bool "uORB spi_led Subscriber"
default n
endmenu

View File

@ -131,7 +131,7 @@ private:
{"uavcan.sub.uorb.sensor_gps.0.id", "UCAN1_UORB_GPS", px4_param_to_uavcan_port_id, uavcan_port_id_to_px4_param},
{"uavcan.pub.uorb.sensor_gps.0.id", "UCAN1_UORB_GPS_P", px4_param_to_uavcan_port_id, uavcan_port_id_to_px4_param},
{"uavcan.sub.uorb.pca_pwm.0.id", "UCAN1_PCA_PWM_S", px4_param_to_uavcan_port_id, uavcan_port_id_to_px4_param},
{"uavcan.sub.uorb.apa102_control.0.id", "UCAN1_APA102_SUB", px4_param_to_uavcan_port_id, uavcan_port_id_to_px4_param},
{"uavcan.sub.uorb.spi_led.0.id", "UCAN1_SPI_LED_S", px4_param_to_uavcan_port_id, uavcan_port_id_to_px4_param},
//{"uavcan.sub.bms.0.id", "UCAN1_BMS0_SUB"}, //FIXME instancing
//{"uavcan.sub.bms.1.id", "UCAN1_BMS1_SUB"},
};

View File

@ -48,7 +48,7 @@
#include <uORB/topics/sensor_gps.h>
#include <uORB/topics/pca_pwm.h>
#include <uORB/topics/apa102_control.h>
#include <uORB/topics/spi_led.h>
template <class T>
class uORB_over_UAVCAN_Subscriber : public UavcanDynamicPortSubscriber

View File

@ -65,8 +65,8 @@
#define CONFIG_CYPHAL_UORB_PCA_PWM_SUBSCRIBER 0
#endif
#ifndef CONFIG_CYPHAL_UORB_AP102_CONTROL_SUBSCRIBER
#define CONFIG_CYPHAL_UORB_AP102_CONTROL_SUBSCRIBER 0
#ifndef CONFIG_CYPHAL_UORB_SPI_LED_SUBSCRIBER
#define CONFIG_CYPHAL_UORB_SPI_LED_SUBSCRIBER 0
#endif
/* Preprocessor calculation of Subscribers count */
@ -77,7 +77,7 @@
CONFIG_CYPHAL_BMS_SUBSCRIBER + \
CONFIG_CYPHAL_UORB_SENSOR_GPS_SUBSCRIBER + \
CONFIG_CYPHAL_UORB_PCA_PWM_SUBSCRIBER + \
CONFIG_CYPHAL_UORB_AP102_CONTROL_SUBSCRIBER
CONFIG_CYPHAL_UORB_SPI_LED_SUBSCRIBER
#include <px4_platform_common/defines.h>
#include <drivers/drv_hrt.h>
@ -200,13 +200,13 @@ private:
0
},
#endif
#if CONFIG_CYPHAL_UORB_APA102_CONTROL_SUBSCRIBER
#if CONFIG_CYPHAL_UORB_SPI_LED_SUBSCRIBER
{
[](CanardHandle & handle, UavcanParamManager & pmgr) -> UavcanDynamicPortSubscriber *
{
return new uORB_over_UAVCAN_Subscriber<apa102_control_s>(handle, pmgr, ORB_ID(apa102_control));
return new uORB_over_UAVCAN_Subscriber<spi_led_s>(handle, pmgr, ORB_ID(spi_led));
},
"uorb.apa102_control",
"uorb.spi_led",
0
},
#endif

View File

@ -161,13 +161,13 @@ PARAM_DEFINE_INT32(UCAN1_UORB_GPS_P, -1);
PARAM_DEFINE_INT32(UCAN1_PCA_PWM_S, -1);
/**
* apa102_control uORB over Cyphal subscription port ID.
* spi_led uORB over Cyphal subscription port ID.
*
* @min -1
* @max 6143
* @group Cyphal
*/
PARAM_DEFINE_INT32(UCAN1_APA102_SUB, -1);
PARAM_DEFINE_INT32(UCAN1_SPI_LED_S, -1);
// Publication Port IDs

View File

@ -34,5 +34,4 @@
#add_subdirectory(neopixel) # requires board support (BOARD_HAS_N_S_RGB_LED)
add_subdirectory(rgbled)
add_subdirectory(rgbled_ncp5623c)
add_subdirectory(apa102)
#add_subdirectory(rgbled_pwm) # requires board support (BOARD_HAS_LED_PWM/BOARD_HAS_UI_LED_PWM)

View File

@ -2,7 +2,6 @@ menu "Lights"
menuconfig COMMON_LIGHT
bool "Common Light's"
default n
select DRIVERS_LIGHT_APA102
select DRIVERS_LIGHTS_RGBLED
select DRIVERS_LIGHTS_RGBLED_NCP5623C
---help---

View File

@ -1,41 +0,0 @@
############################################################################
#
# Copyright (c) 2021 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name PX4 nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
px4_add_module(
MODULE drivers__apa102
MAIN apa102
SRCS
apa102.cpp
DEPENDS
led
)

View File

@ -1,5 +0,0 @@
menuconfig DRIVERS_LIGHTS_APA102
bool "apa102"
default n
---help---
Enable support for apa102

View File

@ -1,275 +0,0 @@
/****************************************************************************
*
* Copyright (c) 2021 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file apa102.cpp
*
* Driver for the the apa102 class of RGB LED drivers.
* this driver is based on the PX4 led driver
*
*/
#include "apa102.hpp"
// Constructor
APA102::APA102(unsigned int number_of_packages, int bus, uint32_t device, int bus_frequency, spi_mode_e spi_mode) :
SPI(DRV_DEVTYPE_UNUSED, MODULE_NAME, bus, device, spi_mode, bus_frequency),
ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::lp_default),
_number_of_packages(number_of_packages)
{
}
// Deconstructor
APA102::~APA102()
{
//TODO: deinit SPI bus
//apa102_deinit();
}
// Init
// This runs after calling the constructor
int APA102::init()
{
// Init SPI bus
int ret = SPI::init();
if (ret != OK) {
printf("SPI::init() failed\n");
DEVICE_DEBUG("SPI init failed");
return -EIO;
}
// Fill buffer with zeros
for (uint8_t i = 0; i < (_number_of_packages * 4) + 8; i++) {
buf[i] = 0x00;
}
// APA102LEDData is just the data format for the BRG LED
_leds = new apa102::APA102LEDData [_number_of_packages];
if (_leds == nullptr) {
return PX4_ERROR;
}
ScheduleNow();
return OK;
}
//
int APA102::task_spawn(int argc, char *argv[])
{
int myoptind = 1;
int ch;
const char *myoptarg = nullptr;
unsigned int number_of_packages = BOARD_MAX_LEDS;
while ((ch = px4_getopt(argc, argv, "n:", &myoptind, &myoptarg)) != EOF) {
switch (ch) {
case 'n':
number_of_packages = atoi(myoptarg) + 1;
if (number_of_packages > BOARD_MAX_LEDS) {
number_of_packages = BOARD_MAX_LEDS;
PX4_INFO("Number of packages can not exceed BOARD_MAX_LEDS");
}
break;
default:
print_usage("unrecognized option");
return 1;
}
}
printf("Number of packages: %d\n", number_of_packages);
APA102 *instance = new APA102(number_of_packages, 1, 0, 4000000, SPIDEV_MODE0);
if (instance) {
_object.store(instance);
_task_id = task_id_is_work_queue;
if (instance->init() == PX4_OK) {
return PX4_OK;
}
} else {
PX4_ERR("alloc failed");
}
delete instance;
_object.store(nullptr);
_task_id = -1;
return PX4_ERROR;
}
int APA102::print_status()
{
PX4_INFO("Controlling %i LEDs", _number_of_packages);
return 0;
}
int APA102::print_usage(const char *reason)
{
if (reason) {
PX4_WARN("%s\n", reason);
}
PRINT_MODULE_DESCRIPTION(
R"DESCR_STR(
### Description
This module is responsible for driving interfasing to the Neopixel Serial LED
### Examples
It is typically started with:
$ apa102 -n 8
To drive all available leds.
)DESCR_STR");
PRINT_MODULE_USAGE_NAME("newpixel", "driver");
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
return 0;
}
int APA102::custom_command(int argc, char *argv[])
{
return print_usage("unrecognized option");
}
/**
* Main loop function
* This will run periodically by the scheduler
*/
void APA102::Run()
{
if (should_exit()) {
ScheduleClear();
exit_and_cleanup();
return;
}
// Structure for uORB data
LedControlData led_control_data;
// Get LED data from uORB (led_control)
if (_led_controller.update(led_control_data) == 1) {
// Loop through each LED
for (unsigned int led = 1; led < math::min(_number_of_packages, arraySize(led_control_data.leds)); led++) {
// Set brightness
uint8_t brightness = led_control_data.leds[led].brightness;
/* Brightness is not 0-255, it is 5 bit, so 0-31. 256/32=8 */
brightness = brightness / 8;
//printf("BRIGHTNESS: %d\n", brightness);
//printf("arraySize(%d)\n", arraySize(led_control_data.leds));
// Use data from uORB to set specific APA102LEDData fields
switch (led_control_data.leds[led].color) {
case led_control_s::COLOR_RED:
_leds[led].R() = 255; _leds[led].G() = 0; _leds[led].B() = 0;
break;
case led_control_s::COLOR_DIM_RED:
_leds[led].R() = 16; _leds[led].G() = 0; _leds[led].B() = 0;
break;
case led_control_s::COLOR_GREEN:
_leds[led].R() = 0; _leds[led].G() = 255; _leds[led].B() = 0;
break;
case led_control_s::COLOR_BLUE:
_leds[led].R() = 0; _leds[led].G() = 0; _leds[led].B() = 255;
break;
case led_control_s::COLOR_AMBER: //make it the same as yellow
case led_control_s::COLOR_YELLOW:
_leds[led].R() = 255; _leds[led].G() = 255; _leds[led].B() = 0;
break;
case led_control_s::COLOR_PURPLE:
_leds[led].R() = 255; _leds[led].G() = 0; _leds[led].B() = 255;
break;
case led_control_s::COLOR_CYAN:
_leds[led].R() = 0; _leds[led].G() = 255; _leds[led].B() = 255;
break;
case led_control_s::COLOR_WHITE:
_leds[led].R() = 255; _leds[led].G() = 255; _leds[led].B() = 255;
break;
default: // led_control_s::COLOR_OFF
_leds[led].R() = 0; _leds[led].G() = 0; _leds[led].B() = 0;
break;
} // end switch
/* APA102 Frame
* 0x000000000 [start frame] (this is already done in init)
* 0xE0 + [brightness]
* 0xXXXXXX [bgr]
* 0xFFFFFFFF [end frame]
*/
for(uint8_t i = 1; i < _number_of_packages; i++)
{
buf[4+(4*(i-1))] = 0b11100000 + brightness;
buf[5+(4*(i-1))] = _leds[i].B();
buf[6+(4*(i-1))] = _leds[i].G();
buf[7+(4*(i-1))] = _leds[i].R();
} // end FOR loop
// Fill with end frame
buf[8+(4*_number_of_packages)] = 0xFF;
buf[9+(4*_number_of_packages)] = 0xFF;
buf[10+(4*_number_of_packages)] = 0xFF;
buf[11+(4*_number_of_packages)] = 0xFF;
} // end FOR loop
transfer(buf, rbuf, (_number_of_packages * 4) + 8);
} // end IF statement
ScheduleDelayed(_led_controller.maximum_update_interval());
} // end FUNCTION
// Main function
// This runs when calling the command on the command line
extern "C" __EXPORT int apa102_main(int argc, char *argv[])
{
// This calls task_spawn
return APA102::main(argc, argv);
}

View File

@ -1,54 +0,0 @@
#include <string.h>
#include <px4_platform_common/px4_config.h>
#include <lib/led/led.h>
#include <px4_platform_common/getopt.h>
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
#include <px4_platform_common/log.h>
#include <px4_platform_common/module.h>
#include <drivers/drv_apa102.h>
#include <drivers/device/spi.h>
class APA102 : public device::SPI, public px4::ScheduledWorkItem, public ModuleBase<APA102>
{
public:
APA102(unsigned int number_of_packages, int bus, uint32_t device, int bus_frequency, spi_mode_e spi_mode);
virtual ~APA102();
/** @see ModuleBase */
static int task_spawn(int argc, char *argv[]);
/** @see ModuleBase */
static int custom_command(int argc, char *argv[]);
/** @see ModuleBase */
static int print_usage(const char *reason = nullptr);
void Run() override;
/** @see ModuleBase::print_status() */
int print_status() override;
int init();
int status();
private:
// We don't want to use BOARD_HAS_N_S_RGB_LED, SPI leds are external
unsigned int _number_of_packages;
uint8_t buf[(BOARD_MAX_LEDS * 4) + 8];
uint8_t rbuf[(BOARD_MAX_LEDS * 4) + 8];
// LedController is a driver that takes care of LEDs using the led_control ORB msg.
// Do we really want to use this?
LedController _led_controller;
// ??
APA102(const APA102 &) = delete;
APA102 operator=(const APA102 &) = delete;
// What is this?
// _leds is the actual buffer I believe
apa102::APA102LEDData *_leds;
};