MartyMacGyver / ESP32-Digital-RGB-LED-Drivers

ESP32 Digital RGB(W) LED Drivers
MIT License
259 stars 51 forks source link

How to use only ws2812 library without arduinoish.hpp? #15

Closed neosarchizo closed 6 years ago

neosarchizo commented 6 years ago

Hi! Thanks for the great library!

I want to use only ws2812 library in my esp32 project without arduinosh.hpp. My project has the following folder structure:

/ (root)
/main
/components
/components/ws2812
/components/ws2812/include

My main source codes are like following codes.

#include <esp_log.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <math.h>
#include "ws2812.h"

#include "sdkconfig.h"

static char tag[] = "neosarchizo";

const int DATA_PIN = 17;
const uint16_t NUM_PIXELS = 3;
uint8_t MAX_COLOR_VAL = 32;

rgbVal *pixels;

void app_main() {
    ESP_LOGD(tag, "start");
    ws2812_init(DATA_PIN, LED_SK6812);
    pixels = (rgbVal*)malloc(sizeof(rgbVal) * NUM_PIXELS);

    while(1) {
        for(uint16_t i=0; i<NUM_PIXELS; i++) {
            pixels[i] = makeRGBVal(MAX_COLOR_VAL, 0, 0);
        }
        ws2812_setColors(NUM_PIXELS, pixels);
        vTaskDelay(1000/portTICK_PERIOD_MS);
        for (uint16_t i=0; i<NUM_PIXELS; i++) {
            pixels[i] = makeRGBVal(0, MAX_COLOR_VAL, 0);
        }
        ws2812_setColors(NUM_PIXELS, pixels);
        vTaskDelay(1000/portTICK_PERIOD_MS);
        for (uint16_t i=0; i<NUM_PIXELS; i++) {
            pixels[i] = makeRGBVal(0, 0, MAX_COLOR_VAL);
        }
        ws2812_setColors(NUM_PIXELS, pixels);
        vTaskDelay(1000/portTICK_PERIOD_MS);
    }

    vTaskDelete(NULL);
} // task_hmc5883l

But I get following errors when I build it.

/Users/neosarchizo/esp/aqk-device/build/main/libmain.a(aqk_device_main.o):(.literal.app_main+0x10): undefined reference to `ws2812_init'
/Users/neosarchizo/esp/aqk-device/build/main/libmain.a(aqk_device_main.o):(.literal.app_main+0x14): undefined reference to `ws2812_setColors'
/Users/neosarchizo/esp/aqk-device/build/main/libmain.a(aqk_device_main.o): In function `app_main':
/Users/neosarchizo/esp/aqk-device/main/./aqk_device_main.c:19: undefined reference to `ws2812_init'
/Users/neosarchizo/esp/aqk-device/main/./aqk_device_main.c:26: undefined reference to `ws2812_setColors'
/Users/neosarchizo/esp/aqk-device/main/./aqk_device_main.c:28: undefined reference to `ws2812_setColors'
/Users/neosarchizo/esp/aqk-device/main/./aqk_device_main.c:33: undefined reference to `ws2812_setColors'
collect2: error: ld returned 1 exit status
make: *** [/Users/neosarchizo/esp/aqk-device/build/aqk-device.elf] Error 1

What did I do wrong?

MartyMacGyver commented 6 years ago

A lot will change in the next release (big feature in progress). That said, if you clone the current version on master, you should be able to build the esp-idf demo. Use that as a guide.

Also, this may be a C thing... my demos are in C++ (as is the library) and I've not looked into how they bind with a main program in C. It may be that this is the problem.

arduinosh.hpp just has some helpful glue code for the (C++) demo... you can instead copy that code in directly. However, again this C vs C++ thing may be happening here.

If after examining the latest version and verifying your structure (and component makefiles!) matches, then perhaps attaching a tarball with JUST the source and makefiles for your demo would help. make clean first and you can skip the sdkconfig file(s) too.

I cannot guarantee this will ever work with regular C, but its worth figuring out where this problem is.

neosarchizo commented 6 years ago

For this, I create pull-request. I added demo2 for projects that work without arduinoish.hpp.

MartyMacGyver commented 6 years ago

Thank you! I will look at it tonight and integrate it (I may make changes now or later but I'll keep it as a C demo).

MartyMacGyver commented 6 years ago

Not closed yet... as I will still be maintaining one unified library, I will need to find a way to make main.c work with the library as-is. I do intend to have a C demo that works against the existing library, but I'm not maintaining a C-only library too (and given the amount of work already on the feature branch I'm doing, there's a lot I'll be looking at).

neosarchizo commented 6 years ago

Oh sorry. If you need any help about maintaining it, just let me know.

MartyMacGyver commented 6 years ago

You're the second person to ask about it, so it's definitely on my todo list.