ws2811.cpp
Go to the documentation of this file.
1 #include "ws2811.h"
2 
3 #include <ros/console.h>
4 #include <memory.h>
5 #include <string.h>
6 
7 typedef struct ws2811_device
8 {
9  int driver_mode;
10  volatile uint8_t *pxl_raw;
11  // volatile dma_t *dma;
12  volatile pwm_t *pwm;
13  // volatile pcm_t *pcm;
14  int spi_fd;
15  // volatile dma_cb_t *dma_cb;
16  uint32_t dma_cb_addr;
17  // volatile gpio_t *gpio;
18  // volatile cm_clk_t *cm_clk;
19  // videocore_mbox_t mbox;
20  int max_count;
22 
24 {
25  ROS_INFO("Initializing mock ws2811");
26  //memset(ws2811, 0, sizeof(*ws2811));
27  //ws2811->rpi_hw = rpi_hw_detect();
28 
29  ws2811->device = (ws2811_device_t*)malloc(sizeof(*ws2811->device));
30  if (!ws2811->device)
31  {
32  return ws2811_return_t::WS2811_ERROR_OUT_OF_MEMORY;
33  }
34 
35  for(int channel = 0; channel < RPI_PWM_CHANNELS; ++channel)
36  {
37  int ledcnt = ws2811->channel[channel].count;
38  if (ledcnt > 0)
39  {
40 
41  ws2811->channel[channel].leds = (ws2811_led_t*)malloc(ledcnt * sizeof(ws2811_led_t));
42  for(int led = 0; led < ledcnt; ++led)
43  {
44  ws2811->channel[channel].leds[led] = 0;
45  }
46  ws2811->channel[channel].gamma = (uint8_t*)malloc(256*sizeof(uint8_t));
47  for(int i = 0; i < 256; ++i)
48  {
49  ws2811->channel[channel].gamma[i] = (uint8_t)i;
50  }
51  }
52  else
53  {
54  ws2811->channel[channel].leds = NULL;
55  ws2811->channel[channel].gamma = NULL;
56  }
57  }
58  return ws2811_return_t::WS2811_SUCCESS;
59 }
60 
61 void ws2811_fini(ws2811_t *ws2811)
62 {
63  ROS_INFO("Finalizing mock ws2811");
64  free(ws2811->device);
65  for(int ch = 0; ch < RPI_PWM_CHANNELS; ++ch)
66  {
67  if (ws2811->channel[ch].count != 0)
68  {
69  free(ws2811->channel[ch].leds);
70  free(ws2811->channel[ch].gamma);
71  }
72  }
73 }
74 
76 {
77  ROS_INFO("Called ws2811_render");
78  for(int ch = 0; ch < RPI_PWM_CHANNELS; ++ch)
79  {
80  int ledcnt = ws2811->channel[ch].count;
81  if (ledcnt > 0)
82  {
83  std::stringstream ledbuf;
84  ledbuf << "[";
85  for(int led = 0; led < ledcnt; ++led)
86  {
87  ledbuf << ws2811->channel[ch].leds[led] << ", ";
88  }
89  ledbuf << "]";
90 
91  ROS_INFO_STREAM("Rendering channel 0: " << ledbuf.str());
92  }
93 
94  }
95  return ws2811_return_t::WS2811_SUCCESS;
96 }
97 
99 {
100  ROS_INFO("Called ws2811_wait");
101  return ws2811_return_t::WS2811_SUCCESS;
102 }
103 
105 #define WS2811_RETURN_STR(state, name, str) str
107 };
108 
109 const char * ws2811_get_return_t_str(const ws2811_return_t state)
110 {
111  int idx = -state;
112  if (idx < sizeof(ws2811_return_state_strings)/sizeof(ws2811_return_state_strings[0]))
113  return ws2811_return_state_strings[idx];
114  return "Unknown/unexpected failure state";
115 }
116 
struct ws2811_device * device
Definition: ws2811.h:89
void ws2811_fini(ws2811_t *ws2811)
Definition: ws2811.cpp:61
uint32_t ws2811_led_t
Definition: ws2811.h:68
volatile pwm_t * pwm
Definition: ws2811.c:107
ws2811_return_t ws2811_wait(ws2811_t *ws2811)
Definition: ws2811.cpp:98
ws2811_channel_t channel[RPI_PWM_CHANNELS]
Definition: ws2811.h:93
#define RPI_PWM_CHANNELS
Definition: pwm.h:54
const char * ws2811_return_state_strings[]
Definition: ws2811.cpp:104
ws2811_return_t
Definition: ws2811.h:116
#define WS2811_RETURN_STATES(X)
Definition: ws2811.h:96
ws2811_return_t ws2811_init(ws2811_t *ws2811)
Definition: ws2811.cpp:23
const char * ws2811_get_return_t_str(const ws2811_return_t state)
Definition: ws2811.cpp:109
int spi_fd
Definition: ws2811.c:109
volatile uint8_t * pxl_raw
Definition: ws2811.c:105
ws2811_led_t * leds
Definition: ws2811.h:77
#define ROS_INFO(...)
struct ws2811_device ws2811_device_t
#define WS2811_RETURN_STR(state, name, str)
uint8_t * gamma
Definition: ws2811.h:83
#define ROS_INFO_STREAM(args)
int max_count
Definition: ws2811.c:115
int driver_mode
Definition: ws2811.c:104
ws2811_return_t ws2811_render(ws2811_t *ws2811)
Definition: ws2811.cpp:75
uint32_t dma_cb_addr
Definition: ws2811.c:111


ws281x
Author(s): Alexey Rogachevskiy , Oleg Kalachev
autogenerated on Wed Jun 15 2022 02:46:00