Skip to content

Commit

Permalink
Merge pull request #15 from mutablelogic/dev
Browse files Browse the repository at this point in the history
Merge dev into main
  • Loading branch information
djthorpe authored Sep 3, 2024
2 parents 2278aef + 935e1c4 commit f57b44f
Show file tree
Hide file tree
Showing 127 changed files with 8,090 additions and 1,045 deletions.
7 changes: 4 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[submodule "lib/pico-sdk"]
path = lib/pico-sdk
url = https://github.com/raspberrypi/pico-sdk
branch = 1.5.1
url = https://github.com/raspberrypi/pico-sdk.git
branch = 2.0.0

[submodule "lib/picotool"]
path = lib/picotool
url = https://github.com/raspberrypi/picotool.git
branch = 1.1.2
branch = 2.0.0
64 changes: 21 additions & 43 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,68 +1,46 @@
# Versions
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.13)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# PICO_BOARD
if (DEFINED ENV{PICO_BOARD})
set(PICO_BOARD $ENV{PICO_BOARD})
message("Using PICO_BOARD from environment ('${PICO_BOARD}')")
set(PICO_BOARD "$ENV{PICO_BOARD}")
set(TARGET_OS "pico")
include(lib/pico-sdk/pico_sdk_init.cmake)
else()
if (NOT PICO_BOARD)
set(PICO_BOARD "pico")
message("Defaulting PICO target board to ${PICO_BOARD} since not specified")
else()
message("PICO target board is ${PICO_BOARD}")
endif()
set(TARGET_OS ${CMAKE_HOST_SYSTEM_NAME})
string(TOLOWER ${TARGET_OS} TARGET_OS)
endif()
message("Target ${TARGET_OS}")

# TARGET set to linux, darwin or pico depending on PICO_BOARD
if(PICO_BOARD STREQUAL "linux")
set(TARGET "linux")
add_compile_definitions(TARGET_LINUX)
add_compile_definitions(TARGET_POSIX)
elseif(PICO_BOARD STREQUAL "darwin")
set(TARGET "darwin")
# TARGET_DARWIN, TARGET_LINUX and TARGET_PICO
if (TARGET_OS STREQUAL "darwin")
add_compile_definitions(TARGET_DARWIN)
add_compile_definitions(TARGET_POSIX)
else()
set(TARGET "pico")
elseif (TARGET_OS STREQUAL "linux")
add_compile_definitions(TARGET_LINUX)
elseif (TARGET_OS STREQUAL "pico")
add_compile_definitions(TARGET_PICO)
include(lib/pico-sdk/pico_sdk_init.cmake)
endif()

# Define project
project(fuse CXX C ASM)
project(picofuse CXX C ASM)

# TODO!!!
add_compile_definitions(DEBUG)

# Pico libraries
if(${TARGET} STREQUAL "pico")
pico_sdk_init()
endif()

# Libraries
# picofuse libraries
add_subdirectory(src/fuse)
if(${TARGET} STREQUAL "pico")
if(TARGET_OS STREQUAL "pico")
pico_sdk_init()
add_subdirectory(src/picofuse)
endif()

# Tests
include(CTest)
add_subdirectory(tests/fuse)

# Tests - fuse
add_subdirectory(tests/app)
add_subdirectory(tests/list)
add_subdirectory(tests/map)
add_subdirectory(tests/panic)
add_subdirectory(tests/pool)
add_subdirectory(tests/random)
add_subdirectory(tests/value)

# Tests - picofuse
if(${TARGET} STREQUAL "pico")
add_subdirectory(tests/blink)
add_subdirectory(tests/temperature)
# Examples
add_subdirectory(examples/fuse)
if(TARGET_OS STREQUAL "pico")
add_subdirectory(examples/picofuse)
endif()

49 changes: 34 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ BUILD_DIR := build
SRC_DIR := $(filter-out src/old, $(wildcard src/*))
EXAMPLES_DIR := $(wildcard examples/*)
TESTS_DIR := $(wildcard tests/*)
PREFIX ?= /usr/local

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

# Pico variables
PICO_PLATFORM ?= rp2040
PICO_BOARD ?= pico_w

# Targets
Expand All @@ -17,25 +17,24 @@ all: config picotool test examples
test: config
@make -C ${BUILD_DIR} all test

config: dependencies mkdir
@echo git submodule update pico-sdk
@${GIT} submodule update --init
@cd lib/pico-sdk && ${GIT} submodule update --init
examples: config
@make -C ${BUILD_DIR} all examples

config: dependencies mkdir submodule
@echo cmake config
@${CMAKE} -B ${BUILD_DIR} -DPICO_PLATFORM=${PICO_PLATFORM} -DPICO_BOARD=${PICO_BOARD}
@${CMAKE} -B ${BUILD_DIR} -DPICO_BOARD=${PICO_BOARD}

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

src: $(SRC_DIR)

tests: $(TESTS_DIR)

examples: $(EXAMPLES_DIR)
$(TESTS_DIR): dependencies mkdir
@echo make $(notdir $@)
@make -C ${BUILD_DIR}/$@

$(SRC_DIR): dependencies mkdir
@echo make $(notdir $@)
Expand All @@ -49,14 +48,34 @@ $(EXAMPLES_DIR): dependencies mkdir
@echo make $(notdir $@)
@make -C ${BUILD_DIR}/$@

# Update submodule to the 2.0.0 version
submodule-update: dependencies
@echo "Updating submodules"
@${GIT} pull --recurse-submodules
@cd lib/pico-sdk && ${GIT} pull origin 2.0.0 && cd ../..
@cd lib/picotool && ${GIT} pull origin 2.0.0 && cd ../..
@${GIT} submodule sync --recursive

# Submodule checkout
submodule: dependencies
@echo "Checking out submodules"
@${GIT} submodule update --init --recursive

# Submodule clean
submodule-clean: dependencies
@echo "Cleaning submodules"
@${GIT} reset --hard
@${GIT} submodule sync --recursive
@${GIT} submodule update --init --force --recursive
@${GIT} clean -ffdx
@${GIT} submodule foreach --recursive git clean -ffdx

mkdir:
@echo mkdir ${BUILD_DIR}
@install -d ${BUILD_DIR}

clean:
clean: submodule-clean
@echo clean
@cd lib/pico-sdk && ${GIT} submodule deinit --force --all
@cd lib/picotool && ${GIT} submodule deinit --force --all
@rm -fr $(BUILD_DIR)

dependencies:
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ On Mac with homebrew, the following packages need installed:

```bash
brew install make cmake libusb git
brew tap ArmMbed/homebrew-formulae
brew install arm-none-eabi-gcc
brew install --cask gcc-arm-embedded
```

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
github account](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account).
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 github account](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account).

## Configuration

Expand Down
22 changes: 22 additions & 0 deletions examples/fuse/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

##############################################################################

set(NAME "helloworld")

add_executable(${NAME}
common/main.c
helloworld/run.c
)
target_include_directories(${NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/../../include
)
target_link_libraries(${NAME} fuse)

if(TARGET_OS STREQUAL "pico")
# enable usb output, disable uart output
pico_enable_stdio_usb(${NAME} 1)
pico_enable_stdio_uart(${NAME} 0)

# create map/bin/hex/uf2 file etc.
pico_add_extra_outputs(${NAME})
endif()
13 changes: 13 additions & 0 deletions examples/fuse/common/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <fuse/fuse.h>

int run(fuse_t *fuse);

int main()
{
fuse_t *fuse = fuse_new();
assert(fuse);
fuse_run(fuse, run);

// Destroy the applicatiom, return exit code
return fuse_destroy(fuse);
}
53 changes: 53 additions & 0 deletions examples/fuse/helloworld/run.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <fuse/fuse.h>

int run(fuse_t *fuse)
{
// Make and free a NULL value
fuse_value_t *value = fuse_alloc(fuse, FUSE_MAGIC_NULL, NULL);
fuse_printf(fuse, "null value=%q\n", value);
fuse_free(fuse, value);

// Make and free a DATA value
value = fuse_alloc(fuse, FUSE_MAGIC_DATA, NULL);
fuse_printf(fuse, "data value=%q\n", value);
fuse_free(fuse, value);

// Make and free a U8 value
value = fuse_alloc(fuse, FUSE_MAGIC_U8, (void *)0xFF);
fuse_printf(fuse, "u8 value=%q\n", value);
fuse_free(fuse, value);

// Make and free a U16 value
value = fuse_alloc(fuse, FUSE_MAGIC_U16, (void *)0xFFFF);
fuse_printf(fuse, "u16 value=%q\n", value);
fuse_free(fuse, value);

// Make and free a U32 value
value = fuse_alloc(fuse, FUSE_MAGIC_U32, (void *)0xFFFFFFFF);
fuse_printf(fuse, "u32 value=%q\n", value);
fuse_free(fuse, value);

// Make and free a U64 value
value = fuse_alloc(fuse, FUSE_MAGIC_U64, (void *)0xFFFFFFFFFFFFFFFF);
fuse_printf(fuse, "u64 value=%q\n", value);
fuse_free(fuse, value);

// Make and free a S8 value
value = fuse_alloc(fuse, FUSE_MAGIC_S8, (void *)0x7F);
fuse_printf(fuse, "s8 value=%v\n", value);
fuse_free(fuse, value);

// Make and free a S16 value
value = fuse_alloc(fuse, FUSE_MAGIC_S16, (void *)0x7FFF);
fuse_printf(fuse, "s16 value=%q\n", value);
fuse_free(fuse, value);

// Make a list
fuse_value_t *list = fuse_alloc(fuse, FUSE_MAGIC_LIST, 0);
fuse_printf(fuse, "list value=%q\n", value);

// Free the list
fuse_free(fuse, list);

return 0;
}
20 changes: 20 additions & 0 deletions examples/picofuse/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

##############################################################################

set(NAME "gpio_in")

add_executable(${NAME}
common/main.c
gpio_in/run.c
)
target_include_directories(${NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/../../include
)
target_link_libraries(${NAME} picofuse)

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

# create map/bin/hex/uf2 file etc.
pico_add_extra_outputs(${NAME})
17 changes: 17 additions & 0 deletions examples/picofuse/blink/run.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <picofuse/picofuse.h>

#define LED_DELAY_MS 250

int run(fuse_t* fuse) {
fuse_led_new();

while (true) {
fuse_led_set(1);
sleep_ms(LED_DELAY_MS);
fuse_led_set(0);
sleep_ms(LED_DELAY_MS);
}

fuse_led_destroy();
return 0;
}
13 changes: 13 additions & 0 deletions examples/picofuse/common/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <fuse/fuse.h>

int run(fuse_t *fuse);

int main()
{
fuse_t *fuse = fuse_new();
assert(fuse);
fuse_run(fuse, run);

// Destroy the applicatiom, return exit code
return fuse_destroy(fuse);
}
10 changes: 10 additions & 0 deletions examples/picofuse/gpio_in/run.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <picofuse/picofuse.h>

int run(fuse_t *fuse)
{
// GPIO Pin 26 input
fuse_gpio_t *pin = fuse_new_gpio(fuse, 26, FUSE_GPIO_IN);
assert(pin);

return 0;
}
22 changes: 22 additions & 0 deletions examples/picofuse/mqtt/run.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <picofuse/picofuse.h>

int run(fuse_t *fuse)
{
// Register the wifi module for DE country code and station mode,
// scanning for WiFi networks
fuse_wifi_userdata_t wifi_params = {
.country_code = "DE",
.mode = FUSE_WIFI_STATION | FUSE_WIFI_SCAN};
fuse_context_t *wifi = fuse_register(fuse, &fuse_wifi, &wifi_params);
assert(wifi);

// Register MQTT module to connect to 192.168.86.12
fuse_mqtt_userdata_t mqtt_params = {
.host = "192.168.86.12",
.port = 1883};
fuse_context_t *mqtt = fuse_register(fuse, &fuse_mqtt, &mqtt_params);
assert(mqtt);

// Run fuse
return 0; //fuse_runloop(fuse);
}
7 changes: 7 additions & 0 deletions examples/picofuse/panic/run.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <picofuse/picofuse.h>

int run(fuse_t *fuse)
{
fuse_panic("This is a really bad thing that happened!", __FILE__, __LINE__);
return 0;
}
Loading

0 comments on commit f57b44f

Please sign in to comment.