2017-01-26 08:13:01 -04:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2024-07-09 00:19:52 -03:00
|
|
|
#include "AP_Notify_config.h"
|
|
|
|
|
|
|
|
#if AP_NOTIFY_GPIO_LED_RGB_ENABLED
|
|
|
|
|
2017-01-26 08:13:01 -04:00
|
|
|
#include "PixRacerLED.h"
|
|
|
|
|
2022-02-28 21:19:12 -04:00
|
|
|
#include <AP_HAL/HAL.h>
|
|
|
|
|
2024-07-09 00:19:52 -03:00
|
|
|
#ifndef AP_NOTIFY_GPIO_LED_RGB_RED_PIN
|
|
|
|
#error "define AP_NOTIFY_GPIO_LED_RGB_RED_PIN"
|
2018-06-26 20:58:02 -03:00
|
|
|
#endif
|
2024-07-09 00:19:52 -03:00
|
|
|
#ifndef AP_NOTIFY_GPIO_LED_RGB_GREEN_PIN
|
|
|
|
#error "define AP_NOTIFY_GPIO_LED_RGB_GREEN_PIN"
|
2018-06-26 20:58:02 -03:00
|
|
|
#endif
|
2024-07-09 00:19:52 -03:00
|
|
|
#ifndef AP_NOTIFY_GPIO_LED_RGB_BLUE_PIN
|
|
|
|
#error "define AP_NOTIFY_GPIO_LED_RGB_BLUE_PIN"
|
2018-06-26 20:58:02 -03:00
|
|
|
#endif
|
|
|
|
|
2017-01-26 08:13:01 -04:00
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
|
|
|
PixRacerLED::PixRacerLED() :
|
2018-10-07 02:46:12 -03:00
|
|
|
RGBLed(0, 1, 1, 1)
|
2017-01-26 08:13:01 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-03-28 22:44:23 -03:00
|
|
|
bool PixRacerLED::init(void)
|
2017-01-26 08:13:01 -04:00
|
|
|
{
|
2019-05-03 00:57:33 -03:00
|
|
|
// when HAL_GPIO_LED_ON is 0 then we must not use pinMode()
|
|
|
|
// as it could remove the OPENDRAIN attribute on the pin
|
|
|
|
#if HAL_GPIO_LED_ON != 0
|
2024-07-09 00:19:52 -03:00
|
|
|
hal.gpio->pinMode(AP_NOTIFY_GPIO_LED_RGB_RED_PIN, HAL_GPIO_OUTPUT);
|
|
|
|
hal.gpio->pinMode(AP_NOTIFY_GPIO_LED_RGB_GREEN_PIN, HAL_GPIO_OUTPUT);
|
|
|
|
hal.gpio->pinMode(AP_NOTIFY_GPIO_LED_RGB_BLUE_PIN, HAL_GPIO_OUTPUT);
|
2019-05-03 00:57:33 -03:00
|
|
|
#endif
|
2024-07-09 00:19:52 -03:00
|
|
|
hal.gpio->write(AP_NOTIFY_GPIO_LED_RGB_RED_PIN, HAL_GPIO_LED_OFF);
|
|
|
|
hal.gpio->write(AP_NOTIFY_GPIO_LED_RGB_GREEN_PIN, HAL_GPIO_LED_OFF);
|
|
|
|
hal.gpio->write(AP_NOTIFY_GPIO_LED_RGB_BLUE_PIN, HAL_GPIO_LED_OFF);
|
2017-01-26 08:13:01 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PixRacerLED::hw_set_rgb(uint8_t r, uint8_t g, uint8_t b)
|
|
|
|
{
|
2024-07-09 00:19:52 -03:00
|
|
|
hal.gpio->write(AP_NOTIFY_GPIO_LED_RGB_RED_PIN, (r > 0)?HAL_GPIO_LED_ON:HAL_GPIO_LED_OFF);
|
|
|
|
hal.gpio->write(AP_NOTIFY_GPIO_LED_RGB_GREEN_PIN, (g > 0)?HAL_GPIO_LED_ON:HAL_GPIO_LED_OFF);
|
|
|
|
hal.gpio->write(AP_NOTIFY_GPIO_LED_RGB_BLUE_PIN, (b > 0)?HAL_GPIO_LED_ON:HAL_GPIO_LED_OFF);
|
2017-01-26 08:13:01 -04:00
|
|
|
return true;
|
|
|
|
}
|
2017-01-26 20:16:12 -04:00
|
|
|
|
2024-07-09 00:19:52 -03:00
|
|
|
#endif // AP_NOTIFY_GPIO_LED_RGB_ENABLED
|