Recent

Author Topic: Is it possible to include/use compiled parts of eg. Arduino in FPC ?  (Read 786 times)

af0815

  • Sr. Member
  • ****
  • Posts: 360
The Arduino Projects have a lot of libraries for the diffents HATs or Sensors, is it possible to use compiled code from this libs ?

PS: This is no question about the license, only if it possible.

regards
Andreas

lucamar

  • Hero Member
  • *****
  • Posts: 2084
Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
« Reply #1 on: June 23, 2019, 11:15:36 pm »
The Arduino Projects have a lot of libraries for the diffents HATs or Sensors, is it possible to use compiled code from this libs ?

PS: This is no question about the license, only if it possible.

Are they dynamic libraries with C bindings? If so, it should be possible to translate the bindings to Pascal and use them. For static libraries or object files ... I don't know, sorry.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

PascalDragon

  • Hero Member
  • *****
  • Posts: 674
  • Compiler Developer
Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
« Reply #2 on: June 24, 2019, 09:06:47 am »
The Arduino Projects have a lot of libraries for the diffents HATs or Sensors, is it possible to use compiled code from this libs ?
I did not test it, but you'd need to write units for the compiled libraries and then use {$L code.o} for each file you need (most files will probably require other files). Or you could try to move all .o files into a static library and link against that...

ccrause

  • Full Member
  • ***
  • Posts: 185
Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
« Reply #3 on: June 24, 2019, 03:53:27 pm »
I think it will be challenging since many (most?) of the libraries are written in C++.  One could write a C layer on top to flatten the code, but for that much effort I would rather stay with Arduino. Or better yet, rewrite library in Pascal.

Thaddy

  • Hero Member
  • *****
  • Posts: 9189
Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
« Reply #4 on: June 24, 2019, 04:15:31 pm »
I think it will be challenging since many (most?) of the libraries are written in C++.  One could write a C layer on top to flatten the code, but for that much effort I would rather stay with Arduino. Or better yet, rewrite library in Pascal.
@ccrause: you are an expert, but:
Arduino is almost all plain C, not C++. It is written C++ style., but it is usually plain C.
C++ is way too heavy to use at all. Free pascal works great on Arduino.
« Last Edit: June 24, 2019, 04:18:04 pm by Thaddy »
also related to equus asinus.

af0815

  • Sr. Member
  • ****
  • Posts: 360
Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
« Reply #5 on: June 24, 2019, 05:12:08 pm »
Thaddy, have you a sample for me ? Please.
regards
Andreas

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 635
Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
« Reply #6 on: June 24, 2019, 05:38:21 pm »
How does free pascal work on Arduino?

Thaddy

  • Hero Member
  • *****
  • Posts: 9189
Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
« Reply #7 on: June 24, 2019, 06:15:17 pm »
How does free pascal work on Arduino?
Build a cross compiler for it.... Both AVR and ARM bare bone are supported as micro controllers.... Which one do you have?

Don't expect Lazarus component style programming to work, though.... But FPC does perfectly OK.
Just like the C cross-compilers
« Last Edit: June 24, 2019, 06:23:26 pm by Thaddy »
also related to equus asinus.

Thaddy

  • Hero Member
  • *****
  • Posts: 9189
Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
« Reply #8 on: June 24, 2019, 06:45:08 pm »
Thaddy, have you a sample for me ? Please.
There are (is) simple stuff in the wiki... Start here, but there is more: https://wiki.freepascal.org/Arduino
 And here https://wiki.freepascal.org/AVR_Programming
And here for the compiler: https://forum.lazarus.freepascal.org/index.php/topic,30960.msg200524.html#msg200524

The actual compiler compares very well on this platform!
« Last Edit: June 24, 2019, 06:49:27 pm by Thaddy »
also related to equus asinus.

ccrause

  • Full Member
  • ***
  • Posts: 185
Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
« Reply #9 on: June 24, 2019, 07:04:30 pm »
Arduino is almost all plain C, not C++. It is written C++ style., but it is usually plain C.
C++ is way too heavy to use at all.

The base wiring library is plain C, but most other libraries seem like C++ (except if class X : public Y is a valid C construct).  I'm no expert in C/C++, let alone the differences between the two, but I did spot use of inheritance and using-declaration (I had to search for that definition):
Code: C  [Select]
  1. class TwoWire : public Stream
  2. {
  3. ...
  4.     using Print::write;
  5. };

I only want to point out that the question to get access to available functionality in Arduino is reasonable, I just think it will be a lot more difficult that linking to a plain C library.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 635
Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
« Reply #10 on: June 24, 2019, 07:18:22 pm »
How does free pascal work on Arduino?
Build a cross compiler for it.... Both AVR and ARM bare bone are supported as micro controllers.... Which one do you have?

Don't expect Lazarus component style programming to work, though.... But FPC does perfectly OK.
Just like the C cross-compilers

I have both, but I am trying to use ARM (STM32). But they work (almost) out of the box in the Arduino IDE, and while I do seem to be able to build an image for them with FPC, it is far from working.

jmpessoa

  • Hero Member
  • *****
  • Posts: 1470
Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
« Reply #11 on: June 24, 2019, 07:36:36 pm »
Quote
How does free pascal work on Arduino?

A wizard to create Arduino loadable module (.hex) using Lazarus/Free Pascal:

https://github.com/jmpessoa/lazarduinomodulewizard
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Thaddy

  • Hero Member
  • *****
  • Posts: 9189
Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
« Reply #12 on: June 24, 2019, 07:42:09 pm »
Arduino is almost all plain C, not C++. It is written C++ style., but it is usually plain C.
C++ is way too heavy to use at all.

The base wiring library is plain C, but most other libraries seem like C++ (except if class X : public Y is a valid C construct).  I'm no expert in C/C++, let alone the differences between the two, but I did spot use of inheritance and using-declaration (I had to search for that definition):
Code: C  [Select]
  1. class TwoWire : public Stream
  2. {
  3. ...
  4.     using Print::write;
  5. };

I only want to point out that the question to get access to available functionality in Arduino is reasonable, I just think it will be a lot more difficult that linking to a plain C library.
That's actually more like a pascal record and is not a true "class" in that sense. You can only use it in record style.... (bitpacked, btw)
also related to equus asinus.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 635
Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
« Reply #13 on: June 24, 2019, 07:46:21 pm »
A wizard to create Arduino loadable module (.hex) using Lazarus/Free Pascal:

https://github.com/jmpessoa/lazarduinomodulewizard

Yes, I got that part working. But the image generated by the Arduino IDE configures the controller, so that it actually works (ie. the clock sources and devices). Free Pascal only initializes it (ie. the vector table).

Dimitrios Chr. Ioannidis

  • Jr. Member
  • **
  • Posts: 83
    • Nephelae
Re: Is it possible to include/use compiled parts of eg. Arduino in FPC ?
« Reply #14 on: June 24, 2019, 11:12:14 pm »
Hi,

I have both, but I am trying to use ARM (STM32). But they work (almost) out of the box in the Arduino IDE, and while I do seem to be able to build an image for them with FPC, it is far from working.

you should try the Microcontroller Board Framework.

I test it with a samd21g18a and worked great. AFAIK, it has support for at least the NUCLEO-F303K8 an STM32 ARM based board so it's a good bet that it will work for you also.

regards,
Dimitrios Chr. Ioannidis
http://www.nephelae.eu