This commit is contained in:
j3d1 2021-11-18 01:45:35 +01:00
parent b72426b9c7
commit 4b23e5bc09

View file

@ -14,14 +14,8 @@
extern "C" {
#include <sysparam.h>
}
const int signal_led_pin = 2;
const int cs0 = 15;
const int gpio4 = 4;
const int gpio5 = 5;
struct apa10xx_pixel_t {
struct {
unsigned int mod: 5, marker: 3;
@ -56,16 +50,51 @@ static apa10xx_pixel_t next_color(int i) {
namespace fiatlux {
struct hal_error_t {
constexpr hal_error_t() = default;
hal_error_t(const char *) {}
hal_error_t(const char *, hal_error_t *cause) {}
};
constexpr hal_error_t empty_error;
enum class hal_module_t {
NONE, SIGNAL, RELAIS, SPI_DIMMER, WS28X, APA10X
};
namespace ports {
hal_module_t spi = hal_module_t::NONE;
hal_module_t uart = hal_module_t::NONE;
hal_module_t gpio2 = hal_module_t::NONE;
hal_module_t gpio4 = hal_module_t::NONE;
hal_module_t gpio5 = hal_module_t::NONE;
}
namespace signal {
void write_data(bool data) {
gpio_write(signal_led_pin, !data);
gpio_write(2, !data);
}
void setup() {
gpio_enable(2, GPIO_OUTPUT);
}
}
namespace relais {
void write_data(bool a, bool b) {
gpio_write(4, a);
gpio_write(5, b);
}
void write_data(uint8_t data[2]) {
gpio_write(gpio4, (bool) data[0]);
gpio_write(gpio5, (bool) data[1]);
write_data((bool) data[0], (bool) data[1]);
}
void setup() {
gpio_enable(4, GPIO_OUTPUT);
gpio_enable(5, GPIO_OUTPUT);
}
}
@ -91,6 +120,10 @@ namespace fiatlux {
gpio_write(cs0, 0);
}
}
void setup() {
spi_init(1, SPI_MODE0, SPI_FREQ_DIV_1M, 1, SPI_BIG_ENDIAN, 1);
}
}
namespace ws28x {
@ -98,6 +131,10 @@ namespace fiatlux {
ws2812_i2s_init(len, PIXEL_RGBW);
ws2812_i2s_update(data, PIXEL_RGBW);
}
void setup() {
}
}
namespace apa10x {
@ -108,22 +145,12 @@ namespace fiatlux {
spi_transfer_32(1, 0xFFFFFFFF);
spi_transfer_32(1, 0xFFFFFFFF);
}
void setup() {
spi_init(1, SPI_MODE0, SPI_FREQ_DIV_1M, 1, SPI_LITTLE_ENDIAN, false);
}
}
struct hal_error_t {
constexpr hal_error_t() = default;
hal_error_t(const char *) {}
hal_error_t(const char *, hal_error_t *cause) {}
};
constexpr hal_error_t empty_error;
enum class hal_module_t {
SIGNAL, RELAIS, SPI_DIMMER, WS28X, APA10X
};
hal_error_t write_channel(uint8_t *data, size_t count, size_t stride, hal_module_t mod) {
if(mod == hal_module_t::SIGNAL) {
if(count != 1)
@ -154,6 +181,7 @@ namespace fiatlux {
} else {
return "unsupported module";
}
return empty_error;
}
hal_error_t setup_channel(size_t count, size_t stride, hal_module_t mod) {
@ -185,13 +213,13 @@ namespace fiatlux {
apa10x::write_data((apa10xx_pixel_t *) data, count);
} else {
return "unsupported module";
}
return empty_error;*/
}*/
return empty_error;
}
}
ws2812_pixel_t **pixels_ptr;
//ws2812_pixel_t **pixels_ptr;
extern "C" void signal_led(bool state) {
fiatlux::signal::write_data(state);
@ -201,10 +229,7 @@ extern "C" void signal_led(bool state) {
/* This task uses the high level GPIO API (esp_gpio.h) to blink an LED.
*
*/
extern "C" void lux_task(void *pvParameters) {
//gpio_enable(9, GPIO_INPUT);
//gpio_enable(10, GPIO_INPUT);
extern "C" [[noreturn]] void lux_task(void *pvParameters) {
int32_t lux_ws2812_number = 8;
auto ret = sysparam_get_int32("lux_ws2812_number", &lux_ws2812_number);
@ -224,14 +249,18 @@ extern "C" void lux_task(void *pvParameters) {
//lux_apa102c_number
gpio_enable(signal_led_pin, GPIO_OUTPUT);
//gpio_enable(cs0, GPIO_OUTPUT);
gpio_enable(gpio4, GPIO_OUTPUT);
gpio_enable(gpio5, GPIO_OUTPUT);
//spi_init(1, SPI_MODE0, SPI_FREQ_DIV_1M, 1, SPI_BIG_ENDIAN, 1); //for spi dimmer
//gpio_enable(9, GPIO_INPUT);
//gpio_enable(10, GPIO_INPUT);
spi_init(1, SPI_MODE0, SPI_FREQ_DIV_1M, 1, SPI_LITTLE_ENDIAN, false); //for apa10xx
while (1) {
//gpio_enable(cs0, GPIO_OUTPUT);
//fiatlux::spi_dimmer::setup();
fiatlux::signal::setup();
fiatlux::relais::setup();
fiatlux::apa10x::setup();
while (true) {
/*for (int j = 0; j < 64; j++) {
for (int i = 0; i < 8; i++)
spi_dac(i, 64 * j);
@ -247,7 +276,7 @@ extern "C" void lux_task(void *pvParameters) {
gpio_write(gpio5, 1);
vTaskDelay(200 / portTICK_PERIOD_MS);
gpio_write(gpio5, 0);*/
signal_led(0);
fiatlux::signal::write_data(false);
for (int c = 8; c >= 0; c--) {
for (auto &pixel: pixels) {
@ -257,16 +286,15 @@ extern "C" void lux_task(void *pvParameters) {
led = next_color(c);
}
ws2812_i2s_update(pixels, PIXEL_RGBW);
write_leds(leds, lux_apa10xx_number);
fiatlux::write_channel((uint8_t *) &leds[0], lux_apa10xx_number, 4, fiatlux::hal_module_t::APA10X);
vTaskDelay(200 / portTICK_PERIOD_MS);
}
gpio_write(gpio4, 1);
fiatlux::relais::write_data(true, false);
vTaskDelay(200 / portTICK_PERIOD_MS);
gpio_write(gpio4, 0);
gpio_write(gpio5, 1);
fiatlux::relais::write_data(false, true);
vTaskDelay(200 / portTICK_PERIOD_MS);
gpio_write(gpio5, 0);
signal_led(1);
fiatlux::relais::write_data(false, false);
fiatlux::signal::write_data(true);
vTaskDelay(200 / portTICK_PERIOD_MS);
}