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

Major rework and update of SDK bindings #62

Open
wants to merge 352 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
352 commits
Select commit Hold shift + click to select a range
84fee6e
fix native paths
daniel-j Mar 6, 2023
9164922
fix nim lib path, dont depend on jq
daniel-j Mar 6, 2023
20e1c94
Merge remote-tracking branch 'upstream/master'
daniel-j Mar 6, 2023
8765d22
clean up test output and imports
daniel-j Mar 6, 2023
04c965a
gitignore
daniel-j Mar 6, 2023
379be26
bump dependencies
daniel-j Mar 6, 2023
44cc195
invalid version for commandant
daniel-j Mar 6, 2023
7497a79
commandant is in nimble directory
daniel-j Mar 6, 2023
a062cc9
major version bump
daniel-j Mar 6, 2023
a0d1b2e
clang now thinks in correct target, use gcc arm-none-eabi include path
daniel-j Mar 7, 2023
9fdb50e
strip command output
daniel-j Mar 7, 2023
e180e6a
try fix mbedtls on windows
daniel-j Mar 7, 2023
4728cb4
fix mbedtls config path
daniel-j Mar 7, 2023
679927e
user config maybe
daniel-j Mar 7, 2023
03adde1
normalize dirs
daniel-j Mar 7, 2023
53933d7
allow futhark on windows
daniel-j Mar 8, 2023
5287ebc
micros doesnt have a tag
daniel-j Mar 8, 2023
7b7f63d
revert micros version
daniel-j Mar 8, 2023
ab38575
btstack special raspberry pi license
daniel-j Mar 8, 2023
12092f2
cmake build type = Debug
daniel-j Mar 8, 2023
3fafc57
more compiler args to futhark
daniel-j Mar 8, 2023
35c632d
rename symbol to avoid clash with nim stdlib
daniel-j Mar 8, 2023
07ec42e
hide warning in altcp_tls_mbedtls.c
daniel-j Mar 9, 2023
6813995
cmake hide warning
daniel-j Mar 9, 2023
a5220b8
drop -fshort-enums, not needed
daniel-j Mar 9, 2023
2efc02e
check enum sizes
daniel-j Mar 9, 2023
929ebd1
after test
daniel-j Mar 13, 2023
2a0c4a8
gpio: use bitset for mask
daniel-j Mar 16, 2023
021bf30
backend
daniel-j Mar 16, 2023
aedd3a3
use fastclean in buildclean command
daniel-j Mar 20, 2023
83596fc
add pico.h wrapper for various board defaults
daniel-j Mar 20, 2023
027ffd8
formatting
daniel-j Mar 20, 2023
08b946e
version and change license
daniel-j Mar 20, 2023
45b2e5b
add picostdlibFutharkSysroot strdefine to let people choose sysroot f…
daniel-j Mar 20, 2023
f63f084
improve sysroot detection
daniel-j Mar 20, 2023
ee97e91
sysroot path
daniel-j Mar 20, 2023
5d7bb3a
sysroot and gcc search dirs
daniel-j Mar 20, 2023
2643af3
binary info test
daniel-j Mar 22, 2023
52da8fc
LittleFS wrapper and example
daniel-j Mar 22, 2023
6be0322
littlefs exports
daniel-j Mar 22, 2023
778b327
rename private to helpers
daniel-j Mar 23, 2023
aad492d
rtc docs
daniel-j Mar 23, 2023
737c732
littlefs fix for windows
daniel-j Mar 23, 2023
362f3bb
Add ntp example
daniel-j Mar 24, 2023
9940593
stop sntp
daniel-j Mar 24, 2023
8750124
force signed char, so futhark can generate cstring types
daniel-j Mar 28, 2023
7108aa2
nim devel fixes
daniel-j Mar 28, 2023
8aa0598
nimAllocPagesViaMalloc doesnt do anything under useMalloc, spi tweaks
daniel-j Mar 30, 2023
3dd5e80
stdio_init_all return type
daniel-j Mar 31, 2023
18a749e
make stdioInitAll discardable
daniel-j Mar 31, 2023
5e3c0b5
add nim datetime helpers
daniel-j May 10, 2023
6b3bb12
update to pico sdk 1.5.1
daniel-j Jun 21, 2023
13e4fc5
fix import in template
daniel-j Jun 25, 2023
6e9c8a9
improve blink examples and tests
daniel-j Jun 25, 2023
2658b26
improve i2c bus scan example
daniel-j Jun 25, 2023
c248648
support namedBin in nimble file
daniel-j Jun 25, 2023
fbebec8
remove echo
daniel-j Jun 25, 2023
6c0a4c7
add GpioOptional
daniel-j Jun 25, 2023
4b9b053
btstack removed some headers
daniel-j Jun 28, 2023
aca167d
fixes for nim 1.6.14 and nim devel
daniel-j Jun 28, 2023
7a9c606
comment space
daniel-j Jun 28, 2023
096fb54
Prepare for release. Update readme, license, piconim
daniel-j Jun 29, 2023
a4ab11e
remove toc from readme, was broken
daniel-j Jun 29, 2023
6292b62
log the memory, static and total size of binary
daniel-j Jun 29, 2023
0b71bdb
major version bump
daniel-j Jun 29, 2023
b19bd19
nimble author
daniel-j Jun 29, 2023
0188416
drop Pico prefix for constants defined in pico.nim
daniel-j Jun 29, 2023
f167cfd
drop Pico prefix of more things, fix duplicate vars
daniel-j Jun 29, 2023
a5ee46a
change example path
daniel-j Jun 29, 2023
277ccc0
change version to 0.4.0
daniel-j Jun 29, 2023
a176c60
move template dir to root, reorganize cmakefiles
daniel-j Jul 1, 2023
45ff59a
add board select to piconim init, move imports.cmake to build dir, re…
daniel-j Jul 3, 2023
6fef5c3
fix imports path
daniel-j Jul 3, 2023
8e60cc2
just in case
daniel-j Jul 3, 2023
d1e336a
disable a test on windows
daniel-j Jul 3, 2023
93ec6ca
description
daniel-j Jul 3, 2023
4f07b2b
for piconim init test
daniel-j Jul 3, 2023
7d83719
windows path fix
daniel-j Jul 4, 2023
cdf6806
use printf
daniel-j Jul 4, 2023
7e1abaa
clean up template, move stuff to common cmake files, tweaks to build
daniel-j Jul 4, 2023
22ecb87
update tasks to the new build system
daniel-j Jul 4, 2023
188f4b4
reorganize tests
daniel-j Jul 4, 2023
9a2c2ac
support different target name from binary name, add examples tasks
daniel-j Jul 4, 2023
08d9168
cant use include in nimble file...
daniel-j Jul 4, 2023
86cf018
add piconim build
daniel-j Jul 5, 2023
c710b3d
add piconim setup
daniel-j Jul 5, 2023
c4323ea
change nimble configure to nimble setup
daniel-j Jul 5, 2023
08c51c1
readme
daniel-j Jul 5, 2023
a762b95
run nimble setup if build cache doesnt exist
daniel-j Jul 5, 2023
56bd922
update gitignore
daniel-j Jul 5, 2023
b42aaa5
futhark version bump
daniel-j Jul 5, 2023
e45b039
update readme
daniel-j Jul 5, 2023
6977fcb
add nimbleutils dependency version
daniel-j Jul 5, 2023
2db1218
fix odd underscores
daniel-j Jul 5, 2023
e79ce69
limits.h isnt in include path on debian
daniel-j Jul 7, 2023
cfaf67a
pio updates wip
daniel-j Jul 10, 2023
1b967d3
fix pio
daniel-j Jul 11, 2023
a575f24
build system updates
daniel-j Jul 11, 2023
6220afe
fix cmake build
daniel-j Jul 11, 2023
2ee5761
clean up tests build
daniel-j Jul 11, 2023
373df61
fix docs
daniel-j Jul 11, 2023
9acc199
add pioInclude
daniel-j Jul 11, 2023
99d3499
add more structs and consts
daniel-j Jul 15, 2023
01bb34e
pio fix, piconim sets nimcache
daniel-j Jul 17, 2023
cca29b8
remove cached json if it exists when nim compile fails
daniel-j Jul 18, 2023
075dc5f
rename setup to configure, to be compatible with new nimble
daniel-j Aug 1, 2023
80c1210
tcp stuff inspired by arduino-pico
daniel-j Aug 7, 2023
82c134d
flush?
daniel-j Aug 7, 2023
4312040
add tls to tcp example
daniel-j Aug 7, 2023
8cdc3c7
build examples in release mode
daniel-j Aug 7, 2023
3434679
default to release mode
daniel-j Aug 7, 2023
a28c5ee
add stdinReadLine proc, read ssid and password from stdin if not set
daniel-j Aug 7, 2023
719b685
cleanup of tcp client stuff
daniel-j Aug 8, 2023
a6998f8
more cleanup
daniel-j Aug 8, 2023
d474a88
wip: add http client and example, based on httpclient from arduino-pico
daniel-j Aug 8, 2023
cd09902
add futharkgen task
daniel-j Aug 8, 2023
0a8fa76
improve futharkgen, used for nim check to avoid red squiggly lines
daniel-j Aug 9, 2023
25defc3
add littlefs and lwip_apps to futharkgen
daniel-j Aug 9, 2023
9dfa909
fix nim 2.0 warning
daniel-j Aug 9, 2023
4003f8d
fix ssid length
daniel-j Aug 9, 2023
c50056a
prettify interp module
daniel-j Aug 9, 2023
2244d52
casing
daniel-j Aug 9, 2023
061518b
nimify all hardware apis (drop prefixes to functions like gpio* i2c*)
daniel-j Aug 9, 2023
615e01d
fix gpio prefixes
daniel-j Aug 9, 2023
6058fc0
prettify gpio more
daniel-j Aug 10, 2023
14b088a
clean up and nimify api
daniel-j Aug 10, 2023
9dc76c6
better cmake binary dir detection, define NDEBUG and release dependin…
daniel-j Aug 10, 2023
f89c410
nimify adc more
daniel-j Aug 10, 2023
88aa343
gpio mask, pwm style, clocks style
daniel-j Aug 10, 2023
6720d46
nimify pwm
daniel-j Aug 10, 2023
45f483e
restore gpio helpers
daniel-j Aug 10, 2023
abb083a
fix setPwmLevel
daniel-j Aug 10, 2023
fc0a3ef
improve examples build, more nimification
daniel-j Aug 12, 2023
5e1ab03
dma helper
daniel-j Aug 12, 2023
605c109
add read_vsys example
daniel-j Aug 12, 2023
797c63e
refactor power reading to its own module
daniel-j Aug 12, 2023
20e71d0
readme
daniel-j Aug 12, 2023
5e28acf
readme
daniel-j Aug 12, 2023
3de0b0b
readme
daniel-j Aug 12, 2023
da5ce5e
build before install
daniel-j Aug 12, 2023
ed5b383
test template
daniel-j Aug 13, 2023
ab54146
light backwards compatability with deprecation notice
daniel-j Aug 13, 2023
9ff3691
discard
daniel-j Aug 23, 2023
405e61f
export cyw43
daniel-j Aug 23, 2023
bfda0d9
fix compatability with sdk, support uart in examples
daniel-j Aug 25, 2023
c8eb4ee
rename Datetime to DatetimeT to not collide with nim's DateTime
daniel-j Aug 27, 2023
d3dec6a
add experimental sleep example and rosc hardware
daniel-j Aug 27, 2023
238dbcd
windows fixes
daniel-j Aug 28, 2023
b664286
improve freertos, add blink example
daniel-j Aug 30, 2023
006a683
dont include lwip stuff in examples when not needed
daniel-j Aug 30, 2023
97d0da9
fix freertos type, comment debug message
daniel-j Oct 16, 2023
b47f4e2
Merge remote-tracking branch 'upstream/master'
daniel-j Nov 11, 2023
0e98e60
clean up trailing whitespace
daniel-j Nov 11, 2023
797412a
bump deps
daniel-j Nov 11, 2023
2e9a6e8
allow override of lwip and mbedtls versions
daniel-j Nov 22, 2023
19e20bc
experiment with compiling from Nim, switch from orc to arc, fix opt:s…
daniel-j Jan 2, 2024
ee3b72a
Merge branch 'master' of github.com:daniel-j/nim-picosdk
daniel-j Jan 2, 2024
7c98c5f
fix oopsie
daniel-j Jan 2, 2024
1266c9b
update FreeRTOS, includes SMP support
daniel-j Jan 2, 2024
f73da35
fix freertos
daniel-j Jan 3, 2024
651e3ae
skip nonexistant files in cmake nimcache, print memory stats
daniel-j Jan 3, 2024
89343b7
update littlefs to v2.8.2
daniel-j Jan 3, 2024
f6cfcf8
styleCheck lite
daniel-j Jan 4, 2024
7be0359
passC -> localPassC
daniel-j Jan 7, 2024
fcff4d7
disable warning
daniel-j Jan 7, 2024
43aa5e2
add patched monotimes, wrap more of freertos, async_context, tweak co…
daniel-j Jan 11, 2024
2bdc760
install nims files
daniel-j Jan 11, 2024
9b4f880
config.nims updates
daniel-j Jan 11, 2024
33af49f
selective nimpretty
daniel-j Jan 14, 2024
f670190
sync pico sdk devel
daniel-j Jan 14, 2024
9927be0
enable stdio and print in freertos example
daniel-j Jan 14, 2024
7c00a9d
update cyw43 with more static inline and comments
daniel-j Jan 17, 2024
3a1c802
fix httpclient path and errors
daniel-j Feb 9, 2024
fa955a1
fixes and add chunked transter-encoding decoder from picohttpparser
daniel-j Feb 13, 2024
b3ac701
add experimental tcpcontext (mockable/hostable)
daniel-j Feb 14, 2024
0055f11
bump littlefs version
daniel-j Feb 20, 2024
94620c1
bump mbedtls version
daniel-j Feb 20, 2024
172a1aa
start of picosocket, will replace tcpcontext/tcpclient
daniel-j Feb 21, 2024
5e022b1
wordwrap minicom
daniel-j Feb 21, 2024
1c3453e
remove double proc
daniel-j Feb 22, 2024
37b1c75
update picosocket
daniel-j Feb 22, 2024
bfdcd21
Merge branch 'master' of github.com:daniel-j/picostdlib
daniel-j Feb 22, 2024
44db961
more wrapped lwip macros
daniel-j Feb 23, 2024
641717e
skip strformat in picosocket, ipv6 fix, improve connect and testing
daniel-j Feb 23, 2024
e9d601b
fix lwip ipv4/ipv6 detection
daniel-j Feb 23, 2024
3d97bde
newSocket
daniel-j Feb 23, 2024
6015825
socket constructor and destructor
daniel-j Feb 23, 2024
9290e67
update tcp client to use picosocket
daniel-j Feb 23, 2024
c1b1882
better picosocket writing and reading stability
daniel-j Feb 23, 2024
5843a92
flush explicitly
daniel-j Feb 23, 2024
7bc19ea
fix build of examples
daniel-j Feb 24, 2024
b34826b
picosocket fixes
daniel-j Feb 25, 2024
2421b88
fix lwip
daniel-j Feb 25, 2024
869cd8d
async
daniel-j Feb 26, 2024
5810a61
tcp example works again
daniel-j Feb 26, 2024
66715c2
enable orc, fix closures, cleaner generics in picosocket
daniel-j Feb 27, 2024
a33e891
dns callbacks is of limited size
daniel-j Feb 28, 2024
cb37a49
update dns.nim
daniel-j Feb 28, 2024
70fdd62
remove owned
daniel-j Feb 28, 2024
bea96a8
revert to arc, use nimAllocPagesViaMalloc
daniel-j Feb 28, 2024
30150ae
picosocket, dns. dont leak
daniel-j Feb 28, 2024
40b8a01
make lock public
daniel-j Feb 28, 2024
e5c63c8
strict lto for nim objects
daniel-j Mar 1, 2024
1161586
Merge branch 'master' into feature-async-socket
daniel-j Mar 1, 2024
cdb6ba3
lower sntp interal
daniel-j Mar 1, 2024
b9020a1
Merge branch 'master' into feature-async-socket
daniel-j Mar 1, 2024
74a53f0
net common, include ntp optionally
daniel-j Mar 7, 2024
93c4fb5
wip mqtt client
daniel-j Mar 7, 2024
86ba340
Merge branch 'feature-async-socket' of github.com:daniel-j/picostdlib…
daniel-j Mar 7, 2024
f0b013c
mqtt data in callback
daniel-j Mar 10, 2024
583f8ab
should be uint16
daniel-j Mar 10, 2024
3d1aaad
fix mqtt buf offset
daniel-j Mar 10, 2024
d1f5a1b
improve mqttclient
daniel-j Mar 10, 2024
88adf54
add dns to mqttclient
daniel-j Mar 10, 2024
43bbc24
mqtt disable request cb for now, add publish and more configs
daniel-j Mar 10, 2024
224541b
mqtt qos enum
daniel-j Mar 10, 2024
5fce7c2
picosocket api
daniel-j Mar 18, 2024
83ddb45
fix tcp example
daniel-j Apr 13, 2024
9806a53
fix nim error
daniel-j Nov 5, 2024
f033371
Update common.nim
daniel-j Nov 5, 2024
b23f6d2
update, supports pico sdk 1.5.1
daniel-j Nov 7, 2024
b7429cd
readme
daniel-j Nov 7, 2024
1daa9db
Merge branch 'feature-async-socket'
daniel-j Nov 7, 2024
82f8a26
Update to support pico sdk v2.0.0
daniel-j Nov 7, 2024
6856a59
Merge remote-tracking branch 'upstream/master'
daniel-j Nov 7, 2024
231ac47
disable freertos in test too
daniel-j Nov 18, 2024
1cd078c
disable freertos in more places, socket fixes
daniel-j Nov 18, 2024
7e7ce76
add 3rd party pico-vfs filesystem module
daniel-j Nov 19, 2024
e0f85b2
tweak lstat workaround
daniel-j Nov 20, 2024
103123b
update filesystem
daniel-j Nov 20, 2024
93564ca
fix cyw43 constant
daniel-j Nov 25, 2024
0a0e32a
updates for sdk 2.1.0 and some other fixes
daniel-j Nov 26, 2024
4973e5d
minor fixes
daniel-j Nov 26, 2024
7792d26
pico_filesystem define
daniel-j Nov 27, 2024
e186416
add contentType to httpclient
daniel-j Nov 27, 2024
1d65d15
socket fixes
daniel-j Nov 28, 2024
28b5b10
add new httpclient using picosocket
daniel-j Nov 28, 2024
cf3313a
fix
daniel-j Nov 29, 2024
b5023f3
add sysroot fallback
daniel-j Dec 26, 2024
0b787f7
Merge branch 'master' of github.com:daniel-j/picostdlib
daniel-j Dec 26, 2024
0de7402
add support for Pico 2 and Pico 2 W
daniel-j Jan 3, 2025
052b13c
add async context example hello_async
daniel-j Jan 8, 2025
3560be1
update async example, add Promise and coroutines
daniel-j Jan 10, 2025
99122ef
coroutine await any promise type
daniel-j Jan 10, 2025
3558a76
use Nim's asyncfutures for async and hook promises into it
daniel-j Jan 13, 2025
bc501f5
async updates
daniel-j Jan 16, 2025
4b1ae6c
async: wait for event
daniel-j Jan 16, 2025
91cbac4
support nim 2.2.2
daniel-j Feb 9, 2025
80add1d
lock futhark version (0.14.0 is broken)
daniel-j Feb 9, 2025
49906e4
update futhark
daniel-j Feb 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
*
!*.*
!*/

nimcache/
nimblecache/
htmldocs/

/htmldocs/
/piconim
/build/
/tests/test_mock
/testproject*/
/secret.nims
/src/picostdlib/futharkgen
/piconim
/piconim.exe
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/picostdlib/vendor/pico-vfs"]
path = src/picostdlib/vendor/pico-vfs
url = https://github.com/daniel-j/pico-vfs.git
35 changes: 19 additions & 16 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
MIT License
BSD-3-Clause License

Copyright (c) 2021 Jason Beetham
Copyright (c) 2022-2023 Daniel Jönsson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
disclaimer.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
126 changes: 87 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,129 @@
# Raspberry Pi Pico SDK for Nim

This library provides the library and build system necessary to write programs for RP2040 based devices (such as the Raspberry Pi Pico) in the [Nim](https://nim-lang.org/) programming language
This library provides the library and build system necessary to write
programs for RP2040-based devices (such as the Raspberry Pi Pico) in the
[Nim](https://nim-lang.org/) programming language.

The libary provides wrappers for the original [Raspberry Pi Pico
SDK](https://github.com/raspberrypi/pico-sdk). The following features are
currently implemented:
The libary provides a complete wrapper for the [Raspberry Pi Pico
SDK](https://github.com/raspberrypi/pico-sdk) v2.1.0. Here are some of the feature highlights:

* Automatic project scaffolding using the `piconim` tool
* Standard library features such as GPIO, time, ADC, PWM and many more
* Rudimentary TinyUSB support: USB device, HID and CDC (serial port) classes
* Project generator and building using the `piconim` tool
* Setup, build and upload your project using Nimble, automatically runs CMake
(use piconim for advanced building)
* Standard SDK library features such as GPIO, time, ADC, PWM and many more
* Wrapper for Pico SDK functions but with Nim flavour, with strict types for safety
* Wireless support for Pico W (Wifi, Bluetooth, HTTPS)

Blink example (works on Pico W too!)

## Table of Contents
```nim
import picostdlib

[Setup](##Setup)
DefaultLedPin.init()
DefaultLedPin.setDir(Out)

[Building](##Building)

[Examples](examples)
while true:
DefaultLedPin.put(High)
sleepMs(250)
DefaultLedPin.put(Low)
sleepMs(250)
```

[Contributing](##Contributing)
See the [examples](examples) folder for more examples on how to use the SDK using Nim.

[License](LICENSE)

## Setup

**The following steps will install piconim and create a new project**

1. First, you will need to have the Nim compiler installed. If you don't already
have it, consider using [choosenim](https://github.com/dom96/choosenim)
have it, consider using [choosenim](https://github.com/dom96/choosenim).

2. Since this is just a wrapper for the original
[pico-sdk](https://github.com/raspberrypi/pico-sdk), you will need to install the C
library [dependencies](https://github.com/raspberrypi/pico-sdk#quick-start-your-own-project)
(Step 1 in the quick start section)
(Step 1 in the quick start section).

3. Some parts of this library uses [Futhark](https://github.com/PMunch/futhark) to
wrap some C libraries, which depends on libclang.
See its installation guide [here](https://github.com/PMunch/futhark#installation).

3. From the terminal, run `nimble install https://github.com/EmbeddedNim/picostdlib`.
4. From the terminal, run `nimble install https://github.com/EmbeddedNim/picostdlib`.

4. Run `piconim init <project-name>` to create a new project directory from a
5. Run `piconim init <project-name>` to create a new project directory from a
template. This will create a new folder, so make sure you are in the parent folder.
When it asks for what project type, choose `>binary<` or `>hybrid<`. If you choose
`>library<` there will be nothing to build.
You can also provide the following options to the subcommand:
- (--sdk, -s) -> specify the path to a locally installed `pico-sdk` repository,
ex. `--sdk:/home/casey/pico-sdk`
ex. `--sdk:/home/user/pico-sdk`.
- (--board, -b) -> specify the board type (`pico` or `pico_w` are accepted),
choosing pico_w includes a pico_w blink example
- (--overwrite, -O) -> a flag to specify overwriting an exisiting directory
with the `<project-name>` already created. Be careful with this.
ex. `piconim myProject --overwrite` will replace a folder named `myProject`
with the `<project-name>` already created. Be careful with this.
ex. `piconim myProject --overwrite` will replace a folder named `myProject`

## Building
6. Change directory to the new project and run `nimble configure`. This will initialize
the Pico SDK using CMake. If you provided a path to the SDK in the previous step, it will
use that, otherwise it will download the SDK from GitHub, or if you have the Pico SDK installed
already, it will use environment variable `PICO_SDK_PATH`.

Now you can work on your project. When you are ready to build the `.uf2` file
(which will be copied to the Raspberry Pi Pico), you can use the `build` subcommand:
You are now ready to start developing and building your project.

`piconim build <main-program>`

Where `<main-program>` is the main module in your `src` folder. (ex. `piconim
build myProject` if the main nim file is `myProject.nim`). You can also specify
an output directory, otherwise it will be placed in `csource/build`
## Building

### `piconim setup`
When you are ready to build the `.uf2` file (which will be copied to the Raspberry Pi Pico),
you can use the `build` command of Nimble:

If a piconim project is cloned fresh, or if `git clean` is ran, then the `csource/build`
directory will need to be re-generated by CMake. This can be accomplished with the
`piconim setup` command. The `setup` command takes an optional `--sdk` argument that works
exactly like for the `init` command, described above.
`nimble build`

Examples:
The generated `.uf2` file is placed in `build/<project>/<program>.uf2`

Modify `CMakeLists.txt` to suit your project's needs.

## Usage

```bash
# Run these commands from the project root.
# Initialize a new project
piconim init [--sdk <sdk-path>] [--board <pico-board>] [--overwrite] <project-name>

# Run the following commands from the project root.
# If you don't specify a program name, it will use all
# binaries specified in your Nimble file. You can specify multiple.

# Run CMake configure, download Pico SDK from Github (if needed)
nimble configure [program]

# Re-run CMake, download Pico SDK from Github
piconim setup
# Builds C/C++ files with Nim, runs CMake build/make
nimble build [program]

# Run the CMake clean target, and cleans nimcache
nimble fastclean [program]

# Clean build directories, and cleans nimcache
nimble distclean [program]

# Runs clean and then builds.
nimble buildclean [program]

# Upload using picotool (installed separately)
# Pass --build to run build task first. Add --clean to clean before building.
nimble upload [program] [--build] [--clean]

# Monitors the tty port using minicom (/dev/ttyACM0)
nimble monitor

# Runs CMake configure without Nimble.
piconim configure [--project <project-name>] [--source <source-dir>] [--sdk <sdk-path>]
[--board <pico-board>]

# Build a program without Nimble.
piconim build [--project <project-name>] [--target <target>] [--compileOnly] [--upload] <program>

# Re-run CMake, use existing SDK
piconim setup --sdk:/home/casey/pico-sdk
```


## Contributing

Please contribute.
157 changes: 157 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
cmake_minimum_required(VERSION 3.13...3.27)

# Set CMake build type. Debug, Release, MinSizeRel, RelWithDebInfo
set(CMAKE_BUILD_TYPE Release)

# Set standards
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# initialize pico-sdk from GIT
# (note this can come from environment, CMake cache etc)
#set(PICO_SDK_FETCH_FROM_GIT on)
#set(PICO_SDK_PATH ENV{PICO_SDK_PATH}) # Set by piconim

# Set board type here
if(NOT DEFINED PICO_BOARD)
set(PICO_BOARD pico)
endif()

# Support C++ exceptions with Nim
set(PICO_CXX_ENABLE_EXCEPTIONS 1)

# Uncomment to disable picotool binary info
# set(PICO_NO_BINARY_INFO 1)


set(PICOSTDLIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../src")
set(pico_generate_pio_header_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")

# note: this must happen before project()
include(${PICOSTDLIB_DIR}/picostdlib/cmake/pico_sdk_import.cmake)

project(examples C CXX ASM)


include(FetchContent)

FetchContent_Declare(mbedtls
GIT_REPOSITORY https://github.com/Mbed-TLS/mbedtls.git
GIT_TAG v2.28.7
)

FetchContent_Declare(lwip
GIT_REPOSITORY https://git.savannah.gnu.org/git/lwip.git
GIT_TAG STABLE-2_2_0_RELEASE
)

FetchContent_Declare(freertos_kernel
GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Kernel.git
GIT_TAG V11.0.1
)

# fetch and use alternative mbedtls version
#FetchContent_MakeAvailable(mbedtls)
#set(PICO_MBEDTLS_PATH ${mbedtls_SOURCE_DIR})

# fetch and use alternative lwip version
#FetchContent_MakeAvailable(lwip)
#set(PICO_LWIP_PATH ${lwip_SOURCE_DIR})

# fetch and initialize FreeRTOS-Kernel
add_library(freertos_config INTERFACE)
target_include_directories(freertos_config SYSTEM INTERFACE ${CMAKE_SOURCE_DIR}/../template/csource) # The config file directory
set(FREERTOS_PORT GCC_RP2040 CACHE STRING "")
# FetchContent_MakeAvailable(freertos_kernel)
# include(${freertos_kernel_SOURCE_DIR}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake)


# initialize the Raspberry Pi Pico SDK
pico_sdk_init()

include(${PICOSTDLIB_DIR}/picostdlib/cmake/picostdlib.cmake)

function(add_example name)
set(target "${name}")

add_executable(${target})

picostdlib_target(${target} ${name})

# set_target_properties(${target} PROPERTIES LINKER_LANGUAGE CXX)

target_include_directories(${target} PRIVATE
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/../template/csource
# ${PICO_SDK_PATH}/lib/lwip/src/include/compat/posix
)

target_link_libraries(${target}
# Additional libraries
)

target_compile_definitions(${target} PRIVATE
# CYW43_HOST_NAME="PicoW"
PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS=2000
)

# enable usb output, disable uart output
pico_enable_stdio_usb(${target} 1)
pico_enable_stdio_uart(${target} 0)

# create map/bin/hex/uf2 file etc.
pico_add_extra_outputs(${target})

# add url via pico_set_program_url
# pico_set_program_url(${target} "")
endfunction()


if(PICO_CYW43_SUPPORTED)
# wireless examples
add_example(picow_blink)
add_example(picow_http_client)
add_example(picow_ntp_client)
add_example(picow_tcp_client)
add_example(picow_mqtt_client)
add_example(picow_tls_client)
add_example(picow_wifi_scan)
else()
# does not support wl_gpio
add_example(hello_pio)
add_example(pwm_led_fade)
endif()

add_example(blink)
add_example(hello_async)
add_example(hello_adc)
add_example(onboard_temperature)
add_example(read_vsys)
add_example(hello_resus)
add_example(hello_stdio)
add_example(hello_48mhz)
add_example(hello_gpout)
add_example(hello_dma)
add_example(hello_filesystem_flash)
add_example(hello_filesystem_sd)
add_example(hello_littlefs)
add_example(hello_7segment)
add_example(hello_gpio_irq)
add_example(hello_serial)
add_example(hello_timestart)
add_example(bus_scan)
# add_example(joystickdisplay)
# add_example(lightsensor)
add_example(hello_multicore)
add_example(hello_pwm)
add_example(hello_reset)
add_example(hello_rtc)
add_example(rtc_alarm)
add_example(unique_board_id)
add_example(hello_sleep)
add_example(hello_timer)
# "tinyusb"
add_example(hello_uart)
add_example(hello_watchdog)
# "ws2812_pio"
# add_example(freertos_blink)
Loading