Seems to be working exactly like this
This commit is contained in:
parent
713be34f29
commit
b67bd2c198
@ -13,11 +13,11 @@ platform = https://github.com/maxgerhardt/platform-raspberrypi.git
|
|||||||
board = pico
|
board = pico
|
||||||
framework = arduino
|
framework = arduino
|
||||||
platform_packages =
|
platform_packages =
|
||||||
framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git#master
|
framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git#c64a4a58d793ee6d24c7df7ff3ec35adac3bbb45
|
||||||
board_build.core = earlephilhower
|
board_build.core = earlephilhower
|
||||||
upload_port = /run/media/amelia/RPI-RP2/
|
upload_port = /run/media/amelia/RPI-RP2/
|
||||||
debug_tool = cmsis-dap
|
debug_tool = cmsis-dap
|
||||||
;upload_protocol = cmsis-dap
|
upload_protocol = cmsis-dap
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
board_build.filesystem_size = 1m
|
board_build.filesystem_size = 1m
|
||||||
board_build.f_cpu = 133000000L
|
board_build.f_cpu = 133000000L
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
#define INT_ETHERNET
|
#define INT_ETHERNET
|
||||||
//#define INT_WIFI
|
//#define INT_WIFI
|
||||||
|
|
||||||
#define ETH_SPI_SPD 10000000
|
#define ETH_SPI_SPD 64000000
|
||||||
|
|
||||||
// network and universe settings
|
// network and universe settings
|
||||||
|
|
||||||
|
21
src/e131.cpp
21
src/e131.cpp
@ -32,7 +32,7 @@ const PROGMEM byte E131::ACN_ID[12] = { 0x41, 0x53, 0x43, 0x2d, 0x45, 0x31, 0x2e
|
|||||||
const byte E131::ACN_ID[12] = { 0x41, 0x53, 0x43, 0x2d, 0x45, 0x31, 0x2e, 0x31, 0x37, 0x00, 0x00, 0x00 };
|
const byte E131::ACN_ID[12] = { 0x41, 0x53, 0x43, 0x2d, 0x45, 0x31, 0x2e, 0x31, 0x37, 0x00, 0x00, 0x00 };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Wiznet5500lwIP eth(17, SPI, 21); // 17 : cs, 21 : INTn
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -125,12 +125,7 @@ int E131::initWiFi(const char *ssid, const char *passphrase) {
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void E131::begin(e131_listen_t type, uint16_t universe, uint8_t n) {
|
|
||||||
if (type == E131_UNICAST)
|
|
||||||
initUnicast();
|
|
||||||
if (type == E131_MULTICAST)
|
|
||||||
initMulticast(universe, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
int E131::begin(const char *ssid, const char *passphrase) {
|
int E131::begin(const char *ssid, const char *passphrase) {
|
||||||
if (initWiFi(ssid, passphrase)) {
|
if (initWiFi(ssid, passphrase)) {
|
||||||
@ -197,12 +192,12 @@ int E131::beginMulticast(const char *ssid, const char *passphrase,
|
|||||||
#if defined (INT_ETHERNET)
|
#if defined (INT_ETHERNET)
|
||||||
|
|
||||||
/* Unicast Ethernet Initializers */
|
/* Unicast Ethernet Initializers */
|
||||||
int E131::begin() {
|
int E131::begin(Wiznet5500lwIP eth) {
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
|
||||||
if(ETH_MODE == "staticip") {
|
if(ETH_MODE == "staticip") {
|
||||||
Serial.println("Setting static IP");
|
Serial.println("Setting static IP");
|
||||||
eth.config(IP_ADDR, INADDR_NONE);
|
eth.config(IP_ADDR, INADDR_NONE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Serial.println(F("Requesting Address via DHCP"));
|
Serial.println(F("Requesting Address via DHCP"));
|
||||||
@ -215,7 +210,7 @@ int E131::begin() {
|
|||||||
SPI.setSCK(18);
|
SPI.setSCK(18);
|
||||||
SPI.setTX(19);
|
SPI.setTX(19);
|
||||||
eth.setSPISpeed(ETH_SPI_SPD);
|
eth.setSPISpeed(ETH_SPI_SPD);
|
||||||
lwipPollingPeriod(3);
|
lwipPollingPeriod(1);
|
||||||
|
|
||||||
//char * hostname_char;
|
//char * hostname_char;
|
||||||
//HOSTNAME.toCharArray(hostname_char, 32);
|
//HOSTNAME.toCharArray(hostname_char, 32);
|
||||||
@ -248,6 +243,12 @@ int E131::begin() {
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void E131::begin(e131_listen_t type, uint16_t universe, uint8_t n) {
|
||||||
|
if (type == E131_UNICAST)
|
||||||
|
initUnicast();
|
||||||
|
if (type == E131_MULTICAST)
|
||||||
|
initMulticast(universe, n);
|
||||||
|
}
|
||||||
|
|
||||||
/* Multicast Ethernet Initializers */
|
/* Multicast Ethernet Initializers */
|
||||||
int E131::beginMulticast(uint8_t *mac, uint16_t universe, uint8_t n) {
|
int E131::beginMulticast(uint8_t *mac, uint16_t universe, uint8_t n) {
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
//# define INT_ETHERNET
|
//# define INT_ETHERNET
|
||||||
|
|
||||||
|
|
||||||
//#define NO_DOUBLE_BUFFER 1
|
#define NO_DOUBLE_BUFFER 1
|
||||||
/* Defaults */
|
/* Defaults */
|
||||||
#define E131_DEFAULT_PORT 5568
|
#define E131_DEFAULT_PORT 5568
|
||||||
#define WIFI_CONNECT_TIMEOUT 15000 /* 15 seconds */
|
#define WIFI_CONNECT_TIMEOUT 15000 /* 15 seconds */
|
||||||
@ -187,7 +187,7 @@ class E131 {
|
|||||||
/****** START - Ethernet ifdef block ******/
|
/****** START - Ethernet ifdef block ******/
|
||||||
#if defined (INT_ETHERNET)
|
#if defined (INT_ETHERNET)
|
||||||
/* Unicast Ethernet Initializers */
|
/* Unicast Ethernet Initializers */
|
||||||
int begin();
|
int begin(Wiznet5500lwIP eth);
|
||||||
|
|
||||||
/* Multicast Ethernet Initializers */
|
/* Multicast Ethernet Initializers */
|
||||||
int beginMulticast(uint8_t *mac, uint16_t universe, uint8_t n = 1);
|
int beginMulticast(uint8_t *mac, uint16_t universe, uint8_t n = 1);
|
||||||
|
98
src/main.cpp
98
src/main.cpp
@ -9,6 +9,8 @@
|
|||||||
#include <FastLED.h>
|
#include <FastLED.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
|
#include <pico/stdlib.h>
|
||||||
|
#include <hardware/vreg.h>
|
||||||
|
|
||||||
int strips[LED_STRIPS] = {170, 170, 170, 170, 170, 170, 170, 170};
|
int strips[LED_STRIPS] = {170, 170, 170, 170, 170, 170, 170, 170};
|
||||||
// Begin code
|
// Begin code
|
||||||
@ -27,6 +29,7 @@ int universes[LED_STRIPS * 4];
|
|||||||
CRGB ledstrip[MAX_LEDS];
|
CRGB ledstrip[MAX_LEDS];
|
||||||
int pins[8];
|
int pins[8];
|
||||||
|
|
||||||
|
uint8_t * livedata;
|
||||||
// Networking
|
// Networking
|
||||||
|
|
||||||
WebServer httpServer(80);
|
WebServer httpServer(80);
|
||||||
@ -40,8 +43,10 @@ String clientbuffer = "";
|
|||||||
String initinfo = "";
|
String initinfo = "";
|
||||||
bool debug = 1;
|
bool debug = 1;
|
||||||
bool printer = 1;
|
bool printer = 1;
|
||||||
|
int channels = 0;
|
||||||
// Colors (RGB)
|
// Colors (RGB)
|
||||||
int bootsel_count = 0;
|
int bootsel_count = 0;
|
||||||
|
int nopackets = 0;
|
||||||
|
|
||||||
const uint8_t RED[PIXEL_SIZE]= {0x20, 0x00, 0x00};
|
const uint8_t RED[PIXEL_SIZE]= {0x20, 0x00, 0x00};
|
||||||
const uint8_t ORANGE[PIXEL_SIZE]= {0x20, 0x10, 0x00};
|
const uint8_t ORANGE[PIXEL_SIZE]= {0x20, 0x10, 0x00};
|
||||||
@ -55,8 +60,10 @@ const uint8_t WHITE[PIXEL_SIZE]= {0x20, 0x20, 0x20};
|
|||||||
#define MAX_PIXELS_PER_UNIVERSE 512 / PIXEL_SIZE /* Number of pixels */
|
#define MAX_PIXELS_PER_UNIVERSE 512 / PIXEL_SIZE /* Number of pixels */
|
||||||
#define CHANNEL_START 1 /* Channel to start listening at */
|
#define CHANNEL_START 1 /* Channel to start listening at */
|
||||||
|
|
||||||
|
Wiznet5500lwIP eth(17, SPI, 21); //, 21); // 17 : cs, 21 : INTn
|
||||||
E131 e131;
|
E131 e131;
|
||||||
|
|
||||||
|
|
||||||
template <class T> T print(T in) {
|
template <class T> T print(T in) {
|
||||||
Serial.print(String(in));
|
Serial.print(String(in));
|
||||||
if(printer) clientbuffer += String(in);
|
if(printer) clientbuffer += String(in);
|
||||||
@ -212,10 +219,10 @@ void write_universe(long universe, uint8_t data[], long size) {
|
|||||||
PRINTFUNC("Universes size: ");
|
PRINTFUNC("Universes size: ");
|
||||||
PRINTLNFUNC(sizeof(universes));*/
|
PRINTLNFUNC(sizeof(universes));*/
|
||||||
int write_size = universes[universe];
|
int write_size = universes[universe];
|
||||||
PRINTFUNC("Length: ");
|
/*PRINTFUNC("Length: ");
|
||||||
PRINTLNFUNC(write_size * PIXEL_SIZE + (CHANNEL_START - 1) + 2);
|
PRINTLNFUNC(write_size * PIXEL_SIZE + (CHANNEL_START - 1) + 2);
|
||||||
PRINTFUNC("Data: ");
|
PRINTFUNC("Data: ");
|
||||||
PRINTLNFUNC(size);
|
PRINTLNFUNC(size);*/
|
||||||
if (write_size * PIXEL_SIZE + (CHANNEL_START - 1) + 2 > size) {
|
if (write_size * PIXEL_SIZE + (CHANNEL_START - 1) + 2 > size) {
|
||||||
println("Write size too big!!");
|
println("Write size too big!!");
|
||||||
return;
|
return;
|
||||||
@ -247,12 +254,16 @@ void write_universe(long universe, uint8_t data[], long size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
vreg_voltage v = VREG_VOLTAGE_1_20;
|
||||||
|
vreg_set_voltage(v);
|
||||||
|
set_sys_clock_khz(252000, false);
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
//rp2040.wdt_begin(8000);
|
rp2040.wdt_begin(8000);
|
||||||
pinMode(24, INPUT); // VBUS detect - check for USB connection
|
pinMode(24, INPUT); // VBUS detect - check for USB connection
|
||||||
if (digitalRead(24)) {
|
if (digitalRead(24)) {
|
||||||
delay(3000); // Wait for serial
|
delay(3000); // Wait for serial
|
||||||
}
|
}
|
||||||
|
pinMode(21, INPUT);
|
||||||
println("\r\nStarting RGB Controller...");
|
println("\r\nStarting RGB Controller...");
|
||||||
pinMode(20, OUTPUT);
|
pinMode(20, OUTPUT);
|
||||||
println("Resetting W5500 Ethernet Driver...");
|
println("Resetting W5500 Ethernet Driver...");
|
||||||
@ -312,10 +323,46 @@ void setup() {
|
|||||||
rp2040.wdt_reset();
|
rp2040.wdt_reset();
|
||||||
|
|
||||||
println("Configuration loaded.");
|
println("Configuration loaded.");
|
||||||
if (!e131.begin()) {
|
|
||||||
|
if(ETH_MODE == "staticip") {
|
||||||
|
Serial.println("Setting static IP");
|
||||||
|
eth.config(IP_ADDR, INADDR_NONE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Serial.println(F("Requesting Address via DHCP"));
|
||||||
|
}
|
||||||
|
SPI.setRX(16);
|
||||||
|
SPI.setCS(17);
|
||||||
|
SPI.setSCK(18);
|
||||||
|
SPI.setTX(19);
|
||||||
|
eth.setSPISpeed(ETH_SPI_SPD);
|
||||||
|
lwipPollingPeriod(1);
|
||||||
|
|
||||||
|
//char * hostname_char;
|
||||||
|
//HOSTNAME.toCharArray(hostname_char, 32);
|
||||||
|
eth.setHostname(HOSTNAME);
|
||||||
|
|
||||||
|
if (!eth.begin()) {
|
||||||
|
Serial.println("No wired Ethernet hardware detected. Check pinouts, wiring.");
|
||||||
println("Connection failed. Retrying.");
|
println("Connection failed. Retrying.");
|
||||||
rp2040.reboot();
|
rp2040.reboot();
|
||||||
}
|
}
|
||||||
|
int count = 0;
|
||||||
|
while (!eth.connected() && count < 32) {
|
||||||
|
rp2040.wdt_reset();
|
||||||
|
count++;
|
||||||
|
Serial.print(".");
|
||||||
|
delay(250);
|
||||||
|
}
|
||||||
|
if (!eth.connected()) {
|
||||||
|
println("Connection failed. Retrying.");
|
||||||
|
rp2040.reboot();
|
||||||
|
}
|
||||||
|
Serial.print(F("\r\n- IP Address: "));
|
||||||
|
Serial.println(eth.localIP());
|
||||||
|
|
||||||
|
|
||||||
|
e131.begin(E131_UNICAST);
|
||||||
#ifdef INT_WIFI
|
#ifdef INT_WIFI
|
||||||
WiFi.noLowPowerMode();
|
WiFi.noLowPowerMode();
|
||||||
#endif
|
#endif
|
||||||
@ -526,25 +573,33 @@ void setup1() {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
/* Parse a packet */
|
/* Parse a packet */
|
||||||
println("Start loop");
|
//println("Start loop");
|
||||||
int channels = 0;
|
|
||||||
if(channels = e131.parsePacket()) {
|
if(channels = e131.parsePacket()) {
|
||||||
// Offset by start universe
|
// Offset by start universe
|
||||||
// as all local functions count from 0
|
// as all local functions count from 0
|
||||||
status = 0;
|
//delay(0);
|
||||||
if(e131.universe > START_UNIVERSE - 1) {
|
livedata = e131.data;
|
||||||
while (status2 == 1) {
|
|
||||||
delay(0);
|
|
||||||
}
|
|
||||||
write_universe(e131.universe - START_UNIVERSE, e131.data, channels);
|
|
||||||
println("Done Writing");
|
|
||||||
}
|
|
||||||
status = 1;
|
status = 1;
|
||||||
|
delayMicroseconds(5000);
|
||||||
|
//Serial.print(eth.isLinked());
|
||||||
|
nopackets = 0;
|
||||||
}
|
}
|
||||||
println("mid loop");
|
else {
|
||||||
|
nopackets++;
|
||||||
|
}
|
||||||
|
if(nopackets > 50000) {
|
||||||
|
nopackets = 0;
|
||||||
|
println("Resetting network");
|
||||||
|
eth.end();
|
||||||
|
delay(5);
|
||||||
|
eth.begin();
|
||||||
|
println("Reset network");
|
||||||
|
}
|
||||||
|
//println("mid loop");
|
||||||
httpServer.handleClient();
|
httpServer.handleClient();
|
||||||
MDNS.update();
|
MDNS.update();
|
||||||
println("end loop");
|
//println("end loop");
|
||||||
if(newconfig == true) {
|
if(newconfig == true) {
|
||||||
println("Waiting for core 1 to idle...");
|
println("Waiting for core 1 to idle...");
|
||||||
ready = 3;
|
ready = 3;
|
||||||
@ -585,11 +640,16 @@ void loop1() {
|
|||||||
while(ready == 4)
|
while(ready == 4)
|
||||||
delay(50);
|
delay(50);
|
||||||
}
|
}
|
||||||
if(status == 1) {
|
status2 = 1;
|
||||||
status2 = 1;
|
if(status == 1 && e131.universe > START_UNIVERSE - 1 && channels > 0) {
|
||||||
|
write_universe(e131.universe - START_UNIVERSE, livedata, channels);
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
status2 = 0;
|
//println("Done Writing");
|
||||||
|
status = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status2 = 0;
|
||||||
|
|
||||||
if (millis() % 100 > 50) { // reset LED
|
if (millis() % 100 > 50) { // reset LED
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
digitalWrite(LED_BUILTIN, HIGH);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user