Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arduino IDE compability #11

Closed
8bitbunny opened this issue May 27, 2017 · 59 comments
Closed

Arduino IDE compability #11

8bitbunny opened this issue May 27, 2017 · 59 comments

Comments

@8bitbunny
Copy link

i am desperate to get this to the Arduino IDE, but i get a huge list of errors when compiling and i can't figure it out due to lack of knowing lvgl well enough... perhaps port it to arduino as well?

@kisvegabor
Copy link
Member

Have you added the project's root path to the include paths?

Can you copy here a few from the error messages?

@8bitbunny
Copy link
Author

8bitbunny commented May 27, 2017

well, arduino is set up differently, and i don't know how to do that on arduino ide.
so i copied everything to the sketch folder, with adding the needed includes in the sketch file.

then i came across alot of "file not found" (due to root include paths), fixed those manually, but then i got "undefined reference to" errors, so i had to include every .c file in my sketch too, and now i get even more errors saying this:


C:\Users\Admin\AppData\Local\Temp\arduino_build_78852\sketch\lvgl/lv_objx/lv_bar.c: In function 'lv_obj_t* lv_bar_create(lv_obj_t*, lv_obj_t*)':

C:\Users\Admin\AppData\Local\Temp\arduino_build_78852\sketch\lvgl/lv_objx/lv_bar.c:62:42: error: invalid conversion from 'void*' to 'lv_bar_ext_t*' [-fpermissive]

lv_bar_ext_t * ext = lv_obj_alloc_ext(new_bar, sizeof(lv_bar_ext_t));

why not simply make everything easy to integrate in arduino too? :P

@8bitbunny
Copy link
Author

note that this is with the application framework enabled

@kisvegabor
Copy link
Member

Hm. Please attache the whole compile log as a txt file.

@8bitbunny
Copy link
Author

okay, i set compiler warnings to "all" so beware of a HUGE list of errors, here's the list: https://pastebin.com/dJZmD2rp

@kisvegabor
Copy link
Member

It seems like compiiler threat the source files as cpp files instead of c. Have you changes the file extensions to .cpp from .c?

@8bitbunny
Copy link
Author

the arduino ide does that by default i think, and i cant find a way on how to disable that, and i leaved the file extentions at their default ones ( .h, .c )

@kisvegabor
Copy link
Member

I googled on it and found that it a limitation of the Arduino IDE. I have never used Arduino so far but others say there are problems when you begin to use things outside of Arduino. Therefore they recommend to work with an other IDE.

https://stackoverflow.com/questions/7803416/can-the-arduino-ide-be-used-to-develop-plain-old-c-programs

Here is a description about a C compatible IDE:
https://spin.atomicobject.com/2011/10/15/taking-the-training-wheels-off-the-arduino/

@8bitbunny
Copy link
Author

i see, so that basically means i need to port the entire device support package to another IDE... (the teensy 3.x support package in my case, which will be a pain)

and i was so hopeful that lvgl could work relatively easy on arduino.. :'(

@8bitbunny
Copy link
Author

just a question, will it ever be ported to arduino? or not?

@kisvegabor
Copy link
Member

Yes, I'm planning to port it to Arduino (and make the required updates) but I will have time for it only a few month later... :(

Teensy 3 doesn't support other IDE/compiler then Arduino?

@8bitbunny
Copy link
Author

awesome that it's going to be ported! no worries on time, do everything at your tempo, will donate some money for the awesome support :)

and for the teensy 3 not as far as i know.. ^^;

@ajaybhargav
Copy link
Contributor

You can create a wrapper class around lvgl to make it arduino compatible, converting whole project to c++ will be a big job.

@8bitbunny
Copy link
Author

never did that kind of coding before, so i wouldn't know how to do that tbh ^^;

@kisvegabor
Copy link
Member

I don't know Arduino, but I suppose that regardless to the wrappers the Arduino compiler has to compile the code. The wrappers helps you only when you use the functions, don't they?

@ajaybhargav
Copy link
Contributor

I have been working on Arduino recently to add support for a new platform that I am making. And lot of code that I write is in C. Arduino core is actually mix bag of C and C++ sources so I am not sure why compiler is throwing errors. It may be the way you are including the files in your project/sketch.

@kisvegabor
Copy link
Member

Good news! Thanks for that!

@kisvegabor kisvegabor changed the title ide compability Arduino IDE compability May 28, 2017
@kisvegabor
Copy link
Member

I've downloaded the Arduino IDE and tried to setup an example dummy library. The first thing I faced that I had to modify the .h files:
at the begginig
#ifdef __cplusplus
extern "C" {
#endif

at the end
#ifdef __cplusplus
} // extern "C"
#endif

If you have time for that can you try it?

Also to not waste time I recommend you to try the PC simulator. It is a very good to know the LittevGL and also your code can be copied to an embedded environment later. Here is a guide about the PC simulator: http://www.gl.littlev.hu/pc-simulator

@8bitbunny
Copy link
Author

you mean at every .h file? that's gonna take some time.

and i will try the pc emulator :)

@8bitbunny
Copy link
Author

also, regarding the pc simulator, why not make a single visual studio project? if needed i can give you a project that's exactly doing that :)

@kisvegabor
Copy link
Member

kisvegabor commented May 28, 2017

Yes, I mean all .h files... :(

Visual studio project: I've chosen Eclipse CDT because it is cross platform. Please create an issue in proj_pc repository to continue the discussion about Visual Studio there.

@8bitbunny
Copy link
Author

Okay, will change all files and try again upcoming week and tell you the result

@8bitbunny
Copy link
Author

8bitbunny commented Jun 1, 2017

i midified all the .h files, and now getting "undefined reference to lv_init()" and the same errors with other functions.

looks like i need to include the dedicated .c files as well in each .h file? :O

@kisvegabor
Copy link
Member

Thank you for the effort to modify the files.

Please, send me the lvgl, misc and hal folders and I will check/try them.

@8bitbunny
Copy link
Author

attached is the arduino folder including ili9341 and touch libraries for the adafruit 2.8" tft ( https://www.adafruit.com/product/1651 ) with a teensy 3.1 (i used teensyduino 1.36 & arduino 1.8.1)

the whole zip needs to be extracted in my documents/Arduino
Arduino.zip

@kisvegabor
Copy link
Member

I've checked the files, tried to compile and saw multiple type of issues. On next week I'll try to solve them!

@kisvegabor
Copy link
Member

kisvegabor commented Jun 8, 2017

Firstly I have tried to port the misc library and I've succeeded! It was required to solve several issues because of the limitations in the Arduino IDE but I was able to compile it! Please try it and if it is working for
you too I will make the LittlevGL as well.

Arduino_misc.zip

@8bitbunny
Copy link
Author

8bitbunny commented Jun 8, 2017

it compiles, but it doesn't go past the misc_init(); function on a teensy 3.2 (fastest, with lto, 96mhz), aka a system halt is thrown.

this is the sketch:

#include <hal.h>
#include <misc.h>

extern "C" char* sbrk(int incr);

int FreeRam() {
  char top;
  return &top - reinterpret_cast<char*>(sbrk(0));
}


void setup() {
  delay(1000);
  Serial.println("Start");
  // put your setup code here, to run once:
  delay(100);
  Serial.print("Misc init..");
  misc_init(); //doesn't get past here
  Serial.println(" Done!");
  Serial.print("Free RAM:");
  Serial.println(FreeRam());
}

void loop() {
  // put your main code here, to run repeatedly:
}

@kisvegabor
Copy link
Member

In misc_conf.h disable the IDLE module. USE_IDLE 0

@kisvegabor
Copy link
Member

Hi,

It is good to here that you have tried that IDE.

Were you able to solve the issue meanwhile?

@8bitbunny
Copy link
Author

Sadly not :(

@kisvegabor kisvegabor reopened this Nov 26, 2017
@kisvegabor
Copy link
Member

Hi Ramon,

Good news for Arduino! In the upcoming v5.0 release I modified the architecture the graphics library and now it is compatible with the default Arduino IDE. I was able to easily compile it with Teensy 3.6.

I cannot test it because I don't have Teensy hardware, but I hope you can do the testing! :) You need to write a disp_fill and disp_map function (see below)

Here is the library:
lvgl_arduino_lib.zip

An this is my sketch:

#include <lvgl.h>

void hal_init(void)
{
    /*Initialize the display*/
    lv_disp_drv_t disp_drv;
    disp_drv.fill = NULL;  /*function to fill an area:          void fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color) */
    disp_drv.map = NULL;   /*function copy pixels to an area:   void map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t *color_p) */
    disp_drv.copy = NULL;  /*ignored*/
    lv_disp_register(&disp_drv);

    /*Initialize the graphics library's tick*/
    /*In a Timer call lv_tich_handler() in every milliseconds*/
}

void setup() {
  lv_init();

  hal_init();

  lv_obj_t *label = lv_label_create(lv_scr_act(), NULL);
  lv_label_set_text(label, "Hello Arduino!");
  lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);

}

void loop() {
  // put your main code here, to run repeatedly:

}

@8bitbunny
Copy link
Author

awesome, altho i see a problem, the arduino IDE has a macro called map, which is used in LV_HAL_DISP.H

@8bitbunny
Copy link
Author

hmm... i get errors when assigning my own function to the null pointers:

error: expected primary-expression before 'x1'
     disp_drv.map = disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t *color_p);

@kisvegabor
Copy link
Member

I updated the library to not use 'map' name.
lvgl_ardion_lib2.zip

    /*Initialize the display*/
    lv_disp_drv_t disp_drv;
    disp_drv.fill_fp = NULL;  /*function to fill an area:          void fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color) */
    disp_drv.map_fp = NULL;   /*function copy pixels to an area:   void map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t *color_p) */
    disp_drv.blend_fp = NULL;  /*ignored*/
    lv_disp_register(&disp_drv);

You get the error because you have to initialize it like this:disp_drv.map_fp = disp_map So write onyl the function name.

@8bitbunny
Copy link
Author

8bitbunny commented Nov 27, 2017

ok, didn't know that

now i get this error(?)
error: 'lv_disp_drv_t {aka struct _disp_drv_t}' has no member named 'fill'

nevermind me, was being dumb

@kisvegabor
Copy link
Member

Look the previous code example! To be consistent with map_fp I renamed fill to fill_fp

@8bitbunny
Copy link
Author

yeah, i figured it out, i am pretty sleepy right now

got it to compile, going to test soon

@8bitbunny
Copy link
Author

8bitbunny commented Nov 27, 2017

it compiled, but doesn't work with my ili9341, while it does work when i call the tft driver library (the non lvgl) functions directly, so it must be something inside of lvgl that refuses to run.

btw, i am running a tick timer for the lvgl as documented

edit: if usefull, my main arduino file


#include <lvgl.h>
#include <ILI9341_t3.h>
#include <SPI.h>

ILI9341_t3 tft = ILI9341_t3(9,10);

static IntervalTimer tick;

void fill_area(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color) {
  uint16_t c = tft.color565(color.red, color.green, color.blue);
  tft.fillRect(x1,y1,x2,y2,c);
}
void disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t *color_p) {
  uint16_t c;
  for (int y = y1; y < y2; y++) {
    for (int x = x1; x < x2; x++) {
      c = tft.color565(color_p->red, color_p->green, color_p->blue);
      tft.fillRect(x,y,x+1,y+1, c);
    }
  }
}

void hal_init(void) {
  /*Initialize the display*/
  lv_disp_drv_t disp_drv;
  disp_drv.fill_fp = fill_area;  /*function to fill an area:          void fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color) */
  disp_drv.map_fp = disp_map;   /*function copy pixels to an area:   void map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t *color_p) */
  lv_disp_register(&disp_drv);

  /*Initialize the graphics library's tick*/
  tft.begin();
  tft.setRotation(0);
  tft.fillRect(0,0,240,320,0x0000);
  delay(300);
  /*In a Timer call lv_tich_handler() in every milliseconds*/
}

void setup() {
  lv_init();
  delay(50);
  hal_init();
  tft.fillRect(0,0,240,320,0xffff);
  tick.begin(lv_tick_handler,1000);
  lv_obj_t *label = lv_label_create(lv_scr_act(), NULL);
  lv_label_set_text(label, "Hello!");
  lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(1);
}

@8bitbunny
Copy link
Author

Just thinking out loud now: the teensy support package runs as multi thread within each yield call (which happens alot!)
This might be a problem with the lvgl scheduler to prevent it from executing?
Also, the MCU doesn't freeze up, I can draw in the loop what and whenever I want.

Also note that the lvgl doesn't just give no output on the screen, but also no change on the SPI bus to which the screen is connected to.

Yes I have configured the lvgl config file for correct screen resolution, also reduced buffer to 10 lines to fit on my teensy 3.2

@kisvegabor
Copy link
Member

Oh sorry, I forget to add lv_task_handler() to the loop... You can also add a few millisecond delay after it and/or call your applicaton's functions.

@8bitbunny
Copy link
Author

it works, lvgl clears the screen to black, but.... no text is displayed :P

@kisvegabor
Copy link
Member

Please show me your disp_map function.

@8bitbunny
Copy link
Author


void disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t *color_p) {
  uint16_t c;
  tft.setAddrWindow(x1,y1,x2,y2);
  for (int y = y1; y <= y2; y++) {
    for (int x = x1; x <= x2; x++) {
      c = tft.color565(color_p->red, color_p->green, color_p->blue);
      tft.drawPixel(x,y,c);
    }
  }
}

@kisvegabor
Copy link
Member

kisvegabor commented Nov 29, 2017

It seems you forget to increment color_p :)

c = tft.color565(color_p->red, color_p->green, color_p->blue);
tft.drawPixel(x,y,c);
color_p++;

@8bitbunny
Copy link
Author

this proves how newb i am with lvgl xD
thanks! it works as should, not i can dive into optimizing my disp_map function, as it is kinda slow.

issue can be closed :)

@kisvegabor
Copy link
Member

Awesome ^^

Please keep in mind the dev-5.0 is under development and some changes may still happen until it is released.

@Pablo2048
Copy link

@ramonschepers Instead of .drawPixel try to use .pushColor - this may speed things up... ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants