tinygo-org / tinygo

Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
https://tinygo.org
Other
15.19k stars 891 forks source link

Use C/C++ drivers on esp32 ? #3251

Open Vince-LD opened 1 year ago

Vince-LD commented 1 year ago

Hello,

I am currently learning Go in order to use tinygo on my esp32 instead of micropython. I saw that many features of the esp32 are not currently supported on the reference page. From my understanding, this is due to the Xtensa architecture.

Coming from a Python background, I have some silly questions:

I know pretty much nothing about what happens when compiling a program especially when you have a target such as a microcontroller so that explains my simplistic questions. It would be amazing if you had ressources and advices to share with me so I can understand all of this better because I don't really know where to start.

I love the esp32 and right now that's all I have and I really need ADC and I2C... I think I am going to order the Seeed Studio XIAO nRF52840 that has support for everything I need, but prototyping everything on the esp32 would be amazing!

aykevl commented 1 year ago

Using C would mean using the ESP-IDF, which is a massive software project that I would really like to avoid. It is possible (Rust has done this), but personally I'm much more interested in providing native support for all of this. In fact, it might be simpler to write the HAL from scratch than try to use ESP-IDF in TinyGo.

Does softi2c works on esp32 and what's the performance penalty compared to hardware i2c?

I haven't tested it.

I have one sensor that doesn't have tinygo drivers yet (MAX30102) and I was wondering if I could use the C++ library to run it.

The difficult part will be to provide the I2C interface in C. While writing a driver shouldn't be difficult, unfortunately TinyGo doesn't currently support I2C on the esp32. I tried to write it once, but couldn't get it to work.