embeddednim / picostdlib Goto Github PK
View Code? Open in Web Editor NEWNim wrapper for the raspberry pi stdlib
License: MIT License
Nim wrapper for the raspberry pi stdlib
License: MIT License
Similar to how nimble looks.
hint:
message to read back the interpreted arguments/option/flagHi Jason,
I wanted to do some multicore tests (it's a beautiful thing about rp2024 !!). But as usual they are a bit complex for me to wrapped.
If you have time you could take a look?
The functions are:
• void multicore_reset_core1 (void)
• void multicore_launch_core1 (void (* entry) (void))
• void multicore_launch_core1_with_stack (void (* entry) (void), uint32_t * stack_bottom, size_t stack_size_bytes)
• void multicore_launch_core1_raw (void (* entry) (void), uint32_t * sp, uint32_t vector_table)
Pagi 193 of the manual.
thanks and bye Martin A.
I'm currently working in implementing this. The PIO API has a large number of functions, but as a first "mvp" PR, I'd like to bind at least enough to get the "blink" and "ws2812" examples working (and implemented in Nim).
The nimble output:
[mfg@Methadon ~]$ nimble install https://github.com/EmbeddedNim/picostdlib
Downloading https://github.com/EmbeddedNim/picostdlib using git
Warning: Package 'picostdlib' has an incorrect structure. It should contain a single directory hierarchy for source files, named 'picostdlib', but file 'blink.nim' is in a directory named 'template/src' instead. This will be an error in the future.
Hint: If 'template/src' contains source files for building 'picostdlib', rename it to 'picostdlib'. Otherwise, prevent its installation by adding `skipDirs = @["template/src"]` to the .nimble file.
Verifying dependencies for [email protected]
Prompt: No local packages.json found, download it from internet? [y/N]
Answer: y
Downloading Official package list
Success Package list downloaded.
Installing https://github.com/casey-SK/commandant@>= 0.15.1
Downloading https://github.com/casey-SK/commandant using git
Verifying dependencies for [email protected]
Installing [email protected]
Success: commandant installed successfully.
Installing https://github.com/beef331/micros@any version
Downloading https://github.com/beef331/micros using git
Verifying dependencies for [email protected]
Installing [email protected]
Success: micros installed successfully.
Installing [email protected]
Building picostdlib/piconim using c backend
/home/mfg/.nimble/pkgs/micros-0.1.1/micros/definitions/routines.nim(161, 12) Warning: Use on a typed Procedure may result in accessing the wrong Stmtlist [User]
Success: picostdlib installed successfully.
Prompt: Missing directory /home/mfg/.nimble/pkgs/picostdlib-0.3.1/src/template. Continue? [y/N]
Answer: N
It seems the structure makes it impossible for nimble to correctly install this package. The "missing" directory is obviously not missing.
[mfg@Methadon ~]$ ls .nimble/pkgs/picostdlib-0.3.1/
nimblemeta.json piconim piconim.nim picostdlib picostdlib.nimble template
[mfg@Methadon ~]$ ls .nimble/pkgs/picostdlib-0.3.1/template/
config.nims csource src template.nimble
Just wanted to mention that I'm working on this, so effort doesn't get duplicated too much.
WIP is here: https://github.com/auxym/picostdlib/blob/tinyusb/src/picostdlib/tusb.nim
I don't currently plan to work on other device classes (MSC, midi, audio, etc) or USB host.
Hi Jason,
Today (back from holidays) I updated Piconim 0.3.0 -> 0.3.1.
If I create a new project everything works well and is completed, while those created first by an error (which I put below). I also tried the "Piconim Setup--Sdk:/Home/Andrea/ProgPiconim/Pico-Sdk" command, but it did not give results.
what should I do ? Recreate the projects or is there another solution?
the error in the old progects:
make[2]: Leaving directory '/home/andrea/ProgPicoNim/scannerI2c/csource/build'
make[2]: Entering directory '/home/andrea/ProgPicoNim/scannerI2c/csource/build'
[ 14%] Building C object CMakeFiles/scannerI2c.dir/nimcache/@m..@s..@s[email protected]@[email protected]@[email protected]
In file included from /home/andrea/ProgPicoNim/scannerI2c/csource/build/nimcache/@m..@s..@s[email protected]@[email protected]@[email protected]:5:
/home/andrea/ProgPicoNim/scannerI2c/csource/nimbase.h:276:35: error: static assertion failed: ""
276 | #define NIM_STATIC_ASSERT(x, msg) _Static_assert((x), msg)
| ^~~~~~~~~~~~~~
/home/andrea/ProgPicoNim/scannerI2c/csource/nimbase.h:550:1: note: in expansion of macro 'NIM_STATIC_ASSERT'
550 | NIM_STATIC_ASSERT(sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8, "");
| ^~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/scannerI2c.dir/build.make:76: CMakeFiles/scannerI2c.dir/nimcache/@m..@s..@s[email protected]@[email protected]@[email protected]] Error 1
make[2]: Leaving directory '/home/andrea/ProgPicoNim/scannerI2c/csource/build'
make[1]: *** [CMakeFiles/Makefile2:1329: CMakeFiles/scannerI2c.dir/all] Error 2
make[1]: Leaving directory '/home/andrea/ProgPicoNim/scannerI2c/csource/build'
make: *** [Makefile:91: all] Error 2
make: Leaving directory '/home/andrea/ProgPicoNim/scannerI2c/csource/build'
Nothing is broken, just an annoyance. Don't remember seeing this before, but currently my pico projects (even a fresh blinky created with piconim init) results in whole bunch of complaining from gcc (see below).
Not sure what changed. I tried older Nim versions and still getting the same. Maybe a new gcc version? I am running arm-none-eabi-gcc (Arch Repository) 12.2.0
.
"Regular" nim compiles don't do this, I guess the pico CMake/make stuff might be passing different -W
flags to gcc?
In file included from /home/francis/temp/proj/csource/build/nimcache/stdlib_system.nim.c:4:
/home/francis/temp/proj/csource/build/nimcache/stdlib_system.nim.c: In function 'align_system_1616':
/home/francis/temp/proj/csource/build/nimcache/stdlib_system.nim.c:281:52: warning: passing argument 3 of '__builtin_ssub_overflow' from incompatible pointer type [-Wincompatible-pointer-types]
281 | if (nimSubInt(alignment, ((NI) 1), &TM__Q5wkpxktOdTGvlSRo9bzt9aw_3)) { raiseOverflow(); goto BeforeRet_;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| NI * {aka long int *}
/home/francis/.choosenim/toolchains/nim-1.6.0/lib/nimbase.h:589:64: note: in definition of macro 'nimSubInt'
589 | #define nimSubInt(a, b, res) __builtin_ssub_overflow(a, b, res)
| ^~~
/home/francis/temp/proj/csource/build/nimcache/stdlib_system.nim.c:281:52: note: expected 'int *' but argument is of type 'NI *' {aka 'long int *'}
281 | if (nimSubInt(alignment, ((NI) 1), &TM__Q5wkpxktOdTGvlSRo9bzt9aw_3)) { raiseOverflow(); goto BeforeRet_;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/francis/.choosenim/toolchains/nim-1.6.0/lib/nimbase.h:589:64: note: in definition of macro 'nimSubInt'
589 | #define nimSubInt(a, b, res) __builtin_ssub_overflow(a, b, res)
| ^~~
/home/francis/temp/proj/csource/build/nimcache/stdlib_system.nim.c:283:78: warning: passing argument 3 of '__builtin_sadd_overflow' from incompatible pointer type [-Wincompatible-pointer-types]
283 | if (nimAddInt(address, (NI)(TM__Q5wkpxktOdTGvlSRo9bzt9aw_3), &TM__Q5wkpxktOdTGvlSRo9bzt9aw_4)) { raiseOverflow(); goto BeforeRet_;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| NI * {aka long int *}
/home/francis/.choosenim/toolchains/nim-1.6.0/lib/nimbase.h:588:64: note: in definition of macro 'nimAddInt'
588 | #define nimAddInt(a, b, res) __builtin_sadd_overflow(a, b, res)
| ^~~
/home/francis/temp/proj/csource/build/nimcache/stdlib_system.nim.c:283:78: note: expected 'int *' but argument is of type 'NI *' {aka 'long int *'}
283 | if (nimAddInt(address, (NI)(TM__Q5wkpxktOdTGvlSRo9bzt9aw_3), &TM__Q5wkpxktOdTGvlSRo9bzt9aw_4)) { raiseOverflow(); goto BeforeRet_;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/francis/.choosenim/toolchains/nim-1.6.0/lib/nimbase.h:588:64: note: in definition of macro 'nimAddInt'
588 | #define nimAddInt(a, b, res) __builtin_sadd_overflow(a, b, res)
| ^~~
/home/francis/temp/proj/csource/build/nimcache/stdlib_system.nim.c:285:52: warning: passing argument 3 of '__builtin_ssub_overflow' from incompatible pointer type [-Wincompatible-pointer-types]
285 | if (nimSubInt(alignment, ((NI) 1), &TM__Q5wkpxktOdTGvlSRo9bzt9aw_5)) { raiseOverflow(); goto BeforeRet_;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| NI * {aka long int *}
/home/francis/.choosenim/toolchains/nim-1.6.0/lib/nimbase.h:589:64: note: in definition of macro 'nimSubInt'
589 | #define nimSubInt(a, b, res) __builtin_ssub_overflow(a, b, res)
| ^~~
/home/francis/temp/proj/csource/build/nimcache/stdlib_system.nim.c:285:52: note: expected 'int *' but argument is of type 'NI *' {aka 'long int *'}
285 | if (nimSubInt(alignment, ((NI) 1), &TM__Q5wkpxktOdTGvlSRo9bzt9aw_5)) { raiseOverflow(); goto BeforeRet_;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/francis/.choosenim/toolchains/nim-1.6.0/lib/nimbase.h:589:64: note: in definition of macro 'nimSubInt'
589 | #define nimSubInt(a, b, res) __builtin_ssub_overflow(a, b, res)
| ^~~
/home/francis/temp/proj/csource/build/nimcache/stdlib_system.nim.c: In function 'nimDecRefIsLast':
/home/francis/temp/proj/csource/build/nimcache/stdlib_system.nim.c:323:61: warning: passing argument 3 of '__builtin_ssub_overflow' from incompatible pointer type [-Wincompatible-pointer-types]
323 | if (nimSubInt((*cell).rc, ((NI) 8), &TM__Q5wkpxktOdTGvlSRo9bzt9aw_10)) { raiseOverflow(); goto BeforeRet_;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| NI * {aka long int *}
/home/francis/.choosenim/toolchains/nim-1.6.0/lib/nimbase.h:589:64: note: in definition of macro 'nimSubInt'
589 | #define nimSubInt(a, b, res) __builtin_ssub_overflow(a, b, res)
| ^~~
/home/francis/temp/proj/csource/build/nimcache/stdlib_system.nim.c:323:61: note: expected 'int *' but argument is of type 'NI *' {aka 'long int *'}
323 | if (nimSubInt((*cell).rc, ((NI) 8), &TM__Q5wkpxktOdTGvlSRo9bzt9aw_10)) { raiseOverflow(); goto BeforeRet_;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(hundreds more lines of similar warnings)
thanks Jeson for the very useful getCharWithTimeout () implementation !!
as a test I wrote a small test program, if you want to include it among the examples!
serialUsb.nim.zip
Hi Jason I added two procedures (timeUs32() & 64) in the existing "time.nim" file creating a type structure:
{.push Header: "Something1".}
aaa
bbb
{.pop.}
{.push Header: "Something2".}
ccc
ddd
{.pop.}
But aren't they sure it's the correct thing to do, or if it is better to create a new Nim file?
P.S. He says we can increase version from 0.2.6 -> 0.2.7?
Hello! I tried to enter the sample code usb, but git forbids me: Invalid username or password
andrea@tec-martin:/Documenti/Git/picostdlib> git push --set-upstream origin Martinix75/Documenti/Git/picostdlib>
remote: Invalid username or password.
fatal: Autenticazione non riuscita per 'https://github.com/beef331/picostdlib.git/'
andrea@tec-martin:
I'm learning these days to use git, so chances are I'm still doing something wrong! :(
Current situation:
piconim init
does not contain a .gitignore filecsource/build
directory cannot be added to .gitignore, because it contains the Makefile, which is generated by cmake during piconim init
. Thus, piconim build
would fail on a fresh/clean repository.Proposal:
setup
(or configure
, or init
and rename the current init
to create
) command that runs cmake
with the SDK path provided as an optional argument. This is automatically run during init
csource/build
directory as well as csource/*.c
.piconim init
, run piconim setup
(optionally providing as SDK path), and build it with piconim build
.If the maintainers agree with the idea, I could put in a PR.
Hi guys,
thanks for this lovely project; I really enjoyed the clean and useful examples! Would you mind showing how to use Nim with the Pico W, i.e. leveragint its wireless capabilities? My internet searches for this were fruitless so far and I think it would make a good addition to the repo.
Thanks a lot in advance!
Cheers,
Frank
hi Jason here I am again.
after having fun with usb, i would like to try to connect my I2c display.
So I wanted to ask if it was possible to implement the three basic functions for I2c:
i2c_init ()
i2c_write_blocking ()
i2c_read_blocking ()
I tried, but it's a little too much for me !!
thanks from Andrea
https://www.youtube.com/watch?v=092xFEmAS98
here is an example of what I would like to do (about)!!!!!
So that users have a single "document" to reference all this library has to offer.
Whenever a picostdlib
module such as adc
or pwm
is imported, it should be noticed and appended to the target_link_libraries()
in CMakeLists during the build operation.
Library users might want to override some of these flags. Eg. running a debug or danger build instead of release, or ORC instead of ARC. I therefore propose to add a nim.cfg
file to the template that specifies these flags, and remove the hardcoded values in piconim. The flags that are "absolutely necessary" for a working build should probably stay where they are (--cpu
, --nimcache
, useMalloc
).
This once again breaks backwards compatibility with previously created projects (sorry). Users that want to upgrade would need to copy the new nim.cfg file in their project.
Thoughts?
I followed the setup instructions, and when running piconim build firmware.nim
(my project is called firmware
) I get the following error:
pico-nim : create raspberry pi pico projects using Nim
Hint: used config file '/home/francis/.choosenim/toolchains/nim-1.6.2/config/nim.cfg' [Conf]
Hint: used config file '/home/francis/.choosenim/toolchains/nim-1.6.2/config/config.nims' [Conf]
....................................................
/home/francis/source/tmpcb-macropad/firmware/src/firmware.nim(2, 8) Error: cannot open file: picostdlib
oserr.nim(95) raiseOSError
Error: unhandled exception: No such file or directory
Additional info: ("csource/@mfirmware.nim.c", "csource/firmware.c") [OSError]
Nim 1.6.2 on Linux (manjaro).
I can probably look into the issue myself in the next couple of days, just wanted to write it down somewhere.
Hi Jason, today I wanted to make a small PWM driver for an engine, but doing an initial test on the PWM (example of the library that worked ) today I got:
...
[ 15%] Building C object CMakeFiles/motorPwm.dir/nimcache/motorPwm.c.obj
In file included from /home/andrea/ProgPicoNim/motorPwm/csource/build/nimcache/motorPwm.c:5:
/home/andrea/ProgPicoNim/motorPwm/csource/nimbase.h:276:35: error: static assertion failed: "backend & Nim disagree on size for: PwmChannel{enum} [type declared in /home/andrea/.nimble/pkgs/picostdlib-0.2.11/picostdlib/pwm.nim(23, 3)]"
276 | #define NIM_STATIC_ASSERT(x, msg) _Static_assert((x), msg)
| ^~~~~~~~~~~~~~
/home/andrea/ProgPicoNim/motorPwm/csource/build/nimcache/motorPwm.c:25:1: note: in expansion of macro 'NIM_STATIC_ASSERT'
25 | NIM_STATIC_ASSERT(sizeof(enum pwm_chan) == 4, "backend & Nim disagree on size for: PwmChannel{enum} [type declared in /home/andrea/.nimble/pkgs/picostdlib-0.2.11/picostdlib/pwm.nim(23, 3)]");
| ^~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/motorPwm.dir/build.make:76: CMakeFiles/motorPwm.dir/nimcache/motorPwm.c.obj] Error 1
the program is (easy):
import picostdlib/[stdio, gpio, pwm]
let
pin0 = 0.Gpio
pin1 = 1.Gpio
pin0.setFunction(PWM)
pin1.setFunction(PWM)
let sliceNum = pin0.toSliceNum()
sliceNum.setWrap(3)
sliceNum.setChanLevel(A, 1u16)
sliceNum.setChanLevel(B, 3u16)
sliceNum.setEnabled(true)
cmakelists.txt mofied --> target_link_libraries(motorPwm pico_stdlib hardware_adc hardware_pwm hardware_gpio)
I don't understand where it may be the problem, can you make a test (maybe I am only tired toned this evening)? thank you
hi Jason,
I wanted to ask if using "piconim build .." it is possible to pass build flags. I wanted to try to use threadpool (or similar) to manage the display (it's a test) but how do you know you have to enable "--threads: on" is it possible to do this? and generally is it possible to enable these flags when I launch the command?
thanks from Martin A.
Implement tests for the following:
init
subcommand
good morning,
i just found a problem with nim 1.6.0 that didn't exist with nim 1.4.8!
import random (just import it to generate the error !! )
now create an error:
/home/andrea/ProgPicoNim/test160/src/os.nim(63, 10) Error: OS module not ported to your operating system!
oserr.nim(94) raiseOSError
Error: unhandled exception: No such file or directory
Additional info: "("csource/@mtest160.nim.c", "csource/test160.c", "No such file or directory")" [OSError]
i know you probably can't do anything about it, but i tell you (maybe it's a bug of nim 1.6.0 ?????)
bye!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.