1
- // For license and other informations see LedDeviceWS2812s .h
1
+ // For license and other informations see LedDeviceWS2812b .h
2
2
// To activate: use led device "ws2812s" in the hyperion configuration
3
3
4
4
// STL includes
15
15
// #include <sys/ioctl.h>
16
16
17
17
// hyperion local includes
18
- #include " LedDeviceWS2812s .h"
18
+ #include " LedDeviceWS2812b .h"
19
19
20
20
// ==== Defines and Vars ====
21
21
227
227
228
228
229
229
230
- LedDeviceWS2812s::LedDeviceWS2812s () :
230
+ LedDeviceWS2812b::LedDeviceWS2812b () :
231
231
LedDevice(),
232
232
mLedCount(0 )
233
233
{
@@ -237,7 +237,7 @@ LedDeviceWS2812s::LedDeviceWS2812s() :
237
237
}
238
238
239
239
240
- int LedDeviceWS2812s ::write (const std::vector<ColorRgb> &ledValues)
240
+ int LedDeviceWS2812b ::write (const std::vector<ColorRgb> &ledValues)
241
241
{
242
242
mLedCount = ledValues.size ();
243
243
// printf("Set leds, number: %d\n", mLedCount);
@@ -315,12 +315,12 @@ int LedDeviceWS2812s::write(const std::vector<ColorRgb> &ledValues)
315
315
return 0 ;
316
316
}
317
317
318
- int LedDeviceWS2812s ::switchOff ()
318
+ int LedDeviceWS2812b ::switchOff ()
319
319
{
320
320
return write (std::vector<ColorRgb>(mLedCount , ColorRgb{0 ,0 ,0 }));
321
321
}
322
322
323
- LedDeviceWS2812s ::~LedDeviceWS2812s ()
323
+ LedDeviceWS2812b ::~LedDeviceWS2812b ()
324
324
{
325
325
// Exit cleanly, freeing memory and stopping the DMA & PWM engines
326
326
// We trap all signals (including Ctrl+C), so even if you don't get here, it terminates correctly
@@ -340,7 +340,7 @@ LedDeviceWS2812s::~LedDeviceWS2812s()
340
340
// Convenience functions
341
341
// --------------------------------------------------------------------------------------------------
342
342
// Print some bits of a binary number (2nd arg is how many bits)
343
- void LedDeviceWS2812s ::printBinary (unsigned int i, unsigned int bits) {
343
+ void LedDeviceWS2812b ::printBinary (unsigned int i, unsigned int bits) {
344
344
int x;
345
345
for (x=bits-1 ; x>=0 ; x--) {
346
346
printf (" %d" , (i & (1 << x)) ? 1 : 0 );
@@ -378,7 +378,7 @@ static void udelay(int us) {
378
378
379
379
// Shutdown functions
380
380
// --------------------------------------------------------------------------------------------------
381
- void LedDeviceWS2812s ::terminate (int dummy) {
381
+ void LedDeviceWS2812b ::terminate (int dummy) {
382
382
// Shut down the DMA controller
383
383
if (dma_reg) {
384
384
CLRBIT (dma_reg[DMA_CS], DMA_CS_ACTIVE);
@@ -402,7 +402,7 @@ void LedDeviceWS2812s::terminate(int dummy) {
402
402
// exit(1);
403
403
}
404
404
405
- void LedDeviceWS2812s ::fatal (const char *fmt, ...) {
405
+ void LedDeviceWS2812b ::fatal (const char *fmt, ...) {
406
406
va_list ap;
407
407
va_start (ap, fmt);
408
408
vfprintf (stderr, fmt, ap);
@@ -414,13 +414,13 @@ void LedDeviceWS2812s::fatal(const char *fmt, ...) {
414
414
// Memory management
415
415
// --------------------------------------------------------------------------------------------------
416
416
// Translate from virtual address to physical
417
- unsigned int LedDeviceWS2812s ::mem_virt_to_phys (void *virt) {
417
+ unsigned int LedDeviceWS2812b ::mem_virt_to_phys (void *virt) {
418
418
unsigned int offset = (uint8_t *)virt - virtbase;
419
419
return page_map[offset >> PAGE_SHIFT].physaddr + (offset % PAGE_SIZE);
420
420
}
421
421
422
422
// Translate from physical address to virtual
423
- unsigned int LedDeviceWS2812s ::mem_phys_to_virt (uint32_t phys) {
423
+ unsigned int LedDeviceWS2812b ::mem_phys_to_virt (uint32_t phys) {
424
424
unsigned int pg_offset = phys & (PAGE_SIZE - 1 );
425
425
unsigned int pg_addr = phys - pg_offset;
426
426
@@ -435,7 +435,7 @@ unsigned int LedDeviceWS2812s::mem_phys_to_virt(uint32_t phys) {
435
435
}
436
436
437
437
// Map a peripheral's IO memory into our virtual memory, so we can read/write it directly
438
- void * LedDeviceWS2812s ::map_peripheral (uint32_t base, uint32_t len) {
438
+ void * LedDeviceWS2812b ::map_peripheral (uint32_t base, uint32_t len) {
439
439
int fd = open (" /dev/mem" , O_RDWR);
440
440
void * vaddr;
441
441
@@ -450,15 +450,15 @@ void * LedDeviceWS2812s::map_peripheral(uint32_t base, uint32_t len) {
450
450
}
451
451
452
452
// Zero out the PWM waveform buffer
453
- void LedDeviceWS2812s ::clearPWMBuffer () {
453
+ void LedDeviceWS2812b ::clearPWMBuffer () {
454
454
memset (PWMWaveform, 0 , NUM_DATA_WORDS * 4 ); // Times four because memset deals in bytes.
455
455
}
456
456
457
457
// Set an individual bit in the PWM output array, accounting for word boundaries
458
458
// The (31 - bitIdx) is so that we write the data backwards, correcting its endianness
459
459
// This means getPWMBit will return something other than what was written, so it would be nice
460
460
// if the logic that calls this function would figure it out instead. (However, that's trickier)
461
- void LedDeviceWS2812s ::setPWMBit (unsigned int bitPos, unsigned char bit) {
461
+ void LedDeviceWS2812b ::setPWMBit (unsigned int bitPos, unsigned char bit) {
462
462
463
463
// Fetch word the bit is in
464
464
unsigned int wordOffset = (int )(bitPos / 32 );
@@ -480,7 +480,7 @@ void LedDeviceWS2812s::setPWMBit(unsigned int bitPos, unsigned char bit) {
480
480
481
481
// ==== Init Hardware ====
482
482
483
- void LedDeviceWS2812s ::initHardware () {
483
+ void LedDeviceWS2812b ::initHardware () {
484
484
int pid;
485
485
int fd;
486
486
char pagemap_fn[64 ];
@@ -722,7 +722,7 @@ void LedDeviceWS2812s::initHardware() {
722
722
}
723
723
724
724
// Begin the transfer
725
- void LedDeviceWS2812s ::startTransfer () {
725
+ void LedDeviceWS2812b ::startTransfer () {
726
726
// Enable DMA
727
727
dma_reg[DMA_CONBLK_AD] = mem_virt_to_phys (ctl->cb );
728
728
dma_reg[DMA_CS] = DMA_CS_CONFIGWORD | (1 << DMA_CS_ACTIVE);
0 commit comments