From a4d3a6ea36a8607aa59ff3c065b3305f4d2197f8 Mon Sep 17 00:00:00 2001 From: Aliaksei Chapyzhenka Date: Sat, 10 Aug 2024 18:48:50 -0700 Subject: [PATCH] colorful LEDs --- sw-panel-v3/README.md | 6 +-- sw-panel-v3/lib/main.css | 6 ++- sw-panel-v3/lib/main.js | 30 ++++++----- sw-panel-v3/main/sw-panel-v3-main.c | 80 +++++++++++++++++++++++++++-- sw-panel-v3/package.json | 2 +- 5 files changed, 102 insertions(+), 22 deletions(-) diff --git a/sw-panel-v3/README.md b/sw-panel-v3/README.md index b0be856..a12dedf 100644 --- a/sw-panel-v3/README.md +++ b/sw-panel-v3/README.md @@ -9,14 +9,14 @@ git pull git submodule update --init --recursive ./install.sh esp32c6 -cd ~/work/github/XAPOH/sw-panel-v3 +cd ~/work/github/AI6YP/XAPOH/sw-panel-v3 . ~/work/github/espressif/esp-idf/export.sh idf.py set-target esp32c6 idf.py build # just build -idf.py -p /dev/ttyUSB0 flash # build & flash +idf.py -p /dev/ttyACM0 flash # build & flash -idf.py -p /dev/ttyUSB0 flash monitor # build & flash & monitor -> exit Ctrl+] +idf.py -p /dev/ttyACM0 flash monitor # build & flash & monitor -> exit Ctrl+] ``` diff --git a/sw-panel-v3/lib/main.css b/sw-panel-v3/lib/main.css index 1dbccbc..1fe952d 100644 --- a/sw-panel-v3/lib/main.css +++ b/sw-panel-v3/lib/main.css @@ -30,7 +30,9 @@ body { background-color: #088; color: #fff; border: 0; - font-size: 24px; + padding: 16px; + margin: 8px; + font-size: 32px; /* line-height: 2.5; */ /* padding: 0 20px; */ text-shadow: 1px 1px 1px #000; @@ -77,6 +79,6 @@ h1 { .configs { display: grid; grid-template-columns: 50% 50%; /* 10%; */ - grid-row-gap: 16px; + /* grid-row-gap: 16px; */ } diff --git a/sw-panel-v3/lib/main.js b/sw-panel-v3/lib/main.js index c22b1f6..2e096b1 100644 --- a/sw-panel-v3/lib/main.js +++ b/sw-panel-v3/lib/main.js @@ -5,8 +5,9 @@ const stringify = require('onml/stringify.js'); const sendGpio = (socket, config) => { console.log(config); - socket.send(Uint8Array.from([0, 0, config.gpios[0], config.gpios[1]])); - socket.send(Uint8Array.from([1, 0, config.gpios[2], config.gpios[3]])); + socket.send(Uint8Array.from([0, 0, config.gpios[0], config.gpios[1]])); + socket.send(Uint8Array.from([1, 0, config.gpios[2], config.gpios[3]])); + socket.send(Uint8Array.from([255].concat(config.gpios.slice(4)))); }; global.XAPOH = async (divName) => { @@ -23,12 +24,13 @@ global.XAPOH = async (divName) => { ...state.configs.flatMap((config, i) => [ ['input', {id: `send_cfg${i}`, class: 'btn_item', type: 'button', value: config.name}], // ['input', {class: 'item', type: 'text', value: config.gpios.join('.')}], - ['div', {class: 'item'}, config.gpios.join('.')], + // ['div', {class: 'item'}, config.gpios.join('.')], // ['input', {class: 'btn_item del', type: 'button', value: '\u2715'}] ]), // ['input', {class: 'num_item', type: 'text'}], // ['input', {class: 'num_item', type: 'text'}], // ['input', {class: 'btn_item add', type: 'button', value: '+'}] + // ['input', {id: 'send_lna', class: 'btn_item', type: 'button'}], ], ['div', {class: 'tiny'}, pkg.version] ]; @@ -37,15 +39,19 @@ global.XAPOH = async (divName) => { // }); const state = { - configs: [ - {name: '144', gpios: [6, 125, 8, 4]}, - {name: '432', gpios: [66, 93, 16, 36]}, - {name: '1296', gpios: [38, 125, 16, 64]}, - {name: '2400', gpios: [102, 61, 20, 4]}, - {name: 'SAT A', gpios: [5, 109, 10, 5]}, - {name: 'SAT B', gpios: [10, 69, 18, 37]}, - {name: 'SAT J', gpios: [6, 107, 10, 5]}, - {name: 'SAT Q', gpios: [6, 60, 84, 4]}, + configs: [// I2C0 I2C1 / rgb 0 \ / GRB 1 \ / GRB 2 \ / GRB 3 \ / GRB 4 \ / GRB 5 \ / GRB 6 \ / GRB 7 \ / GRB 8 \ / GRB 9 \ / GRB 10\ + {name: '144', gpios: [6, 125, 8, 4, 0, 5, 0, 100,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}, + {name: '144+', gpios: [6, 125, 8, 20, 0, 5, 0, 0, 0,100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}, + {name: '432', gpios: [66, 93, 16, 36, 0, 5, 0, 0, 0, 0, 100,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}, + {name: '432+', gpios: [66, 93, 16, 52, 0, 5, 0, 0, 0, 0, 0, 0,100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}, + {name: '1296', gpios: [38, 125, 16, 64, 0, 5, 0, 0, 0, 0, 0, 0, 0, 100,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}, + {name: '1296+', gpios: [38, 125, 16, 80, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0,100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}, + {name: '2400', gpios: [102, 61, 20, 4, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}, + {name: '2400+', gpios: [102, 61, 20, 20, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}, + {name: 'SAT A', gpios: [5, 109, 10, 5, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 100,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}, + {name: 'SAT B', gpios: [10, 69, 18, 37, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100,0,100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}, + {name: 'SAT J', gpios: [6, 107, 10, 5, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 100,0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}, + {name: 'SAT Q', gpios: [6, 60, 84, 4, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100,0,100, 0, 0, 0, 0, 0, 0]}, ] }; diff --git a/sw-panel-v3/main/sw-panel-v3-main.c b/sw-panel-v3/main/sw-panel-v3-main.c index 2847d3f..159c351 100644 --- a/sw-panel-v3/main/sw-panel-v3-main.c +++ b/sw-panel-v3/main/sw-panel-v3-main.c @@ -13,6 +13,9 @@ #include "driver/gpio.h" #include "driver/i2c_master.h" +#include "driver/rmt_tx.h" + +#include "led_strip_encoder.h" // WIFI #include "esp_wifi.h" @@ -27,6 +30,11 @@ #include "pages.h" +#define RMT_LED_STRIP_RESOLUTION_HZ 10000000 // 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution) +#define RMT_LED_STRIP_GPIO_NUM 8 + +#define NUM_LEDS 11 + // pins #define PWR_SW 0 // pin6 <- #define FUZE_IN 1 // pin7 -> ADC? @@ -36,7 +44,7 @@ #define ON 5 // pin11 <- #define DISPLAY_RS 6 // pin12 <- #define DISPLAY_CS 7 // pin13 <- -#define DISPLAY_CLOCK 8 // pin14 <- +#define RGB 8 // pin14 <- LED Strip #define BOOT 9 // pin15 -> #define DISPLAY_DATA 14 // pin18 <- #define DISPLAY_RESET 15 // pin19 <- @@ -53,7 +61,8 @@ static const char *TAG = "XAPOH"; -#include "lcd.h" + +// #include "lcd.h" /* FreeRTOS event group to signal when we are connected*/ static EventGroupHandle_t s_wifi_event_group; @@ -64,11 +73,26 @@ static EventGroupHandle_t s_wifi_event_group; #define WIFI_CONNECTED_BIT BIT0 #define WIFI_FAIL_BIT BIT1 +struct pixels_s { + uint8_t data[NUM_LEDS * 3]; + // rmt_channel_handle_t led_chan; // = NULL; + // rmt_encoder_handle_t led_encoder; + // rmt_transmit_config_t tx_config; +}; +typedef struct pixels_s pixels_t; + + + static i2c_master_bus_config_t i2c_master; static i2c_device_config_t i2c_dev0; static i2c_device_config_t i2c_dev1; +static pixels_t pixels; +static rmt_channel_handle_t led_chan = NULL; +static rmt_encoder_handle_t led_encoder0 = NULL; + +rmt_transmit_config_t tx_config = { .loop_count = 0, }; static int s_retry_num = 0; @@ -233,6 +257,11 @@ esp_err_t msg_handler(httpd_req_t *req) { httpd_ws_frame_t ws_pkt; uint8_t *buf = NULL; uint8_t *tx_buf = NULL; + rmt_encoder_handle_t led_encoder = NULL; + led_strip_encoder_config_t encoder_config = { + .resolution = RMT_LED_STRIP_RESOLUTION_HZ, + }; + memset(&ws_pkt, 0, sizeof(httpd_ws_frame_t)); ws_pkt.type = HTTPD_WS_TYPE_BINARY; /* Set max_len = 0 to get the frame len */ @@ -260,7 +289,14 @@ esp_err_t msg_handler(httpd_req_t *req) { free(buf); return ret; } - rdwr_i2c(i2c_master, buf, tx_buf, ws_pkt.len); + if (buf[0] == 255) { // RGB LEDS + ESP_LOGI(TAG, "pkt_len: %d", ws_pkt.len); + memcpy(&pixels.data, buf + 1, ws_pkt.len - 1); + ESP_ERROR_CHECK(rmt_transmit(led_chan, led_encoder0, pixels.data, sizeof(pixels.data), &tx_config)); + ESP_ERROR_CHECK(rmt_tx_wait_all_done(led_chan, portMAX_DELAY)); + } else { + rdwr_i2c(i2c_master, buf, tx_buf, ws_pkt.len); + } ws_pkt.payload = tx_buf; } // ESP_LOGI(TAG, "Packet type: %d", ws_pkt.type); @@ -350,8 +386,44 @@ void app_main(void) { rdwr_i2c(i2c_master, default0, default0, 4); rdwr_i2c(i2c_master, default1, default1, 4); + // RGB init + ESP_LOGI(TAG, "Create RMT TX channel"); + rmt_tx_channel_config_t tx_chan_config = { + .clk_src = RMT_CLK_SRC_DEFAULT, // select source clock + .gpio_num = RMT_LED_STRIP_GPIO_NUM, + .mem_block_symbols = 64, // increase the block size can make the LED less flickering + .resolution_hz = RMT_LED_STRIP_RESOLUTION_HZ, + .trans_queue_depth = 4, // set the number of transactions that can be pending in the background + }; + ESP_ERROR_CHECK(rmt_new_tx_channel(&tx_chan_config, &led_chan)); + + + ESP_LOGI(TAG, "Install led strip encoder"); + rmt_encoder_handle_t led_encoder = NULL; + led_strip_encoder_config_t encoder_config = { + .resolution = RMT_LED_STRIP_RESOLUTION_HZ, + }; + ESP_ERROR_CHECK(rmt_new_led_strip_encoder(&encoder_config, &led_encoder)); + led_encoder0 = led_encoder; + + ESP_LOGI(TAG, "Enable RMT TX channel"); + ESP_ERROR_CHECK(rmt_enable(led_chan)); + + // rmt_transmit_config_t tx_config = { + // .loop_count = 0, // no transfer loop + // }; + + pixels = (pixels_t) { .data = { + 0, 0, 5, // r g b + 100,0, 0, // G R B + }}; + + ESP_ERROR_CHECK(rmt_transmit(led_chan, led_encoder0, pixels.data, sizeof(pixels.data), &tx_config)); + ESP_ERROR_CHECK(rmt_tx_wait_all_done(led_chan, portMAX_DELAY)); + + // SPI LCD - lcd_init(spi); + // lcd_init(spi); wifi_init_sta(); start_webserver(); diff --git a/sw-panel-v3/package.json b/sw-panel-v3/package.json index d812cf0..5fb2a7c 100644 --- a/sw-panel-v3/package.json +++ b/sw-panel-v3/package.json @@ -1,6 +1,6 @@ { "name": "xapoh", - "version": "1.1.1", + "version": "1.2.0", "description": "Web XAPOH", "main": "index.js", "directories": {