Skip to content

Commit

Permalink
add spi support - untested
Browse files Browse the repository at this point in the history
  • Loading branch information
endail committed Nov 24, 2024
1 parent 43296df commit 1ae2967
Show file tree
Hide file tree
Showing 14 changed files with 814 additions and 73 deletions.
24 changes: 11 additions & 13 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@
{
"name": "Pico",
"includePath": [
"${workspaceFolder}/include/**",
"${env:PICO_TOOLCHAIN_PATH}/lib/gcc/arm-none-eabi/**",
"${env:PICO_SDK_PATH}/**"
"${workspaceFolder}/**",
"${userHome}/.pico-sdk/sdk/2.0.0/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
"forcedInclude": [
"${workspaceFolder}/build/generated/pico_base/pico/config_autogen.h",
"${userHome}/.pico-sdk/sdk/2.0.0/src/common/pico_base_headers/include/pico.h"
],
"windowsSdkVersion": "10.0.22000.0",
"compilerPath": "${env:PICO_TOOLCHAIN_PATH}/bin/arm-none-eabi-gcc.exe",
"cppStandard": "c++11",
"intelliSenseMode": "gcc-arm",
"cStandard": "c11",
"configurationProvider": "ms-vscode.cmake-tools"
"defines": [],
"compilerPath": "${userHome}/.pico-sdk/toolchain/13_3_Rel1/bin/arm-none-eabi-gcc",
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"cStandard": "c17",
"cppStandard": "c++14",
"intelliSenseMode": "linux-gcc-arm"
}
],
"version": 4
Expand Down
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"recommendations": [
"marus25.cortex-debug",
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"ms-vscode.vscode-serial-monitor",
"raspberry-pi.raspberry-pi-pico",
]
}
73 changes: 59 additions & 14 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,69 @@
"version": "0.2.0",
"configurations": [
{
"name": "Debug file->elf",
"cwd": "${workspaceFolder}",
"executable": "${workspaceFolder}${pathSeparator}build${pathSeparator}${relativeFileDirname}${pathSeparator}${fileBasenameNoExtension}.elf",
"name": "Pico Debug (Cortex-Debug)",
"cwd": "${userHome}/.pico-sdk/openocd/0.12.0+dev/scripts",
"executable": "${command:raspberry-pi-pico.launchTargetPath}",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"device": "Pico2040",
"showDevDebugOutput": "both",
// "runToEntryPoint": "main",
"preLaunchTask": "CMake Build",
"serverpath": "${userHome}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
"gdbPath": "${command:raspberry-pi-pico.getGDBPath}",
"device": "${command:raspberry-pi-pico.getChipUppercase}",
"configFiles": [
"interface${pathSeparator}picoprobe.cfg",
"target${pathSeparator}rp2040.cfg"
"interface/cmsis-dap.cfg",
"target/${command:raspberry-pi-pico.getTarget}.cfg"
],
"searchDir": [
"${env:OPENOCD_PATH}${pathSeparator}tcl"
"svdFile": "${userHome}/.pico-sdk/sdk/2.0.0/src/${command:raspberry-pi-pico.getChip}/hardware_regs/${command:raspberry-pi-pico.getChipUppercase}.svd",
"runToEntryPoint": "main",
// Fix for no_flash binaries, where monitor reset halt doesn't do what is expected
// Also works fine for flash binaries
"overrideLaunchCommands": [
"monitor reset init",
"load \"${command:raspberry-pi-pico.launchTargetPath}\""
],
"svdFile": "${env:PICO_SDK_PATH}${pathSeparator}src${pathSeparator}rp2040${pathSeparator}hardware_regs${pathSeparator}rp2040.svd"
}
"openOCDLaunchCommands": [
"adapter speed 5000"
]
},
{
"name": "Pico Debug (Cortex-Debug with external OpenOCD)",
"cwd": "${workspaceRoot}",
"executable": "${command:raspberry-pi-pico.launchTargetPath}",
"request": "launch",
"type": "cortex-debug",
"servertype": "external",
"gdbTarget": "localhost:3333",
"gdbPath": "${command:raspberry-pi-pico.getGDBPath}",
"device": "${command:raspberry-pi-pico.getChipUppercase}",
"svdFile": "${userHome}/.pico-sdk/sdk/2.0.0/src/${command:raspberry-pi-pico.getChip}/hardware_regs/${command:raspberry-pi-pico.getChipUppercase}.svd",
"runToEntryPoint": "main",
// Fix for no_flash binaries, where monitor reset halt doesn't do what is expected
// Also works fine for flash binaries
"overrideLaunchCommands": [
"monitor reset init",
"load \"${command:raspberry-pi-pico.launchTargetPath}\""
]
},
{
"name": "Pico Debug (C++ Debugger)",
"type": "cppdbg",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${command:raspberry-pi-pico.launchTargetPath}",
"MIMode": "gdb",
"miDebuggerPath": "${command:raspberry-pi-pico.getGDBPath}",
"miDebuggerServerAddress": "localhost:3333",
"debugServerPath": "${userHome}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
"debugServerArgs": "-f interface/cmsis-dap.cfg -f target/${command:raspberry-pi-pico.getTarget}.cfg -c \"adapter speed 5000\"",
"serverStarted": "Listening on port .* for gdb connections",
"filterStderr": true,
"hardwareBreakpoints": {
"require": true,
"limit": 4
},
"preLaunchTask": "Flash",
"svdPath": "${userHome}/.pico-sdk/sdk/2.0.0/src/${command:raspberry-pi-pico.getChip}/hardware_regs/${command:raspberry-pi-pico.getChipUppercase}.svd"
},
]
}
}
72 changes: 32 additions & 40 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,39 @@
{
"cmake.statusbar.advanced": {
"debug": {
"visibility": "hidden"
"cmake.options.statusBarVisibility": "hidden",
"cmake.options.advanced": {
"build": {
"statusBarVisibility": "hidden"
},
"launch": {
"visibility": "hidden"
"statusBarVisibility": "hidden"
},
"launchTarget": {
"visibility": "hidden"
"debug": {
"statusBarVisibility": "hidden"
}
},
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"cmake.buildBeforeRun": true,
"cmake.configureOnOpen": true,
"files.associations": {
"stdio.h": "c",
"hx711.h": "c",
"cstdlib": "c",
"stdint.h": "c",
"cstdint": "c",
"time.h": "c",
"_timespec.h": "c",
"_types.h": "c",
"gpio.h": "c",
"hx711_multi.h": "c",
"array": "c",
"deque": "c",
"string": "c",
"unordered_map": "c",
"vector": "c",
"string_view": "c",
"initializer_list": "c",
"util.h": "c",
"random": "c",
"limits": "c",
"cstddef": "c",
"mutex.h": "c",
"platform.h": "c"
"cmake.configureOnEdit": false,
"cmake.automaticReconfigure": false,
"cmake.configureOnOpen": false,
"cmake.generator": "Ninja",
"cmake.cmakePath": "${userHome}/.pico-sdk/cmake/v3.28.6/bin/cmake",
"C_Cpp.debugShortcut": false,
"terminal.integrated.env.windows": {
"PICO_SDK_PATH": "${env:USERPROFILE}/.pico-sdk/sdk/2.0.0",
"PICO_TOOLCHAIN_PATH": "${env:USERPROFILE}/.pico-sdk/toolchain/13_3_Rel1",
"Path": "${env:USERPROFILE}/.pico-sdk/toolchain/13_3_Rel1/bin;${env:USERPROFILE}/.pico-sdk/picotool/2.0.0/picotool;${env:USERPROFILE}/.pico-sdk/cmake/v3.28.6/bin;${env:USERPROFILE}/.pico-sdk/ninja/v1.12.1;${env:PATH}"
},
"terminal.integrated.env.osx": {
"PICO_SDK_PATH": "${env:HOME}/.pico-sdk/sdk/2.0.0",
"PICO_TOOLCHAIN_PATH": "${env:HOME}/.pico-sdk/toolchain/13_3_Rel1",
"PATH": "${env:HOME}/.pico-sdk/toolchain/13_3_Rel1/bin:${env:HOME}/.pico-sdk/picotool/2.0.0/picotool:${env:HOME}/.pico-sdk/cmake/v3.28.6/bin:${env:HOME}/.pico-sdk/ninja/v1.12.1:${env:PATH}"
},
"terminal.integrated.env.linux": {
"PICO_SDK_PATH": "${env:HOME}/.pico-sdk/sdk/2.0.0",
"PICO_TOOLCHAIN_PATH": "${env:HOME}/.pico-sdk/toolchain/13_3_Rel1",
"PATH": "${env:HOME}/.pico-sdk/toolchain/13_3_Rel1/bin:${env:HOME}/.pico-sdk/picotool/2.0.0/picotool:${env:HOME}/.pico-sdk/cmake/v3.28.6/bin:${env:HOME}/.pico-sdk/ninja/v1.12.1:${env:PATH}"
},
"C_Cpp.intelliSenseEngineFallback": "enabled",
"C_Cpp.default.intelliSenseMode": "gcc-arm",
"C_Cpp.default.browse.limitSymbolsToIncludedHeaders": false,
"C_Cpp.default.cppStandard": "",
"C_Cpp.default.cStandard": "c11",
"C_Cpp.default.mergeConfigurations": true
}
"raspberry-pi-pico.cmakeAutoConfigure": true,
"raspberry-pi-pico.useCmakeTools": false,
"raspberry-pi-pico.cmakePath": "${HOME}/.pico-sdk/cmake/v3.28.6/bin/cmake",
"raspberry-pi-pico.ninjaPath": "${HOME}/.pico-sdk/ninja/v1.12.1/ninja"
}
56 changes: 51 additions & 5 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,57 @@
"version": "2.0.0",
"tasks": [
{
"label": "CMake Build",
"command": "${command:cmake.tasksBuildCommand}",
"type": "shell",
"label": "Compile Project",
"type": "process",
"isBuildCommand": true,
"command": "${userHome}/.pico-sdk/ninja/v1.12.1/ninja",
"args": ["-C", "${workspaceFolder}/build"],
"group": "build",
"problemMatcher": []
"presentation": {
"reveal": "always",
"panel": "dedicated"
},
"problemMatcher": "$gcc",
"windows": {
"command": "${env:USERPROFILE}/.pico-sdk/ninja/v1.12.1/ninja.exe"
}
},
{
"label": "Run Project",
"type": "process",
"command": "${env:HOME}/.pico-sdk/picotool/2.0.0/picotool/picotool",
"args": [
"load",
"${command:raspberry-pi-pico.launchTargetPath}",
"-fx"
],
"presentation": {
"reveal": "always",
"panel": "dedicated"
},
"problemMatcher": [],
"windows": {
"command": "${env:USERPROFILE}/.pico-sdk/picotool/2.0.0/picotool/picotool.exe"
}
},
{
"label": "Flash",
"type": "process",
"command": "${userHome}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
"args": [
"-s",
"${userHome}/.pico-sdk/openocd/0.12.0+dev/scripts",
"-f",
"interface/cmsis-dap.cfg",
"-f",
"target/${command:raspberry-pi-pico.getTarget}.cfg",
"-c",
"adapter speed 5000; program \"${command:raspberry-pi-pico.launchTargetPath}\" verify reset exit"
],
"problemMatcher": [],
"windows": {
"command": "${env:USERPROFILE}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
}
}
]
}
}
21 changes: 20 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License
#
# Copyright (c) 2023 Daniel Robertson
# Copyright (c) 2024 Daniel Robertson
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -20,6 +20,22 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work ==
if(WIN32)
set(USERHOME $ENV{USERPROFILE})
else()
set(USERHOME $ENV{HOME})
endif()
set(sdkVersion 2.0.0)
set(toolchainVersion 13_3_Rel1)
set(picotoolVersion 2.0.0)
set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake)
if (EXISTS ${picoVscode})
include(${picoVscode})
endif()
# ====================================================================================
set(PICO_BOARD pico CACHE STRING "Board type")

cmake_minimum_required(VERSION 3.12)

# this must go above project()!
Expand Down Expand Up @@ -73,6 +89,7 @@ target_link_libraries(hx711-pico-c INTERFACE
hardware_gpio
hardware_irq
hardware_pio
hardware_spi
hardware_timer
pico_platform
pico_sync
Expand All @@ -82,6 +99,8 @@ target_link_libraries(hx711-pico-c INTERFACE
target_sources(hx711-pico-c INTERFACE
${CMAKE_CURRENT_LIST_DIR}/src/hx711.c
${CMAKE_CURRENT_LIST_DIR}/src/hx711_multi.c
${CMAKE_CURRENT_LIST_DIR}/src/hx711_spi_master.c
${CMAKE_CURRENT_LIST_DIR}/src/hx711_spi_slave.c
${CMAKE_CURRENT_LIST_DIR}/src/common.c
${CMAKE_CURRENT_LIST_DIR}/src/util.c
)
Expand Down
6 changes: 6 additions & 0 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,22 @@

#include "hx711.h"
#include "hx711_multi.h"
#include "hx711_spi_master.h"
#include "hx711_spi_slave.h"

#ifdef __cplusplus
extern "C" {
#endif

extern const hx711_config_t HX711__DEFAULT_CONFIG;
extern const hx711_multi_config_t HX711__MULTI_DEFAULT_CONFIG;
extern const hx711_spi_master_config_t HX711__SPI_MASTER_DEFAULT_CONFIG;
extern const hx711_spi_slave_config_t HX711__SPI_SLAVE_DEFAULT_CONFIG;

void hx711_get_default_config(hx711_config_t* const cfg);
void hx711_multi_get_default_config(hx711_multi_config_t* const cfg);
void hx711_spi_master_get_default_config(hx711_spi_master_config_t* const cfg);
void hx711_spi_slave_get_default_config(hx711_spi_slave_config_t* const cfg);

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 1ae2967

Please sign in to comment.