Compare commits
No commits in common. "ab5a62a3f116a28dd081877839b76582b6049bd3" and "97ce195c495fc090810139fa0df8ae8dc4d03e54" have entirely different histories.
ab5a62a3f1
...
97ce195c49
6 changed files with 22 additions and 61 deletions
|
@ -1,10 +1,9 @@
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CX = g++
|
CX = g++
|
||||||
LD = ld
|
LD = ld
|
||||||
VPATH = . ..
|
CFLAGS = -c -Os -fPIC
|
||||||
CFLAGS = -c -Os -fPIC -I../ -I../common
|
|
||||||
|
|
||||||
OBJS = main.o ws2812b.o
|
OBJS = main.o
|
||||||
SLIB = graph.so
|
SLIB = graph.so
|
||||||
|
|
||||||
all: $(SLIB)
|
all: $(SLIB)
|
||||||
|
|
|
@ -5,7 +5,6 @@ import cffi
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
c_header = '''
|
c_header = '''
|
||||||
void test (void);
|
|
||||||
void print_table (void);
|
void print_table (void);
|
||||||
double ComputeRed (double);
|
double ComputeRed (double);
|
||||||
double ComputeGreen (double);
|
double ComputeGreen (double);
|
||||||
|
@ -26,17 +25,16 @@ def plot_colors(C):
|
||||||
plt.grid()
|
plt.grid()
|
||||||
plt.ylabel('Intenzity')
|
plt.ylabel('Intenzity')
|
||||||
plt.xlabel('N')
|
plt.xlabel('N')
|
||||||
plt.savefig('color.png')
|
#plt.savefig('color.png')
|
||||||
#plt.show()
|
plt.show()
|
||||||
|
|
||||||
############################ MAIN ##############################################################
|
############################ MAIN ##############################################################
|
||||||
def main_func():
|
def main_func():
|
||||||
ffi = cffi.FFI()
|
ffi = cffi.FFI()
|
||||||
ffi.cdef(c_header)
|
ffi.cdef(c_header)
|
||||||
C = ffi.dlopen("./graph.so")
|
C = ffi.dlopen("./graph.so")
|
||||||
C.test()
|
|
||||||
plot_colors(C)
|
plot_colors(C)
|
||||||
C.print_table()
|
#C.print_table()
|
||||||
ffi.dlclose(C)
|
ffi.dlclose(C)
|
||||||
return True
|
return True
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -1,22 +1,20 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include "ws2812b.h"
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
extern void test (void);
|
|
||||||
extern void print_table (void);
|
extern void print_table (void);
|
||||||
extern double ComputeRed (double);
|
extern double ComputeRed (double);
|
||||||
extern double ComputeGreen (double);
|
extern double ComputeGreen (double);
|
||||||
extern double ComputeBlue (double);
|
extern double ComputeBlue (double);
|
||||||
};
|
};
|
||||||
union MColor {
|
union Color {
|
||||||
struct _c {
|
struct _c {
|
||||||
uint8_t g, r, b, a;
|
uint8_t g, r, b, a;
|
||||||
explicit _c (const uint8_t _r, const uint8_t _g, const uint8_t _b) noexcept :
|
explicit _c (const uint8_t _r, const uint8_t _g, const uint8_t _b) noexcept :
|
||||||
g(_g), r(_r), b(_b), a(0u) {}
|
g(_g), r(_r), b(_b), a(0u) {}
|
||||||
} c;
|
} c;
|
||||||
uint32_t number;
|
uint32_t number;
|
||||||
explicit MColor (const uint8_t r, const uint8_t g, const uint8_t b) : c(r, g, b) {}
|
explicit Color (const uint8_t r, const uint8_t g, const uint8_t b) : c(r, g, b) {}
|
||||||
};
|
};
|
||||||
#if 0
|
#if 0
|
||||||
static Color getColor (const int index) {
|
static Color getColor (const int index) {
|
||||||
|
@ -40,25 +38,25 @@ static uint8_t Gauss (const double x, const double x0) {
|
||||||
double r = 256.0 * exp (-sigma * arg * arg);
|
double r = 256.0 * exp (-sigma * arg * arg);
|
||||||
return uint8_t (r);
|
return uint8_t (r);
|
||||||
}
|
}
|
||||||
static MColor getColor (const int index) {
|
static Color getColor (const int index) {
|
||||||
uint8_t r=0,g=0,b=0; // proměnné barvy
|
uint8_t r=0,g=0,b=0; // proměnné barvy
|
||||||
r = Gauss(index, 85.333);
|
r = Gauss(index, 85.333);
|
||||||
g = Gauss(index, 170.67);
|
g = Gauss(index, 170.67);
|
||||||
b = Gauss(index, 0.01) + Gauss(index, 256.0);
|
b = Gauss(index, 0.01) + Gauss(index, 256.0);
|
||||||
MColor color(r, g, b);
|
Color color(r, g, b);
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
double ComputeRed (double x) {
|
double ComputeRed (double x) {
|
||||||
MColor c = getColor(x);
|
Color c = getColor(x);
|
||||||
return double (c.c.r);
|
return double (c.c.r);
|
||||||
}
|
}
|
||||||
double ComputeGreen (double x) {
|
double ComputeGreen (double x) {
|
||||||
MColor c = getColor(x);
|
Color c = getColor(x);
|
||||||
return double (c.c.g);
|
return double (c.c.g);
|
||||||
}
|
}
|
||||||
double ComputeBlue (double x) {
|
double ComputeBlue (double x) {
|
||||||
MColor c = getColor(x);
|
Color c = getColor(x);
|
||||||
return double (c.c.b);
|
return double (c.c.b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,42 +66,9 @@ void print_table () {
|
||||||
fprintf(out, "const unsigned table [] = {");
|
fprintf(out, "const unsigned table [] = {");
|
||||||
for (unsigned n=0u; n<256u; n++) {
|
for (unsigned n=0u; n<256u; n++) {
|
||||||
if ((n%8) == 0u) fprintf(out, "\n");
|
if ((n%8) == 0u) fprintf(out, "\n");
|
||||||
const MColor c = getColor(n);
|
const Color c = getColor(n);
|
||||||
fprintf(out, " 0x%06X,", c.number);
|
fprintf(out, " 0x%06X,", c.number);
|
||||||
}
|
}
|
||||||
fprintf(out, "\n};\n");
|
fprintf(out, "\n};\n");
|
||||||
fclose(out);
|
fclose(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr unsigned PADDING = 10 * sizeof (Color);
|
|
||||||
static constexpr unsigned LEDS_LEN = NUMLEDS * sizeof (Color);
|
|
||||||
static constexpr unsigned FULL_LEN = PADDING + LEDS_LEN;
|
|
||||||
static uint8_t buffer [FULL_LEN];
|
|
||||||
void test () {
|
|
||||||
printf ("led color size = %zd\n", sizeof (Color));
|
|
||||||
for (unsigned n=0; n<FULL_LEN; n++) buffer[n] = 0;
|
|
||||||
Color * const cptr = reinterpret_cast<Color*>(buffer + PADDING);
|
|
||||||
for (unsigned n=0; n<NUMLEDS; n++) {
|
|
||||||
Color & c = cptr [n];
|
|
||||||
const OneColor cb (0xff), cg (0x55), cr (0x00);
|
|
||||||
c.b = cb; c.g = cg; c.r = cr;
|
|
||||||
}
|
|
||||||
const unsigned mlen = 1024;
|
|
||||||
char text [mlen];
|
|
||||||
for (unsigned n=0; n<NUMLEDS; n++) {
|
|
||||||
Color & c = cptr [n];
|
|
||||||
unsigned k = 0u;
|
|
||||||
k += c.g.to_string(text + k);
|
|
||||||
text [k++] = '|';
|
|
||||||
k += c.r.to_string(text + k);
|
|
||||||
text [k++] = '|';
|
|
||||||
k += c.b.to_string(text + k);
|
|
||||||
printf("led %d => %s\n", n, text);
|
|
||||||
}
|
|
||||||
printf("buffer dump :");
|
|
||||||
for (unsigned n=0; n<FULL_LEN; n++) {
|
|
||||||
if ((n%10) == 0) printf("\n");
|
|
||||||
printf("<%02x>", buffer[n]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,13 +2,13 @@ const unsigned table [] = {
|
||||||
0xFF0700, 0xFF0700, 0xFF0800, 0xFE0900, 0xFE0A00, 0xFC0A00, 0xFB0B00, 0xF90C00,
|
0xFF0700, 0xFF0700, 0xFF0800, 0xFE0900, 0xFE0A00, 0xFC0A00, 0xFB0B00, 0xF90C00,
|
||||||
0xF80D00, 0xF60E00, 0xF31000, 0xF11100, 0xEE1200, 0xEB1300, 0xE81500, 0xE51600,
|
0xF80D00, 0xF60E00, 0xF31000, 0xF11100, 0xEE1200, 0xEB1300, 0xE81500, 0xE51600,
|
||||||
0xE11800, 0xDE1A00, 0xDA1B00, 0xD61D00, 0xD21F00, 0xCE2100, 0xCA2400, 0xC52600,
|
0xE11800, 0xDE1A00, 0xDA1B00, 0xD61D00, 0xD21F00, 0xCE2100, 0xCA2400, 0xC52600,
|
||||||
0xC12800, 0xBC2B00, 0xB82D00, 0xB33000, 0xAE3300, 0xA93600, 0xA53900, 0xA03C00,
|
0xC12800, 0xBC2B00, 0xB82D00, 0xB33000, 0xAE3300, 0xA93600, 0xA43900, 0xA03C00,
|
||||||
0x9B3F00, 0x964300, 0x914600, 0x8C4A00, 0x884E00, 0x835100, 0x7E5500, 0x795900,
|
0x9B3F00, 0x964300, 0x914600, 0x8C4A00, 0x874E00, 0x835100, 0x7E5500, 0x795900,
|
||||||
0x755D00, 0x706200, 0x6C6600, 0x676A00, 0x636F00, 0x5F7300, 0x5B7800, 0x577C00,
|
0x755D00, 0x706200, 0x6C6600, 0x676A00, 0x636F00, 0x5F7300, 0x5B7800, 0x577C00,
|
||||||
0x538100, 0x4F8600, 0x4B8B00, 0x478F00, 0x449400, 0x409900, 0x3D9E00, 0x3AA300,
|
0x538100, 0x4F8600, 0x4B8B00, 0x478F00, 0x449400, 0x409900, 0x3D9E00, 0x3AA300,
|
||||||
0x37A800, 0x34AC00, 0x31B100, 0x2EB600, 0x2CBB00, 0x29BF00, 0x27C400, 0x24C800,
|
0x37A800, 0x34AC00, 0x31B100, 0x2EB600, 0x2CBB00, 0x29BF00, 0x27C400, 0x24C800,
|
||||||
0x22CC00, 0x20D101, 0x1ED501, 0x1CD901, 0x1ADD01, 0x19E001, 0x17E401, 0x15E702,
|
0x22CD00, 0x20D101, 0x1ED501, 0x1CD901, 0x1ADD01, 0x19E001, 0x17E401, 0x15E702,
|
||||||
0x14EA02, 0x12ED02, 0x11F002, 0x10F202, 0x0FF503, 0x0EF703, 0x0DF903, 0x0CFB04,
|
0x14EA02, 0x12ED02, 0x11F002, 0x10F302, 0x0FF503, 0x0EF703, 0x0DF903, 0x0CFB04,
|
||||||
0x0BFC04, 0x0AFD05, 0x09FE05, 0x08FF06, 0x08FF06, 0x07FF07, 0x06FF07, 0x06FF08,
|
0x0BFC04, 0x0AFD05, 0x09FE05, 0x08FF06, 0x08FF06, 0x07FF07, 0x06FF07, 0x06FF08,
|
||||||
0x05FF09, 0x05FE09, 0x04FD0A, 0x04FC0B, 0x04FA0C, 0x03F80D, 0x03F60E, 0x03F40F,
|
0x05FF09, 0x05FE09, 0x04FD0A, 0x04FC0B, 0x04FA0C, 0x03F80D, 0x03F60E, 0x03F40F,
|
||||||
0x02F210, 0x02EF12, 0x02EC13, 0x02E914, 0x01E616, 0x01E317, 0x01DF19, 0x01DB1B,
|
0x02F210, 0x02EF12, 0x02EC13, 0x02E914, 0x01E616, 0x01E317, 0x01DF19, 0x01DB1B,
|
||||||
|
@ -17,7 +17,7 @@ const unsigned table [] = {
|
||||||
0x008E49, 0x00894C, 0x008450, 0x008054, 0x007B58, 0x00765C, 0x007260, 0x006D64,
|
0x008E49, 0x00894C, 0x008450, 0x008054, 0x007B58, 0x00765C, 0x007260, 0x006D64,
|
||||||
0x006969, 0x00646D, 0x006072, 0x005C76, 0x00587B, 0x005480, 0x005084, 0x004C89,
|
0x006969, 0x00646D, 0x006072, 0x005C76, 0x00587B, 0x005480, 0x005084, 0x004C89,
|
||||||
0x00498E, 0x004593, 0x004298, 0x003E9C, 0x003BA1, 0x0038A6, 0x0035AB, 0x0032B0,
|
0x00498E, 0x004593, 0x004298, 0x003E9C, 0x003BA1, 0x0038A6, 0x0035AB, 0x0032B0,
|
||||||
0x002FB4, 0x002DB9, 0x002ABE, 0x0027C2, 0x0025C7, 0x0023CB, 0x0121CF, 0x011FD3,
|
0x002FB4, 0x002CB9, 0x002ABE, 0x0027C2, 0x0025C7, 0x0023CB, 0x0121CF, 0x011FD3,
|
||||||
0x011DD7, 0x011BDB, 0x0119DF, 0x0117E3, 0x0116E6, 0x0214E9, 0x0213EC, 0x0212EF,
|
0x011DD7, 0x011BDB, 0x0119DF, 0x0117E3, 0x0116E6, 0x0214E9, 0x0213EC, 0x0212EF,
|
||||||
0x0210F2, 0x030FF4, 0x030EF6, 0x030DF8, 0x040CFA, 0x040BFC, 0x040AFD, 0x0509FE,
|
0x0210F2, 0x030FF4, 0x030EF6, 0x030DF8, 0x040CFA, 0x040BFC, 0x040AFD, 0x0509FE,
|
||||||
0x0509FF, 0x0608FF, 0x0607FF, 0x0707FF, 0x0806FF, 0x0806FF, 0x0905FE, 0x0A05FD,
|
0x0509FF, 0x0608FF, 0x0607FF, 0x0707FF, 0x0806FF, 0x0806FF, 0x0905FE, 0x0A05FD,
|
||||||
|
|
|
@ -35,6 +35,8 @@ unsigned OneColor::to_string(char * ptr, const int m) {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ws2812b::ws2812b (FIFO<uint32_t,8> & r) noexcept : OneWay (), ring(r) {
|
||||||
|
}
|
||||||
unsigned int ws2812b::Send (uint8_t * const ptr, const unsigned int len) {
|
unsigned int ws2812b::Send (uint8_t * const ptr, const unsigned int len) {
|
||||||
uint32_t cmd;
|
uint32_t cmd;
|
||||||
while (ring.Read(cmd)) {
|
while (ring.Read(cmd)) {
|
||||||
|
|
|
@ -38,16 +38,13 @@ static constexpr unsigned FIFOLEN = 8u; // min. depth je 8, jinak mocnina 2 >=
|
||||||
* pořád, v 1. části dělá "reset", tedy časování rámce (vysílá nuly).
|
* pořád, v 1. části dělá "reset", tedy časování rámce (vysílá nuly).
|
||||||
* V 2. části si vybere z fronty ring data a uloží je do buferu ve správném
|
* V 2. části si vybere z fronty ring data a uloží je do buferu ve správném
|
||||||
* tvaru. Využívá se toho, že přerušení přijde až na konci a naplnění daty
|
* tvaru. Využívá se toho, že přerušení přijde až na konci a naplnění daty
|
||||||
* netrvá dlouho, takže se přepisuje jen část, která se právě nevysílá.
|
* netrvá dlouho, takže se přepisuje jen část, která se nevysílá.
|
||||||
* Fronta byla použita (celkem zbytečně) protože zatím netuším jaká data posílat.
|
* Fronta byla použita (celkem zbytečně) protože zatím netuším jaká data posílat.
|
||||||
* NOTE
|
|
||||||
* Protože WS2812B je 5V záležitost a procesor je napájen jen 3.3V, funguje to
|
|
||||||
* na hraně a je dobré zapojit mezi MOSI a +5V rezistor 1k. Je to pak stabilnější.
|
|
||||||
* */
|
* */
|
||||||
class ws2812b : public OneWay<uint8_t> {
|
class ws2812b : public OneWay<uint8_t> {
|
||||||
FIFO<uint32_t,FIFOLEN> & ring;
|
FIFO<uint32_t,FIFOLEN> & ring;
|
||||||
public:
|
public:
|
||||||
explicit ws2812b (FIFO<uint32_t,FIFOLEN> & r) noexcept : OneWay (), ring(r) {}
|
explicit ws2812b (FIFO<uint32_t,FIFOLEN> & r) noexcept;
|
||||||
unsigned int Send (uint8_t * const ptr, const unsigned int len) override;
|
unsigned int Send (uint8_t * const ptr, const unsigned int len) override;
|
||||||
protected:
|
protected:
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue