-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Arduino support? #3637
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
Comments
Arduino is AVR-based, so really it's just a matter of waiting for LLVM's AVR support to stabilize, and adding support to the standard library. In theory, basic language support should already be in place, as long as you don't use the standard library. The real question then is how to handle stuff like the GPIO on an Arduino - e.g. |
@pixelherodev What do you mean with "as long as you don't use the standard
library.", I assume the standard zig library?
Op zo 10 nov. 2019 om 01:05 schreef pixelherodev <[email protected]>:
… Arduino is AVR-based, so really it's just a matter of waiting for LLVM's
AVR support to stabilize, and adding support to the standard library. In
theory, basic language support should already be in place, as long as you
don't use the standard library.
The real question then is how to handle stuff like the GPIO on an Arduino
- e.g. digitalRead in the Arduino AVR SDK. Similar functionality could
probably be added to the standard library under std.os for Arduino.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3637?email_source=notifications&email_token=AAFUKWXUW324SL3LX4JCFPDQS5F3TA5CNFSM4JLJLQE2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDUR74A#issuecomment-552148976>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFUKWRNL3R2YMXARBBWBL3QS5F3TANCNFSM4JLJLQEQ>
.
|
Just to be clear, you can in fact use most of the standard library. But the cross platform OS abstractions lack Arduino support, so it would be a compile error currently to, for example, open a file. |
Interesting. I might look into this more later (like 6 months from now). |
auduino's digitalRead is mmio so that's pretty trivial. But as I mentioned in #3645, avr-lld support is pretty bad. Thus, for simple code I have done
The need for llvm-objcopy should be removed after #2826 Because of #3645 (and probably other issues) the below example doesn't run with master (as of this writing) but does work with 0.5.0 const SFR=packed struct {
pin03:u4,
pin47:u4,
};
const PORTB = 0x38;
export fn main () void{
var portb=@intToPtr(*volatile SFR,PORTB);
portb.pin47=15;
while(true){}
} This example reads portb, changes upper nibble to 0xF and then writes data back to portb. I should probably write a github wiki page for avr |
i had a small time to work on it, const PORTBDATA = 0x25;
const PORTBDIR = 0x24;
export fn main () void{
var pb = @intToPtr(*volatile u8, PORTBDATA);
var pbd = @intToPtr(*volatile u8, PORTBDIR);
pbd.* = 0xff;
while(true){
pb.* = (1 << 5);
var i : u32 = 0;
while (i<5000) {
// nop
i +=1;
var j = pb.*;
}
pb.* = 0;
i = 0;
while (i<5000) {
// nop
i +=1;
var j = pb.*;
}
}
} and compile with
|
This could be: |
sure, |
So, should standard functionality be implemented in os.arduino? I can definitely do that at some point in the next month if that's desired. Edit: the other question then is how it should be implemented. os.arduino.digitalRead could be done, but a pin type might also work - e.g. const led_pin = os.arduino.digital_pin(3);
export fn main() void {
led_pin.mode(os.arduino.digital_pin.output);
led_pin.write(1);
// do other stuff
} |
Arduino is a microcontroller, and pin management permit to handle the hardware directly. Seems there are different strategies in adding arduino support :
none the less, i like the "pin" object description, i would probably not put it in os. module make sense ? i saw rust has worked also to create a dedicated project for embedded |
Creating a "pin" object, leads to create a wrapper, or modify all existing libraries we could reuse.This has to be put into balance. |
I don't think the std lib should have things like Have I overlooked something? |
I was not about the std having this functionality. For me it was more if it
was possible or not.
Op do 3 dec. 2020 om 16:32 schreef Ethan Frei <[email protected]>:
… I don't think the std lib should have things like digtalWrite(1, true)
because at the ATmega328 chip level, pin 1 means nothing. The Arduino
company has designated that itself. In the future, perhaps there could be
an "ArduinoUno" board-specific library which has these things.
Have I overlooked something?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3637 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFUKWV3O3RQTXIFA4OGRTDSS6VPJANCNFSM4JLJLQEQ>
.
|
As far as possible goes, is it possible to just have a cImport for these kinds of things instead of rewriting everything into std lib? |
@clankill3r https://github.com/FireFox317/avr-arduino-zig from @FireFox317 may help Some forks can be interesting also https://github.com/FireFox317/avr-arduino-zig/network |
@krishnaTORQUE for your future github adventures, there is a subscribe button in the right pannel 😃 |
Is this possible today? |
For info on getting Zig working on AVR and other microcontrollers, I'd recommend the microzig project and the Zig Embedded Group Discord |
Any update on the progress/feasibility of this? |
It is, in theory, possible to use Zig's C backend and use either |
That doesn't sound too bad; I have some free time, does anyone know how big the SDK is and/or where I can get my hands on it. I'm having trouble finding it. |
You can find it here: https://github.com/arduino/ArduinoCore-avr |
Has there been progress on this? |
FYI: ZigEmbeddedGroup/microzig#534 (comment) Milestone is set after Zig 1.0? Fair enough, but like mentioned in the issue above, it might be a nice way to learn programming (with Zig) if one could use educational resources for Arduino with Zig as well (with some adjustments). Could be a nice way to introduce the next generation programmers to Zig and to programming in general. |
Is it possible to have support for Arduino and other micro controllers?
And if so, what needs to happen?
The text was updated successfully, but these errors were encountered: