This commit is contained in:
j3d1 2022-09-24 07:48:47 +02:00
parent 9c5fb65a90
commit 1263d7836f
6 changed files with 105 additions and 35 deletions

View file

@ -11,6 +11,24 @@ char syslog_buf[syslog_buffer_size + 1];
volatile unsigned head = 0;
volatile unsigned streams = 0;
const char hex_lookup[] = "0123456789ABCDEF";
char str_i32[] = "00000000";
extern "C" void syslog_i32(const uint32_t val) {
str_i32[1] = hex_lookup[val & 0xF];
str_i32[0] = hex_lookup[(val >> 4) & 0xF];
str_i32[3] = hex_lookup[(val >> 8) & 0xF];
str_i32[2] = hex_lookup[(val >> 12) & 0xF];
str_i32[5] = hex_lookup[(val >> 16) & 0xF];
str_i32[4] = hex_lookup[(val >> 20) & 0xF];
str_i32[7] = hex_lookup[(val >> 24) & 0xF];
str_i32[6] = hex_lookup[(val >> 28) & 0xF];
//
syslog(str_i32);
}
extern "C" void syslog(const char *msg) {
//printf("syslog> %s", msg);
while (char c = *msg++) {

View file

@ -5,12 +5,16 @@
#ifndef FIRMWARE_LOG_H
#define FIRMWARE_LOG_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
void syslog(const char *);
void syslog_i32(const uint32_t);
unsigned syslog_current_tail();
unsigned syslog_data_after(unsigned);

View file

@ -3,6 +3,7 @@
//
#include "lux.h"
#include "log.h"
#include <string.h>
#include <FreeRTOS.h>
@ -15,6 +16,17 @@ extern "C" {
#include <sysparam.h>
}
const auto htons = [](uint16_t x) -> uint16_t {
return ((x) << 8 & 0xFF00) | ((x) >> 8 & 0x00FF);
};
const auto &ntohs = htons;
const auto htonl = [](uint32_t x) -> uint32_t {
return ((x) << 24 & 0xFF000000UL) | ((x) << 8 & 0x00FF0000UL) | ((x) >> 8 & 0x0000FF00UL) |
((x) >> 24 & 0x000000FFUL);
};
const auto &ntohl = htonl;
struct apa10xx_pixel_t {
struct {
unsigned int mod: 5, marker: 3;
@ -60,7 +72,8 @@ namespace fiatlux {
hal_error_t(const char *, hal_error_t *cause) {}
};
constexpr hal_error_t empty_error;
constexpr hal_error_t
empty_error;
enum class hal_module_t {
NONE, SIGNAL, RELAIS, SPI_DIMMER, WS28X, APA10X
@ -264,7 +277,55 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
fiatlux::signal::setup();
fiatlux::relais::setup();
fiatlux::apa10x::setup();
//fiatlux::apa10x::setup();
spi_init(1, SPI_MODE0, SPI_FREQ_DIV_500K, true, SPI_BIG_ENDIAN, false);
/*
CC48 API:
- 12 x 16bit registers
- [2*n] = 12bit constant current value
- [2*n+1] = 8bit PWM value
*/
uint32_t dummy = 0;
union {
struct {
unsigned dat: 16;
unsigned addr: 12;
unsigned op: 4;
} __attribute__((packed));
uint32_t _;
} frame = {._=0};
frame.addr = 0x123;
frame.dat = 0xAA55;
frame.op = 0x7;
auto transfer = [](uint32_t val) -> uint32_t {
uint32_t out = val;
uint32_t in;
spi_transfer(1, &out, &in, 1, SPI_32BIT);
return in;
};
dummy = transfer(frame._);
if(dummy) {
syslog("> ");
syslog_i32(dummy);
syslog("\n");
}
syslog("< ");
syslog_i32(frame._);
syslog("\n");
dummy = 0;
for (volatile int i = 0; i < 512 * 16; ++i);
frame._ = transfer(dummy);
if(frame._) {
syslog("> ");
syslog_i32(frame._);
syslog("\n");
}
while (true) {
/*for (int j = 0; j < 64; j++) {
@ -289,9 +350,9 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
pixel = next_colour(c);
}*/
for (auto &led: leds) {
led = next_color(c);
}
//for (auto &led: leds) {
// led = next_color(c);
//}
for (int i = 0; i < 120; i++)
pixels[i] = {{top_color.r, top_color.g, top_color.b, top_color.a}};
@ -299,9 +360,8 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
for (int i = 120; i < 240; i++)
pixels[i] = {{bottom_color.r, bottom_color.g, bottom_color.b, bottom_color.a}};
ws2812_i2s_update(pixels, PIXEL_RGBW);
fiatlux::write_channel((uint8_t *) &leds[0], lux_apa10xx_number, 4, fiatlux::hal_module_t::APA10X);
//fiatlux::write_channel((uint8_t *) &leds[0], lux_apa10xx_number, 4, fiatlux::hal_module_t::APA10X);
vTaskDelay(200 / portTICK_PERIOD_MS);
}
fiatlux::relais::write_data(true, false);
@ -312,5 +372,7 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
fiatlux::signal::write_data(true);
vTaskDelay(200 / portTICK_PERIOD_MS);
}
}

View file

@ -5,6 +5,8 @@
#ifndef FIRMWARE_LUX_H
#define FIRMWARE_LUX_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -14,10 +16,10 @@ void lux_task(void *pvParameters);
void signal_led(bool state);
typedef struct {
char r;
char g;
char b;
char a;
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
} rgba_t;
extern rgba_t top_color;

View file

@ -30,7 +30,6 @@ using namespace fiatlux;
#define vTaskDelayMs(ms) vTaskDelay((ms) / portTICK_PERIOD_MS)
const char hex_lookup[] = "0123456789ABCDEF\0\0";
uint16_t voltage_val;
@ -232,8 +231,6 @@ void websocket_task(void *pvParameter) {
vTaskDelete(nullptr);
}
char str[] = "L00000000\n";
/**
* This function is called when websocket frame is received.
*
@ -264,17 +261,9 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
bottom_color.r = data[7];
bottom_color.g = data[6];
bottom_color.b = data[5];
str[0] = 'B';
str[2] = hex_lookup[val & 0xF];
str[1] = hex_lookup[(val >> 4) & 0xF];
str[4] = hex_lookup[(val >> 8) & 0xF];
str[3] = hex_lookup[(val >> 12) & 0xF];
str[6] = hex_lookup[(val >> 16) & 0xF];
str[5] = hex_lookup[(val >> 20) & 0xF];
str[8] = hex_lookup[(val >> 24) & 0xF];
str[7] = hex_lookup[(val >> 28) & 0xF];
//
syslog(str);
syslog("B");
syslog_i32(val);
syslog("\n");
//signal_led(false);
res.cmd = (messages::id) 'B';
res.ret = OK;
@ -285,16 +274,9 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
top_color.r = data[7];
top_color.g = data[6];
top_color.b = data[5];
str[0] = 'T';
str[2] = hex_lookup[val & 0xF];
str[1] = hex_lookup[(val >> 4) & 0xF];
str[4] = hex_lookup[(val >> 8) & 0xF];
str[3] = hex_lookup[(val >> 12) & 0xF];
str[6] = hex_lookup[(val >> 16) & 0xF];
str[5] = hex_lookup[(val >> 20) & 0xF];
str[8] = hex_lookup[(val >> 24) & 0xF];
str[7] = hex_lookup[(val >> 28) & 0xF];
syslog(str);
syslog("B");
syslog_i32(val);
syslog("\n");
//signal_led(false);
res.cmd = (messages::id) 'T';
res.ret = OK;

View file

@ -374,6 +374,8 @@
for (var i = 0; i < len; i++)
str += dv.getChar(4 + i);
syslog.innerHTML = syslog.innerHTML.slice(0, offset) + str;
const scrollingElement = (document.scrollingElement || document.body);
scrollingElement.scrollTop = scrollingElement.scrollHeight;
} else
console.log('unknown command', cmd, val);
}