Skip to content

Commit f57b44f

Browse files
authored
Merge pull request #15 from mutablelogic/dev
Merge dev into main
2 parents 2278aef + 935e1c4 commit f57b44f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+8090
-1045
lines changed

.gitmodules

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
[submodule "lib/pico-sdk"]
22
path = lib/pico-sdk
3-
url = https://github.com/raspberrypi/pico-sdk
4-
branch = 1.5.1
3+
url = https://github.com/raspberrypi/pico-sdk.git
4+
branch = 2.0.0
5+
56
[submodule "lib/picotool"]
67
path = lib/picotool
78
url = https://github.com/raspberrypi/picotool.git
8-
branch = 1.1.2
9+
branch = 2.0.0

CMakeLists.txt

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,46 @@
11
# Versions
2-
cmake_minimum_required(VERSION 3.12)
2+
cmake_minimum_required(VERSION 3.13)
33
set(CMAKE_C_STANDARD 11)
4-
set(CMAKE_CXX_STANDARD 17)
54

65
# PICO_BOARD
76
if (DEFINED ENV{PICO_BOARD})
8-
set(PICO_BOARD $ENV{PICO_BOARD})
9-
message("Using PICO_BOARD from environment ('${PICO_BOARD}')")
7+
set(PICO_BOARD "$ENV{PICO_BOARD}")
8+
set(TARGET_OS "pico")
9+
include(lib/pico-sdk/pico_sdk_init.cmake)
1010
else()
11-
if (NOT PICO_BOARD)
12-
set(PICO_BOARD "pico")
13-
message("Defaulting PICO target board to ${PICO_BOARD} since not specified")
14-
else()
15-
message("PICO target board is ${PICO_BOARD}")
16-
endif()
11+
set(TARGET_OS ${CMAKE_HOST_SYSTEM_NAME})
12+
string(TOLOWER ${TARGET_OS} TARGET_OS)
1713
endif()
14+
message("Target ${TARGET_OS}")
1815

19-
# TARGET set to linux, darwin or pico depending on PICO_BOARD
20-
if(PICO_BOARD STREQUAL "linux")
21-
set(TARGET "linux")
22-
add_compile_definitions(TARGET_LINUX)
23-
add_compile_definitions(TARGET_POSIX)
24-
elseif(PICO_BOARD STREQUAL "darwin")
25-
set(TARGET "darwin")
16+
# TARGET_DARWIN, TARGET_LINUX and TARGET_PICO
17+
if (TARGET_OS STREQUAL "darwin")
2618
add_compile_definitions(TARGET_DARWIN)
27-
add_compile_definitions(TARGET_POSIX)
28-
else()
29-
set(TARGET "pico")
19+
elseif (TARGET_OS STREQUAL "linux")
20+
add_compile_definitions(TARGET_LINUX)
21+
elseif (TARGET_OS STREQUAL "pico")
3022
add_compile_definitions(TARGET_PICO)
31-
include(lib/pico-sdk/pico_sdk_init.cmake)
3223
endif()
3324

3425
# Define project
35-
project(fuse CXX C ASM)
26+
project(picofuse CXX C ASM)
3627

3728
# TODO!!!
3829
add_compile_definitions(DEBUG)
3930

40-
# Pico libraries
41-
if(${TARGET} STREQUAL "pico")
42-
pico_sdk_init()
43-
endif()
44-
45-
# Libraries
31+
# picofuse libraries
4632
add_subdirectory(src/fuse)
47-
if(${TARGET} STREQUAL "pico")
33+
if(TARGET_OS STREQUAL "pico")
34+
pico_sdk_init()
4835
add_subdirectory(src/picofuse)
4936
endif()
5037

5138
# Tests
5239
include(CTest)
40+
add_subdirectory(tests/fuse)
5341

54-
# Tests - fuse
55-
add_subdirectory(tests/app)
56-
add_subdirectory(tests/list)
57-
add_subdirectory(tests/map)
58-
add_subdirectory(tests/panic)
59-
add_subdirectory(tests/pool)
60-
add_subdirectory(tests/random)
61-
add_subdirectory(tests/value)
62-
63-
# Tests - picofuse
64-
if(${TARGET} STREQUAL "pico")
65-
add_subdirectory(tests/blink)
66-
add_subdirectory(tests/temperature)
42+
# Examples
43+
add_subdirectory(examples/fuse)
44+
if(TARGET_OS STREQUAL "pico")
45+
add_subdirectory(examples/picofuse)
6746
endif()
68-

Makefile

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ BUILD_DIR := build
22
SRC_DIR := $(filter-out src/old, $(wildcard src/*))
33
EXAMPLES_DIR := $(wildcard examples/*)
44
TESTS_DIR := $(wildcard tests/*)
5+
PREFIX ?= /usr/local
56

67
# Paths to tools needed in dependencies
78
GIT := $(shell which git)
89
CMAKE := $(shell which cmake)
910

1011
# Pico variables
11-
PICO_PLATFORM ?= rp2040
1212
PICO_BOARD ?= pico_w
1313

1414
# Targets
@@ -17,25 +17,24 @@ all: config picotool test examples
1717
test: config
1818
@make -C ${BUILD_DIR} all test
1919

20-
config: dependencies mkdir
21-
@echo git submodule update pico-sdk
22-
@${GIT} submodule update --init
23-
@cd lib/pico-sdk && ${GIT} submodule update --init
20+
examples: config
21+
@make -C ${BUILD_DIR} all examples
22+
23+
config: dependencies mkdir submodule
2424
@echo cmake config
25-
@${CMAKE} -B ${BUILD_DIR} -DPICO_PLATFORM=${PICO_PLATFORM} -DPICO_BOARD=${PICO_BOARD}
25+
@${CMAKE} -B ${BUILD_DIR} -DPICO_BOARD=${PICO_BOARD}
2626

27-
picotool: config
28-
@echo git submodule update picotool
29-
@cd lib/picotool && ${GIT} submodule update --init
27+
picotool: dependencies mkdir submodule
3028
@echo make picotool
3129
@PICO_SDK_PATH=../../../lib/pico-sdk ${CMAKE} -S lib/picotool -B ${BUILD_DIR}/lib/picotool
3230
@make -C ${BUILD_DIR}/lib/picotool
31+
@echo "\nRun:\n install -s ${BUILD_DIR}/lib/picotool/picotool ${PREFIX}/bin\n"
3332

3433
src: $(SRC_DIR)
3534

36-
tests: $(TESTS_DIR)
37-
38-
examples: $(EXAMPLES_DIR)
35+
$(TESTS_DIR): dependencies mkdir
36+
@echo make $(notdir $@)
37+
@make -C ${BUILD_DIR}/$@
3938

4039
$(SRC_DIR): dependencies mkdir
4140
@echo make $(notdir $@)
@@ -49,14 +48,34 @@ $(EXAMPLES_DIR): dependencies mkdir
4948
@echo make $(notdir $@)
5049
@make -C ${BUILD_DIR}/$@
5150

51+
# Update submodule to the 2.0.0 version
52+
submodule-update: dependencies
53+
@echo "Updating submodules"
54+
@${GIT} pull --recurse-submodules
55+
@cd lib/pico-sdk && ${GIT} pull origin 2.0.0 && cd ../..
56+
@cd lib/picotool && ${GIT} pull origin 2.0.0 && cd ../..
57+
@${GIT} submodule sync --recursive
58+
59+
# Submodule checkout
60+
submodule: dependencies
61+
@echo "Checking out submodules"
62+
@${GIT} submodule update --init --recursive
63+
64+
# Submodule clean
65+
submodule-clean: dependencies
66+
@echo "Cleaning submodules"
67+
@${GIT} reset --hard
68+
@${GIT} submodule sync --recursive
69+
@${GIT} submodule update --init --force --recursive
70+
@${GIT} clean -ffdx
71+
@${GIT} submodule foreach --recursive git clean -ffdx
72+
5273
mkdir:
5374
@echo mkdir ${BUILD_DIR}
5475
@install -d ${BUILD_DIR}
5576

56-
clean:
77+
clean: submodule-clean
5778
@echo clean
58-
@cd lib/pico-sdk && ${GIT} submodule deinit --force --all
59-
@cd lib/picotool && ${GIT} submodule deinit --force --all
6079
@rm -fr $(BUILD_DIR)
6180

6281
dependencies:

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,11 @@ On Mac with homebrew, the following packages need installed:
4444

4545
```bash
4646
brew install make cmake libusb git
47-
brew tap ArmMbed/homebrew-formulae
48-
brew install arm-none-eabi-gcc
47+
brew install --cask gcc-arm-embedded
4948
```
5049

51-
If you haven't done so already, [create an ssh key](https://www.digitalocean.com/community/tutorials/how-to-create-ssh-keys-with-openssh-on-macos-or-linux) and [add it to your
52-
github account](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account).
50+
If you haven't done so already, [create an ssh key](https://www.digitalocean.com/community/tutorials/how-to-create-ssh-keys-with-openssh-on-macos-or-linux)
51+
and [add it to your github account](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account).
5352

5453
## Configuration
5554

examples/fuse/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
##############################################################################
3+
4+
set(NAME "helloworld")
5+
6+
add_executable(${NAME}
7+
common/main.c
8+
helloworld/run.c
9+
)
10+
target_include_directories(${NAME} PRIVATE
11+
${CMAKE_CURRENT_LIST_DIR}/../../include
12+
)
13+
target_link_libraries(${NAME} fuse)
14+
15+
if(TARGET_OS STREQUAL "pico")
16+
# enable usb output, disable uart output
17+
pico_enable_stdio_usb(${NAME} 1)
18+
pico_enable_stdio_uart(${NAME} 0)
19+
20+
# create map/bin/hex/uf2 file etc.
21+
pico_add_extra_outputs(${NAME})
22+
endif()

examples/fuse/common/main.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <fuse/fuse.h>
2+
3+
int run(fuse_t *fuse);
4+
5+
int main()
6+
{
7+
fuse_t *fuse = fuse_new();
8+
assert(fuse);
9+
fuse_run(fuse, run);
10+
11+
// Destroy the applicatiom, return exit code
12+
return fuse_destroy(fuse);
13+
}

examples/fuse/helloworld/run.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <fuse/fuse.h>
2+
3+
int run(fuse_t *fuse)
4+
{
5+
// Make and free a NULL value
6+
fuse_value_t *value = fuse_alloc(fuse, FUSE_MAGIC_NULL, NULL);
7+
fuse_printf(fuse, "null value=%q\n", value);
8+
fuse_free(fuse, value);
9+
10+
// Make and free a DATA value
11+
value = fuse_alloc(fuse, FUSE_MAGIC_DATA, NULL);
12+
fuse_printf(fuse, "data value=%q\n", value);
13+
fuse_free(fuse, value);
14+
15+
// Make and free a U8 value
16+
value = fuse_alloc(fuse, FUSE_MAGIC_U8, (void *)0xFF);
17+
fuse_printf(fuse, "u8 value=%q\n", value);
18+
fuse_free(fuse, value);
19+
20+
// Make and free a U16 value
21+
value = fuse_alloc(fuse, FUSE_MAGIC_U16, (void *)0xFFFF);
22+
fuse_printf(fuse, "u16 value=%q\n", value);
23+
fuse_free(fuse, value);
24+
25+
// Make and free a U32 value
26+
value = fuse_alloc(fuse, FUSE_MAGIC_U32, (void *)0xFFFFFFFF);
27+
fuse_printf(fuse, "u32 value=%q\n", value);
28+
fuse_free(fuse, value);
29+
30+
// Make and free a U64 value
31+
value = fuse_alloc(fuse, FUSE_MAGIC_U64, (void *)0xFFFFFFFFFFFFFFFF);
32+
fuse_printf(fuse, "u64 value=%q\n", value);
33+
fuse_free(fuse, value);
34+
35+
// Make and free a S8 value
36+
value = fuse_alloc(fuse, FUSE_MAGIC_S8, (void *)0x7F);
37+
fuse_printf(fuse, "s8 value=%v\n", value);
38+
fuse_free(fuse, value);
39+
40+
// Make and free a S16 value
41+
value = fuse_alloc(fuse, FUSE_MAGIC_S16, (void *)0x7FFF);
42+
fuse_printf(fuse, "s16 value=%q\n", value);
43+
fuse_free(fuse, value);
44+
45+
// Make a list
46+
fuse_value_t *list = fuse_alloc(fuse, FUSE_MAGIC_LIST, 0);
47+
fuse_printf(fuse, "list value=%q\n", value);
48+
49+
// Free the list
50+
fuse_free(fuse, list);
51+
52+
return 0;
53+
}

examples/picofuse/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
##############################################################################
3+
4+
set(NAME "gpio_in")
5+
6+
add_executable(${NAME}
7+
common/main.c
8+
gpio_in/run.c
9+
)
10+
target_include_directories(${NAME} PRIVATE
11+
${CMAKE_CURRENT_LIST_DIR}/../../include
12+
)
13+
target_link_libraries(${NAME} picofuse)
14+
15+
# enable usb output, disable uart output
16+
pico_enable_stdio_usb(${NAME} 1)
17+
pico_enable_stdio_uart(${NAME} 0)
18+
19+
# create map/bin/hex/uf2 file etc.
20+
pico_add_extra_outputs(${NAME})

examples/picofuse/blink/run.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <picofuse/picofuse.h>
2+
3+
#define LED_DELAY_MS 250
4+
5+
int run(fuse_t* fuse) {
6+
fuse_led_new();
7+
8+
while (true) {
9+
fuse_led_set(1);
10+
sleep_ms(LED_DELAY_MS);
11+
fuse_led_set(0);
12+
sleep_ms(LED_DELAY_MS);
13+
}
14+
15+
fuse_led_destroy();
16+
return 0;
17+
}

examples/picofuse/common/main.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <fuse/fuse.h>
2+
3+
int run(fuse_t *fuse);
4+
5+
int main()
6+
{
7+
fuse_t *fuse = fuse_new();
8+
assert(fuse);
9+
fuse_run(fuse, run);
10+
11+
// Destroy the applicatiom, return exit code
12+
return fuse_destroy(fuse);
13+
}

0 commit comments

Comments
 (0)