init repository
This commit is contained in:
Executable
+75
@@ -0,0 +1,75 @@
|
||||
#!/bin/bash
|
||||
|
||||
###############################################
|
||||
#
|
||||
# Download and compile `picotool`.
|
||||
# src: https://github.com/raspberrypi/picotool
|
||||
#
|
||||
# The Pico C SDK must be installed before,
|
||||
# see: `install_sdk.bash`.
|
||||
#
|
||||
# ex: ./install_picotool.bash 2.1.0
|
||||
# NOTE: the version passed must match the SDK
|
||||
# version installed
|
||||
#
|
||||
###############################################
|
||||
|
||||
PICOTOOL_VERSION=$1
|
||||
REGEX_VERSION="^[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}$"
|
||||
|
||||
if [[ -z ${INSTALL_PATH} ]]
|
||||
then
|
||||
INSTALL_PATH=${PWD}
|
||||
fi
|
||||
|
||||
usage() {
|
||||
echo "usage:"
|
||||
echo "./install_picotool.bash <version> (ex: ./install_picotool.bash 2.1.0)"
|
||||
}
|
||||
|
||||
if [[ ! "${PICOTOOL_VERSION}" =~ ${REGEX_VERSION} ]]
|
||||
then
|
||||
echo "error: unable to parse the picotool version: '${PICOTOOL_VERSION}'"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -d ${INSTALL_PATH}/sdk/${PICOTOOL_VERSION} ]]
|
||||
then
|
||||
echo "error: SDK ${PICOTOOL_VERSION} must be installed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -d ${INSTALL_PATH}/picotool/${PICOTOOL_VERSION} ]]
|
||||
then
|
||||
echo "install dependencies..."
|
||||
sudo apt install build-essential pkg-config libusb-1.0-0-dev cmake
|
||||
|
||||
echo "installing picotool..."
|
||||
wget https://github.com/raspberrypi/picotool/releases/download/${PICOTOOL_VERSION}/picotool-${PICOTOOL_VERSION}.tar.gz -P ${INSTALL_PATH}
|
||||
if [[ $? != 0 ]]
|
||||
then
|
||||
echo "error: unable to get picotool VERSION: ${PICOTOOL_VERSION}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p ${INSTALL_PATH}/picotool/${PICOTOOL_VERSION}
|
||||
tar xzvf ${INSTALL_PATH}/picotool-${PICOTOOL_VERSION}.tar.gz -C ${INSTALL_PATH}/picotool/${PICOTOOL_VERSION}
|
||||
rm ${INSTALL_PATH}/picotool-${PICOTOOL_VERSION}.tar.gz
|
||||
fi
|
||||
|
||||
echo "building picotool..."
|
||||
mkdir -p ${INSTALL_PATH}/picotool/${PICOTOOL_VERSION}/build
|
||||
PICO_SDK_PATH=${INSTALL_PATH}/sdk/${PICOTOOL_VERSION}
|
||||
|
||||
cd ${INSTALL_PATH}/picotool/${PICOTOOL_VERSION}/build
|
||||
cmake ..
|
||||
make -C ${INSTALL_PATH}/picotool/${PICOTOOL_VERSION}/build
|
||||
|
||||
picotool_version=$(${INSTALL_PATH}/picotool/${PICOTOOL_VERSION}/build/picotool version)
|
||||
echo "${picotool_version} compiled successfully"
|
||||
|
||||
echo "adding udev picotool rules..."
|
||||
sudo cp ${INSTALL_PATH}/picotool/${PICOTOOL_VERSION}/udev/99-picotool.rules /etc/udev/rules.d/
|
||||
|
||||
echo "picotool installation completed"
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
|
||||
###############################################
|
||||
#
|
||||
# Download and install Pico C SDK.
|
||||
# src: https://github.com/raspberrypi/pico-sdk
|
||||
#
|
||||
# ex: ./install_sdk.bash 2.1.0
|
||||
#
|
||||
###############################################
|
||||
|
||||
PICO_SDK_VERSION=$1
|
||||
REGEX_VERSION="^[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}$"
|
||||
|
||||
if [[ -z ${INSTALL_PATH} ]]
|
||||
then
|
||||
INSTALL_PATH=${PWD}
|
||||
fi
|
||||
|
||||
usage() {
|
||||
echo "usage:"
|
||||
echo "./install_sdk.bash <version> (ex: ./install_sdk.bash 2.1.0)"
|
||||
}
|
||||
|
||||
if [[ ! "${PICO_SDK_VERSION}" =~ ${REGEX_VERSION} ]]
|
||||
then
|
||||
echo "error: unable to parse the SDK version: '${PICO_SDK_VERSION}'"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -d ${INSTALL_PATH}/sdk/${PICO_SDK_VERSION} ]]
|
||||
then
|
||||
echo "installing dependencies..."
|
||||
sudo apt install cmake python3 build-essential gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib
|
||||
|
||||
echo "installing Pico C SDK ${PICO_SDK_VERSION}"
|
||||
|
||||
pico_tar_file="pico-sdk-${PICO_SDK_VERSION}.tar.gz"
|
||||
wget https://github.com/raspberrypi/pico-sdk/releases/download/${PICO_SDK_VERSION}/pico-sdk-${PICO_SDK_VERSION}.tar.gz -P ${INSTALL_PATH}
|
||||
if [[ $? != 0 ]]
|
||||
then
|
||||
echo "error: unable to get pico SDK VERSION: ${PICO_SDK_VERSION}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p ${INSTALL_PATH}/sdk/${PICO_SDK_VERSION}
|
||||
tar xzvf ${INSTALL_PATH}/${pico_tar_file} -C ${INSTALL_PATH}/sdk/${PICO_SDK_VERSION}
|
||||
rm ${INSTALL_PATH}/${pico_tar_file}
|
||||
|
||||
echo "Pico C SDK installed successfully: ${INSTALL_PATH}/sdk/${PICO_SDK_VERSION}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Pico C SDK already exists: ${INSTALL_PATH}/sdk/${PICO_SDK_VERSION}"
|
||||
Executable
+82
@@ -0,0 +1,82 @@
|
||||
#!/bin/bash
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# Generate a new project from templates.
|
||||
# It scaffold a project, ready to use, in the current directory with:
|
||||
# * CMakeLists.txt
|
||||
# * main.c
|
||||
#
|
||||
# ./install_sdk.bash <project_name> <sdk_version>
|
||||
# ex: ./install_sdk.bash <project_name> <sdk_version>
|
||||
#
|
||||
# The SDK must be installed before using the script.
|
||||
# If the SDK is located in a different directory than the project
|
||||
# set the `INSTALL_PATH` env var to point to the SDK directory.
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
PROJECT_NAME=$1
|
||||
PICO_SDK_VERSION=$2
|
||||
REGEX_VERSION="^[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}$"
|
||||
|
||||
if [[ -z ${INSTALL_PATH} ]]
|
||||
then
|
||||
INSTALL_PATH=${PWD}
|
||||
fi
|
||||
|
||||
usage() {
|
||||
echo "usage:"
|
||||
echo "./scaffold_project.bash <project_name> <sdk_version> (ex: ./scaffold_project.bash test 2.1.0)"
|
||||
}
|
||||
|
||||
if [[ -z ${PROJECT_NAME} ]]
|
||||
then
|
||||
echo "error: project name must not be empty"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PROJECT_DIR="${PROJECT_NAME}"
|
||||
if [[ -d ${PROJECT_DIR} ]]
|
||||
then
|
||||
echo "error: a project with same name: ${PROJECT_NAME} already exists"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! "${PICO_SDK_VERSION}" =~ ${REGEX_VERSION} ]]
|
||||
then
|
||||
echo "error: unable to parse the SDK version: '${PICO_SDK_VERSION}' (ex: ./install_sdk 2.1.0)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -d ${INSTALL_PATH}/sdk/${PICO_SDK_VERSION} ]]
|
||||
then
|
||||
echo "error: no SDK v${PICO_SDK_VERSION} exists, please make an install first"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PICO_SDK_PATH=${INSTALL_PATH}/sdk/${PICO_SDK_VERSION}
|
||||
|
||||
mkdir -p ${PROJECT_DIR}
|
||||
|
||||
echo "generating templates..."
|
||||
|
||||
# build from the cmake list template
|
||||
cp templates/CMakeLists.txt.tpl templates/CMakeLists.txt.tmp
|
||||
sed -i "s/<project_name>/${PROJECT_NAME}/g" templates/CMakeLists.txt.tmp
|
||||
mv templates/CMakeLists.txt.tmp ${PROJECT_DIR}/CMakeLists.txt
|
||||
|
||||
# move the c src file into the project folder
|
||||
cp templates/main.c.tpl templates/main.c.tmp
|
||||
sed -i "s/<prog_name>/${PROJECT_NAME}/g" templates/main.c.tmp
|
||||
mv templates/main.c.tmp ${PROJECT_DIR}/main.c
|
||||
|
||||
echo "building the project: ${PROJECT_NAME}..."
|
||||
cd ${PROJECT_DIR}
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake ..
|
||||
make -j$(nproc)
|
||||
|
||||
echo "project ${PROJECT_NAME} successfully generated"
|
||||
Reference in New Issue
Block a user