Initial commit for Raspberry Pi GPIO ARGB controller

This commit is contained in:
Adam Honse
2024-07-22 01:15:15 -05:00
parent d834b18a16
commit fc411345a3
35 changed files with 4974 additions and 0 deletions

View File

@@ -0,0 +1,138 @@
/*---------------------------------------------------------*\
| RGBController_RaspberryPi_Linux.cpp |
| |
| RGBController for Raspberry Pi GPIO ARGB |
| |
| Adam Honse (CalcProgrammer1) 21 Jul 2024 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#include "RGBController_RaspberryPi_Linux.h"
/**------------------------------------------------------------------*\
@name Raspberry Pi
@category Motherboard
@type GPIO
@save :x:
@direct :white_check_mark:
@effects :x:
@detectors DetectRaspberryPiControllers
@comment
\*-------------------------------------------------------------------*/
RGBController_RaspberryPi::RGBController_RaspberryPi(RaspberryPiController* controller_ptr)
{
controller = controller_ptr;
name = "Raspberry Pi";
type = DEVICE_TYPE_MOTHERBOARD;
vendor = "Raspberry Pi";
description = "Raspberry Pi GPIO Device";
location = controller->GetDeviceLocation();
mode Direct;
Direct.name = "Direct";
Direct.value = 0;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct);
SetupZones();
}
void RGBController_RaspberryPi::SetupZones()
{
/*-------------------------------------------------*\
| Only set LED count on the first run |
\*-------------------------------------------------*/
bool first_run = false;
if(zones.size() == 0)
{
first_run = true;
}
/*-------------------------------------------------*\
| Clear any existing color/LED configuration |
\*-------------------------------------------------*/
leds.clear();
colors.clear();
zones.resize(1);
/*-------------------------------------------------*\
| Set zones and leds |
\*-------------------------------------------------*/
for (unsigned int channel_idx = 0; channel_idx < 1; channel_idx++)
{
char ch_idx_string[2];
snprintf(ch_idx_string, 2, "%d", channel_idx + 1);
zones[channel_idx].name = "Channel ";
zones[channel_idx].name.append(ch_idx_string);
zones[channel_idx].type = ZONE_TYPE_LINEAR;
zones[channel_idx].leds_min = 0;
zones[channel_idx].leds_max = 1000;
if(first_run)
{
zones[channel_idx].leds_count = 0;
}
zones[channel_idx].matrix_map = NULL;
for (unsigned int led_ch_idx = 0; led_ch_idx < zones[channel_idx].leds_count; led_ch_idx++)
{
char led_idx_string[4];
snprintf(led_idx_string, 4, "%d", led_ch_idx + 1);
led new_led;
new_led.name = "Channel ";
new_led.name.append(ch_idx_string);
new_led.name.append(", LED ");
new_led.name.append(led_idx_string);
leds.push_back(new_led);
}
}
controller->SetSize(zones[0].leds_count);
SetupColors();
}
void RGBController_RaspberryPi::ResizeZone(int zone, int new_size)
{
if((size_t) zone >= zones.size())
{
return;
}
if(((unsigned int)new_size >= zones[zone].leds_min) && ((unsigned int)new_size <= zones[zone].leds_max))
{
zones[zone].leds_count = new_size;
SetupZones();
}
}
void RGBController_RaspberryPi::DeviceUpdateLEDs()
{
DeviceUpdateMode();
}
void RGBController_RaspberryPi::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_RaspberryPi::UpdateSingleLED(int /*led*/)
{
DeviceUpdateLEDs();
}
void RGBController_RaspberryPi::DeviceUpdateMode()
{
controller->SetColors(&colors[0]);
}

View File

@@ -0,0 +1,33 @@
/*---------------------------------------------------------*\
| RGBController_RaspberryPi_Linux.h |
| |
| RGBController for Raspberry Pi GPIO ARGB |
| |
| Adam Honse (CalcProgrammer1) 21 Jul 2024 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#pragma once
#include "RaspberryPiController_Linux.h"
#include "RGBController.h"
class RGBController_RaspberryPi : public RGBController
{
public:
RGBController_RaspberryPi(RaspberryPiController* controller_ptr);
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void DeviceUpdateMode();
private:
RaspberryPiController* controller;
};

View File

@@ -0,0 +1,36 @@
/*---------------------------------------------------------*\
| RaspberryPiControllerDetect_Linux.cpp |
| |
| Detector for Raspberry Pi GPIO ARGB |
| |
| Adam Honse (CalcProgrammer1) 21 Jul 2024 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#include <vector>
#include "Detector.h"
#include "RaspberryPiController_Linux.h"
#include "RGBController_RaspberryPi_Linux.h"
/******************************************************************************************\
* *
* DetectRaspberryPiControllers *
* *
* Detect Raspberry Pi controllers *
* *
\******************************************************************************************/
void DetectRaspberryPiControllers()
{
RaspberryPiController* controller = new RaspberryPiController();
if(controller->Initialize())
{
RGBController_RaspberryPi* rgb_controller = new RGBController_RaspberryPi(controller);
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
}
REGISTER_DETECTOR("Raspberry Pi", DetectRaspberryPiControllers);

View File

@@ -0,0 +1,73 @@
/*---------------------------------------------------------*\
| RaspberryPiController_Linux.cpp |
| |
| Driver for Raspberry Pi GPIO ARGB |
| |
| Adam Honse (CalcProgrammer1) 21 Jul 2024 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#include "LogManager.h"
#include "RaspberryPiController_Linux.h"
RaspberryPiController::RaspberryPiController()
{
memset(&rpi_ws2811, 0x00, sizeof(rpi_ws2811));
rpi_ws2811.freq = WS2811_TARGET_FREQ;
rpi_ws2811.dmanum = RPI_WS2811_DMA;
rpi_ws2811.render_wait_time = 0;
rpi_ws2811.channel[0].gpionum = RPI_WS2811_GPIO;
rpi_ws2811.channel[0].invert = 0;
rpi_ws2811.channel[0].count = 0;
rpi_ws2811.channel[0].strip_type = WS2811_STRIP_GBR;
rpi_ws2811.channel[0].brightness = 255;
rpi_ws2811.channel[1].gpionum = 0;
rpi_ws2811.channel[1].invert = 0;
rpi_ws2811.channel[1].count = 0;
rpi_ws2811.channel[1].strip_type = 0;
rpi_ws2811.channel[1].brightness = 0;
}
RaspberryPiController::~RaspberryPiController()
{
ws2811_fini(&rpi_ws2811);
}
std::string RaspberryPiController::GetDeviceLocation()
{
return("GPIO: 13, DMA: 10");
}
bool RaspberryPiController::Initialize()
{
if(ws2811_init(&rpi_ws2811) != WS2811_SUCCESS)
{
LOG_ERROR( "RaspberryPi: ws2811_init() failure");
return(false);
}
return(true);
}
void RaspberryPiController::SetColors(RGBColor * colors)
{
for(int i = 0; i < 2; i++)
{
rpi_ws2811.channel[0].leds[i] = colors[i];
}
ws2811_render(&rpi_ws2811);
}
void RaspberryPiController::SetSize(unsigned int new_size)
{
rpi_ws2811.channel[0].count = new_size;
ws2811_fini(&rpi_ws2811);
Initialize();
}

View File

@@ -0,0 +1,35 @@
/*---------------------------------------------------------*\
| RaspberryPiController_Linux.h |
| |
| Driver for Raspberry Pi GPIO ARGB |
| |
| Adam Honse (CalcProgrammer1) 21 Jul 2024 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#pragma once
#include <string>
#include "RGBController.h"
#include "ws2811.h"
#define RPI_WS2811_DMA 10
#define RPI_WS2811_GPIO 18
class RaspberryPiController
{
public:
RaspberryPiController();
~RaspberryPiController();
std::string GetDeviceLocation();
bool Initialize();
void SetColors(RGBColor * colors);
void SetSize(unsigned int new_size);
private:
ws2811_t rpi_ws2811;
};