mirror of
https://github.com/mytechnotalent/Embedded-Hacking.git
synced 2026-07-09 05:57:48 +02:00
Added constants
This commit is contained in:
@@ -1,5 +1,2 @@
|
|||||||
.idea
|
|
||||||
_deps
|
|
||||||
cmake-*
|
|
||||||
build
|
build
|
||||||
.DS_Store
|
!.vscode/*
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
[]
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
[]
|
|
||||||
+20
-16
@@ -1,18 +1,22 @@
|
|||||||
{
|
{
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "Pico",
|
"name": "Pico",
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**",
|
"${workspaceFolder}/**",
|
||||||
"${env:PICO_SDK_PATH}/**"
|
"${userHome}/.pico-sdk/sdk/2.2.0/**"
|
||||||
],
|
],
|
||||||
"defines": [],
|
"forcedInclude": [
|
||||||
"compilerPath": "${env:PICO_INSTALL_PATH}/gcc-arm-none-eabi/bin/arm-none-eabi-gcc.exe",
|
"${workspaceFolder}/build/generated/pico_base/pico/config_autogen.h",
|
||||||
"cStandard": "c11",
|
"${userHome}/.pico-sdk/sdk/2.2.0/src/common/pico_base_headers/include/pico.h"
|
||||||
"cppStandard": "c++11",
|
],
|
||||||
"intelliSenseMode": "linux-gcc-arm",
|
"defines": [],
|
||||||
"configurationProvider": "ms-vscode.cmake-tools"
|
"compilerPath": "${userHome}/.pico-sdk/toolchain/14_2_Rel1/bin/arm-none-eabi-gcc.exe",
|
||||||
}
|
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
|
||||||
],
|
"cStandard": "c17",
|
||||||
"version": 4
|
"cppStandard": "c++14",
|
||||||
|
"intelliSenseMode": "linux-gcc-arm"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
}
|
}
|
||||||
|
|||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "Pico",
|
||||||
|
"compilers": {
|
||||||
|
"C": "${command:raspberry-pi-pico.getCompilerPath}",
|
||||||
|
"CXX": "${command:raspberry-pi-pico.getCxxCompilerPath}"
|
||||||
|
},
|
||||||
|
"environmentVariables": {
|
||||||
|
"PATH": "${command:raspberry-pi-pico.getEnvPath};${env:PATH}"
|
||||||
|
},
|
||||||
|
"cmakeSettings": {
|
||||||
|
"Python3_EXECUTABLE": "${command:raspberry-pi-pico.getPythonPath}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
+8
-8
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
"marus25.cortex-debug",
|
"marus25.cortex-debug",
|
||||||
"ms-vscode.cmake-tools",
|
"ms-vscode.cpptools",
|
||||||
"ms-vscode.cpptools",
|
"ms-vscode.cpptools-extension-pack",
|
||||||
"ms-vscode.cpptools-extension-pack",
|
"ms-vscode.vscode-serial-monitor",
|
||||||
"ms-vscode.vscode-serial-monitor"
|
"raspberry-pi.raspberry-pi-pico"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Vendored
+48
-56
@@ -1,58 +1,50 @@
|
|||||||
{
|
{
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "Pico Debug (Cortex-Debug)",
|
"name": "Pico Debug (Cortex-Debug)",
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${userHome}/.pico-sdk/openocd/0.12.0+dev/scripts",
|
||||||
"executable": "${command:cmake.launchTargetPath}",
|
"executable": "${command:raspberry-pi-pico.launchTargetPath}",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "cortex-debug",
|
"type": "cortex-debug",
|
||||||
"servertype": "openocd",
|
"servertype": "openocd",
|
||||||
"gdbPath": "arm-none-eabi-gdb",
|
"serverpath": "${userHome}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
|
||||||
"device": "RP2040",
|
"gdbPath": "${command:raspberry-pi-pico.getGDBPath}",
|
||||||
"configFiles": [
|
"device": "${command:raspberry-pi-pico.getChipUppercase}",
|
||||||
"interface/cmsis-dap.cfg",
|
"configFiles": [
|
||||||
"target/rp2040.cfg"
|
"interface/cmsis-dap.cfg",
|
||||||
],
|
"target/${command:raspberry-pi-pico.getTarget}.cfg"
|
||||||
"svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",
|
],
|
||||||
"runToEntryPoint": "main",
|
"svdFile": "${userHome}/.pico-sdk/sdk/2.2.0/src/${command:raspberry-pi-pico.getChip}/hardware_regs/${command:raspberry-pi-pico.getChipUppercase}.svd",
|
||||||
"openOCDLaunchCommands": [
|
"runToEntryPoint": "main",
|
||||||
"adapter speed 1000"
|
// 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",
|
||||||
"name": "Pico Debug (Cortex-Debug with external OpenOCD)",
|
"load \"${command:raspberry-pi-pico.launchTargetPath}\""
|
||||||
"cwd": "${workspaceFolder}",
|
],
|
||||||
"executable": "${command:cmake.launchTargetPath}",
|
"openOCDLaunchCommands": [
|
||||||
"request": "launch",
|
"adapter speed 5000"
|
||||||
"type": "cortex-debug",
|
]
|
||||||
"servertype": "external",
|
},
|
||||||
"gdbTarget": "localhost:3333",
|
{
|
||||||
"gdbPath": "arm-none-eabi-gdb",
|
"name": "Pico Debug (Cortex-Debug with external OpenOCD)",
|
||||||
"device": "RP2040",
|
"cwd": "${workspaceRoot}",
|
||||||
"svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",
|
"executable": "${command:raspberry-pi-pico.launchTargetPath}",
|
||||||
"runToEntryPoint": "main"
|
"request": "launch",
|
||||||
},
|
"type": "cortex-debug",
|
||||||
{
|
"servertype": "external",
|
||||||
"name": "Pico Debug (C++ Debugger)",
|
"gdbTarget": "localhost:3333",
|
||||||
"type": "cppdbg",
|
"gdbPath": "${command:raspberry-pi-pico.getGDBPath}",
|
||||||
"request": "launch",
|
"device": "${command:raspberry-pi-pico.getChipUppercase}",
|
||||||
"cwd": "${workspaceFolder}",
|
"svdFile": "${userHome}/.pico-sdk/sdk/2.2.0/src/${command:raspberry-pi-pico.getChip}/hardware_regs/${command:raspberry-pi-pico.getChipUppercase}.svd",
|
||||||
"program": "${command:cmake.launchTargetPath}",
|
"runToEntryPoint": "main",
|
||||||
"MIMode": "gdb",
|
// Fix for no_flash binaries, where monitor reset halt doesn't do what is expected
|
||||||
"miDebuggerPath": "arm-none-eabi-gdb",
|
// Also works fine for flash binaries
|
||||||
"miDebuggerServerAddress": "localhost:3333",
|
"overrideLaunchCommands": [
|
||||||
"debugServerPath": "openocd",
|
"monitor reset init",
|
||||||
"debugServerArgs": "-f interface/cmsis-dap.cfg -f target/rp2040.cfg -c \"adapter speed 1000\"",
|
"load \"${command:raspberry-pi-pico.launchTargetPath}\""
|
||||||
"serverStarted": "Listening on port .* for gdb connections",
|
]
|
||||||
"filterStderr": true,
|
},
|
||||||
"stopAtEntry": true,
|
]
|
||||||
"hardwareBreakpoints": {
|
|
||||||
"require": true,
|
|
||||||
"limit": 4
|
|
||||||
},
|
|
||||||
"preLaunchTask": "Flash",
|
|
||||||
"svdPath": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-19
@@ -1,29 +1,42 @@
|
|||||||
{
|
{
|
||||||
// These settings tweaks to the cmake plugin will ensure
|
"cmake.showSystemKits": false,
|
||||||
// that you debug using cortex-debug instead of trying to launch
|
"cmake.options.statusBarVisibility": "hidden",
|
||||||
// a Pico binary on the host
|
"cmake.options.advanced": {
|
||||||
"cmake.statusbar.advanced": {
|
"build": {
|
||||||
"debug": {
|
"statusBarVisibility": "hidden"
|
||||||
"visibility": "hidden"
|
|
||||||
},
|
},
|
||||||
"launch": {
|
"launch": {
|
||||||
"visibility": "hidden"
|
"statusBarVisibility": "hidden"
|
||||||
},
|
},
|
||||||
"build": {
|
"debug": {
|
||||||
"visibility": "hidden"
|
"statusBarVisibility": "hidden"
|
||||||
},
|
|
||||||
"buildTarget": {
|
|
||||||
"visibility": "hidden"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cmake.buildBeforeRun": true,
|
"cmake.configureOnEdit": false,
|
||||||
"cmake.configureOnOpen": true,
|
"cmake.automaticReconfigure": false,
|
||||||
"cmake.configureSettings": {
|
"cmake.configureOnOpen": false,
|
||||||
"CMAKE_MODULE_PATH": "${env:PICO_INSTALL_PATH}/pico-sdk-tools"
|
|
||||||
},
|
|
||||||
"cmake.generator": "Ninja",
|
"cmake.generator": "Ninja",
|
||||||
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
|
"cmake.cmakePath": "${userHome}/.pico-sdk/cmake/v3.31.5/bin/cmake",
|
||||||
"C_Cpp.errorSquiggles": "enabled",
|
"C_Cpp.debugShortcut": false,
|
||||||
|
"terminal.integrated.env.windows": {
|
||||||
|
"PICO_SDK_PATH": "${env:USERPROFILE}/.pico-sdk/sdk/2.2.0",
|
||||||
|
"PICO_TOOLCHAIN_PATH": "${env:USERPROFILE}/.pico-sdk/toolchain/14_2_Rel1",
|
||||||
|
"Path": "${env:USERPROFILE}/.pico-sdk/toolchain/14_2_Rel1/bin;${env:USERPROFILE}/.pico-sdk/picotool/2.2.0-a4/picotool;${env:USERPROFILE}/.pico-sdk/cmake/v3.31.5/bin;${env:USERPROFILE}/.pico-sdk/ninja/v1.12.1;${env:PATH}"
|
||||||
|
},
|
||||||
|
"terminal.integrated.env.osx": {
|
||||||
|
"PICO_SDK_PATH": "${env:HOME}/.pico-sdk/sdk/2.2.0",
|
||||||
|
"PICO_TOOLCHAIN_PATH": "${env:HOME}/.pico-sdk/toolchain/14_2_Rel1",
|
||||||
|
"PATH": "${env:HOME}/.pico-sdk/toolchain/14_2_Rel1/bin:${env:HOME}/.pico-sdk/picotool/2.2.0-a4/picotool:${env:HOME}/.pico-sdk/cmake/v3.31.5/bin:${env:HOME}/.pico-sdk/ninja/v1.12.1:${env:PATH}"
|
||||||
|
},
|
||||||
|
"terminal.integrated.env.linux": {
|
||||||
|
"PICO_SDK_PATH": "${env:HOME}/.pico-sdk/sdk/2.2.0",
|
||||||
|
"PICO_TOOLCHAIN_PATH": "${env:HOME}/.pico-sdk/toolchain/14_2_Rel1",
|
||||||
|
"PATH": "${env:HOME}/.pico-sdk/toolchain/14_2_Rel1/bin:${env:HOME}/.pico-sdk/picotool/2.2.0-a4/picotool:${env:HOME}/.pico-sdk/cmake/v3.31.5/bin:${env:HOME}/.pico-sdk/ninja/v1.12.1:${env:PATH}"
|
||||||
|
},
|
||||||
|
"raspberry-pi-pico.cmakeAutoConfigure": true,
|
||||||
|
"raspberry-pi-pico.useCmakeTools": false,
|
||||||
|
"raspberry-pi-pico.cmakePath": "${HOME}/.pico-sdk/cmake/v3.31.5/bin/cmake",
|
||||||
|
"raspberry-pi-pico.ninjaPath": "${HOME}/.pico-sdk/ninja/v1.12.1/ninja",
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"stdlib.h": "c"
|
"stdlib.h": "c"
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+100
-27
@@ -1,29 +1,102 @@
|
|||||||
{
|
{
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
{
|
||||||
"label": "Flash",
|
"label": "Compile Project",
|
||||||
"type": "shell",
|
"type": "process",
|
||||||
"command": "openocd",
|
"isBuildCommand": true,
|
||||||
"args": [
|
"command": "${userHome}/.pico-sdk/ninja/v1.12.1/ninja",
|
||||||
"-f",
|
"args": ["-C", "${workspaceFolder}/build"],
|
||||||
"interface/cmsis-dap.cfg",
|
"group": "build",
|
||||||
"-f",
|
"presentation": {
|
||||||
"target/rp2040.cfg",
|
"reveal": "always",
|
||||||
"-c",
|
"panel": "dedicated"
|
||||||
"adapter speed 1000; program {${command:cmake.launchTargetPath}} verify reset exit"
|
},
|
||||||
],
|
"problemMatcher": "$gcc",
|
||||||
"problemMatcher": []
|
"windows": {
|
||||||
},
|
"command": "${env:USERPROFILE}/.pico-sdk/ninja/v1.12.1/ninja.exe"
|
||||||
{
|
}
|
||||||
"label": "Build",
|
},
|
||||||
"type": "cmake",
|
{
|
||||||
"command": "build",
|
"label": "Run Project",
|
||||||
"problemMatcher": "$gcc",
|
"type": "process",
|
||||||
"group": {
|
"command": "${env:HOME}/.pico-sdk/picotool/2.2.0-a4/picotool/picotool",
|
||||||
"kind": "build",
|
"args": [
|
||||||
"isDefault": true
|
"load",
|
||||||
}
|
"${command:raspberry-pi-pico.launchTargetPath}",
|
||||||
}
|
"-fx"
|
||||||
]
|
],
|
||||||
|
"presentation": {
|
||||||
|
"reveal": "always",
|
||||||
|
"panel": "dedicated"
|
||||||
|
},
|
||||||
|
"problemMatcher": [],
|
||||||
|
"windows": {
|
||||||
|
"command": "${env:USERPROFILE}/.pico-sdk/picotool/2.2.0-a4/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",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Rescue Reset",
|
||||||
|
"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.getChip}-rescue.cfg",
|
||||||
|
"-c",
|
||||||
|
"adapter speed 5000; reset halt; exit"
|
||||||
|
],
|
||||||
|
"problemMatcher": [],
|
||||||
|
"windows": {
|
||||||
|
"command": "${env:USERPROFILE}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "RISC-V Reset (RP2350)",
|
||||||
|
"type": "process",
|
||||||
|
"command": "${userHome}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
|
||||||
|
"args": [
|
||||||
|
"-s",
|
||||||
|
"${userHome}/.pico-sdk/openocd/0.12.0+dev/scripts",
|
||||||
|
"-c",
|
||||||
|
"set USE_CORE { rv0 rv1 cm0 cm1 }",
|
||||||
|
"-f",
|
||||||
|
"interface/cmsis-dap.cfg",
|
||||||
|
"-f",
|
||||||
|
"target/rp2350.cfg",
|
||||||
|
"-c",
|
||||||
|
"adapter speed 5000; init;",
|
||||||
|
"-c",
|
||||||
|
"write_memory 0x40120158 8 { 0x3 }; echo [format \"Info : ARCHSEL 0x%02x\" [read_memory 0x40120158 8 1]];",
|
||||||
|
"-c",
|
||||||
|
"reset halt; targets rp2350.rv0; echo [format \"Info : ARCHSEL_STATUS 0x%02x\" [read_memory 0x4012015C 8 1]]; exit"
|
||||||
|
],
|
||||||
|
"problemMatcher": [],
|
||||||
|
"windows": {
|
||||||
|
"command": "${env:USERPROFILE}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "pico/stdlib.h"
|
||||||
|
#include "hardware/i2c.h"
|
||||||
|
#include "lcd_1602.h"
|
||||||
|
|
||||||
|
#define FAV_NUM 42
|
||||||
|
|
||||||
|
#define I2C_PORT i2c1
|
||||||
|
#define I2C_SDA_PIN 2
|
||||||
|
#define I2C_SCL_PIN 3
|
||||||
|
|
||||||
|
const int OTHER_FAV_NUM = 1337;
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
stdio_init_all();
|
||||||
|
|
||||||
|
i2c_init(I2C_PORT, 100000);
|
||||||
|
gpio_set_function(I2C_SDA_PIN, GPIO_FUNC_I2C);
|
||||||
|
gpio_set_function(I2C_SCL_PIN, GPIO_FUNC_I2C);
|
||||||
|
gpio_pull_up(I2C_SDA_PIN);
|
||||||
|
gpio_pull_up(I2C_SCL_PIN);
|
||||||
|
|
||||||
|
lcd_i2c_init(I2C_PORT, 0x27, 4, 0x08);
|
||||||
|
|
||||||
|
lcd_set_cursor(0, 0);
|
||||||
|
lcd_puts("Reverse");
|
||||||
|
lcd_set_cursor(1, 0);
|
||||||
|
lcd_puts("Engineering");
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
printf("FAV_NUM: %d\r\n", FAV_NUM);
|
||||||
|
printf("OTHER_FAV_NUM: %d\r\n", OTHER_FAV_NUM);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +1,59 @@
|
|||||||
|
# Generated Cmake Pico project file
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.13)
|
cmake_minimum_required(VERSION 3.13)
|
||||||
|
|
||||||
include(pico_sdk_import.cmake)
|
|
||||||
project(0x0017_constant C CXX ASM)
|
|
||||||
set(CMAKE_C_STANDARD 11)
|
set(CMAKE_C_STANDARD 11)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
|
# Initialise pico_sdk from installed location
|
||||||
|
# (note this can come from environment, CMake cache etc)
|
||||||
|
|
||||||
|
# == 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.2.0)
|
||||||
|
set(toolchainVersion 14_2_Rel1)
|
||||||
|
set(picotoolVersion 2.2.0-a4)
|
||||||
|
set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake)
|
||||||
|
if (EXISTS ${picoVscode})
|
||||||
|
include(${picoVscode})
|
||||||
|
endif()
|
||||||
|
# ====================================================================================
|
||||||
|
set(PICO_BOARD pico2 CACHE STRING "Board type")
|
||||||
|
|
||||||
|
# Pull in Raspberry Pi Pico SDK (must be before project)
|
||||||
|
include(pico_sdk_import.cmake)
|
||||||
|
|
||||||
|
project(0x0017_constants C CXX ASM)
|
||||||
|
|
||||||
|
# Initialise the Raspberry Pi Pico SDK
|
||||||
pico_sdk_init()
|
pico_sdk_init()
|
||||||
|
|
||||||
add_executable(0x0017_constant
|
# Add executable. Default name is the project name, version 0.1
|
||||||
main.c
|
|
||||||
)
|
|
||||||
|
|
||||||
pico_enable_stdio_usb(0x0017_constant 1)
|
add_executable(0x0017_constants 0x0017_constants.c lcd_1602.c)
|
||||||
pico_enable_stdio_uart(0x0017_constant 1)
|
|
||||||
|
|
||||||
pico_add_extra_outputs(0x0017_constant)
|
pico_set_program_name(0x0017_constants "0x0017_constants")
|
||||||
|
pico_set_program_version(0x0017_constants "0.1")
|
||||||
|
|
||||||
target_link_libraries(0x0017_constant
|
# Modify the below lines to enable/disable output over UART/USB
|
||||||
|
pico_enable_stdio_uart(0x0017_constants 1)
|
||||||
|
pico_enable_stdio_usb(0x0017_constants 0)
|
||||||
|
|
||||||
|
# Add the standard library to the build
|
||||||
|
target_link_libraries(0x0017_constants
|
||||||
pico_stdlib
|
pico_stdlib
|
||||||
|
hardware_i2c
|
||||||
|
hardware_gpio)
|
||||||
|
|
||||||
|
# Add the standard include files to the build
|
||||||
|
target_include_directories(0x0017_constants PRIVATE
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
pico_add_extra_outputs(0x0017_constants)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
/**
|
||||||
|
* @file lcd_1602.c
|
||||||
|
* @brief Implementation of PCF8574-backed HD44780 (16x2) LCD driver
|
||||||
|
* @author Kevin Thomas
|
||||||
|
* @date 2025
|
||||||
|
*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 Kevin Thomas
|
||||||
|
*
|
||||||
|
* 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:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "lcd_1602.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
static i2c_inst_t *lcd_i2c = NULL;
|
||||||
|
static uint8_t lcd_addr = 0x27;
|
||||||
|
static int lcd_nibble_shift = 4;
|
||||||
|
static uint8_t lcd_backlight_mask = 0x08;
|
||||||
|
|
||||||
|
/* PCF8574 -> LCD control pins */
|
||||||
|
#define PIN_RS 0x01
|
||||||
|
#define PIN_RW 0x02
|
||||||
|
#define PIN_EN 0x04
|
||||||
|
|
||||||
|
static void pcf_write_byte(uint8_t data) {
|
||||||
|
if (!lcd_i2c) return;
|
||||||
|
i2c_write_blocking(lcd_i2c, lcd_addr, &data, 1, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pcf_pulse_enable(uint8_t data) {
|
||||||
|
pcf_write_byte(data | PIN_EN);
|
||||||
|
sleep_us(1);
|
||||||
|
pcf_write_byte(data & ~PIN_EN);
|
||||||
|
sleep_us(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void lcd_write4(uint8_t nibble, uint8_t mode) {
|
||||||
|
uint8_t data = (nibble & 0x0F) << lcd_nibble_shift;
|
||||||
|
data |= mode ? PIN_RS : 0;
|
||||||
|
data |= lcd_backlight_mask;
|
||||||
|
pcf_pulse_enable(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void lcd_send(uint8_t value, uint8_t mode) {
|
||||||
|
lcd_write4((value >> 4) & 0x0F, mode);
|
||||||
|
lcd_write4(value & 0x0F, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lcd_i2c_init(i2c_inst_t *i2c, uint8_t pcf_addr, int nibble_shift, uint8_t backlight_mask) {
|
||||||
|
lcd_i2c = i2c;
|
||||||
|
lcd_addr = pcf_addr;
|
||||||
|
lcd_nibble_shift = nibble_shift;
|
||||||
|
lcd_backlight_mask = backlight_mask;
|
||||||
|
|
||||||
|
// Follow init sequence for HD44780 in 4-bit mode
|
||||||
|
lcd_write4(0x03, 0);
|
||||||
|
sleep_ms(5);
|
||||||
|
lcd_write4(0x03, 0);
|
||||||
|
sleep_us(150);
|
||||||
|
lcd_write4(0x03, 0);
|
||||||
|
sleep_us(150);
|
||||||
|
lcd_write4(0x02, 0);
|
||||||
|
sleep_us(150);
|
||||||
|
|
||||||
|
// Function set: 4-bit, 2 lines
|
||||||
|
lcd_send(0x28, 0);
|
||||||
|
|
||||||
|
// Display on, cursor off
|
||||||
|
lcd_send(0x0C, 0);
|
||||||
|
|
||||||
|
// Clear
|
||||||
|
lcd_send(0x01, 0);
|
||||||
|
sleep_ms(2);
|
||||||
|
|
||||||
|
// Entry mode set
|
||||||
|
lcd_send(0x06, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lcd_clear(void) {
|
||||||
|
lcd_send(0x01, 0);
|
||||||
|
sleep_ms(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lcd_set_cursor(int line, int position) {
|
||||||
|
const uint8_t row_offsets[] = {0x00, 0x40};
|
||||||
|
|
||||||
|
if (line > 1) line = 1;
|
||||||
|
lcd_send(0x80 | (position + row_offsets[line]), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lcd_puts(const char *s) {
|
||||||
|
while (*s) {
|
||||||
|
lcd_send((uint8_t)*s++, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/**
|
||||||
|
* @file lcd_1602.h
|
||||||
|
* @brief Header for PCF8574-backed HD44780 (16x2) LCD driver
|
||||||
|
* @author Kevin Thomas
|
||||||
|
* @date 2025
|
||||||
|
*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 Kevin Thomas
|
||||||
|
*
|
||||||
|
* 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:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LCD_1602_H
|
||||||
|
#define LCD_1602_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "pico/stdlib.h"
|
||||||
|
#include "hardware/i2c.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialize the LCD driver over I2C
|
||||||
|
*
|
||||||
|
* Configures the internal driver state and performs the HD44780 initialization
|
||||||
|
* sequence. The driver does not configure I2C pins or call i2c_init; that
|
||||||
|
* must be done by the caller prior to calling this function.
|
||||||
|
*
|
||||||
|
* @param i2c Pointer to the I2C instance (e.g. i2c0 or i2c1)
|
||||||
|
* @param pcf_addr PCF8574 I2C address (commonly 0x27 or 0x3F)
|
||||||
|
* @param nibble_shift Bit shift applied to 4-bit nibbles (commonly 4 or 0)
|
||||||
|
* @param backlight_mask PCF8574 bit mask that controls the backlight
|
||||||
|
*/
|
||||||
|
void lcd_i2c_init(i2c_inst_t *i2c, uint8_t pcf_addr, int nibble_shift, uint8_t backlight_mask);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clear the LCD display
|
||||||
|
*
|
||||||
|
* Clears the display and returns the cursor to the home position. This
|
||||||
|
* call blocks for the duration required by the HD44780 controller.
|
||||||
|
*/
|
||||||
|
void lcd_clear(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the cursor position
|
||||||
|
*
|
||||||
|
* @param line Line number (0 or 1)
|
||||||
|
* @param position Column (0..15)
|
||||||
|
*/
|
||||||
|
void lcd_set_cursor(int line, int position);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Write a null-terminated string to the display
|
||||||
|
*
|
||||||
|
* @param s The string to write (ASCII)
|
||||||
|
*/
|
||||||
|
void lcd_puts(const char *s);
|
||||||
|
|
||||||
|
#endif // LCD_1602_H
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include "pico/stdlib.h"
|
|
||||||
|
|
||||||
#define FAV_NUM 42
|
|
||||||
|
|
||||||
const int OTHER_FAV_NUM = 1337;
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
stdio_init_all();
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
printf("FAV_NUM: %d\r\n", FAV_NUM);
|
|
||||||
printf("regular_fav_num: %d\r\n", OTHER_FAV_NUM);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,28 @@
|
|||||||
# This can be dropped into an external project to help locate this SDK
|
# This can be dropped into an external project to help locate this SDK
|
||||||
# It should be include()ed prior to project()
|
# It should be include()ed prior to project()
|
||||||
|
|
||||||
|
# Copyright 2020 (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
||||||
|
# following conditions are met:
|
||||||
|
#
|
||||||
|
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
||||||
|
# disclaimer.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
|
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
|
||||||
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
|
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
|
||||||
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
|
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
|
||||||
@@ -18,9 +40,20 @@ if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_P
|
|||||||
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
|
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_TAG} AND (NOT PICO_SDK_FETCH_FROM_GIT_TAG))
|
||||||
|
set(PICO_SDK_FETCH_FROM_GIT_TAG $ENV{PICO_SDK_FETCH_FROM_GIT_TAG})
|
||||||
|
message("Using PICO_SDK_FETCH_FROM_GIT_TAG from environment ('${PICO_SDK_FETCH_FROM_GIT_TAG}')")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (PICO_SDK_FETCH_FROM_GIT AND NOT PICO_SDK_FETCH_FROM_GIT_TAG)
|
||||||
|
set(PICO_SDK_FETCH_FROM_GIT_TAG "master")
|
||||||
|
message("Using master as default value for PICO_SDK_FETCH_FROM_GIT_TAG")
|
||||||
|
endif()
|
||||||
|
|
||||||
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
|
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
|
||||||
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
|
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
|
||||||
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
|
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
|
||||||
|
set(PICO_SDK_FETCH_FROM_GIT_TAG "${PICO_SDK_FETCH_FROM_GIT_TAG}" CACHE FILEPATH "release tag for SDK")
|
||||||
|
|
||||||
if (NOT PICO_SDK_PATH)
|
if (NOT PICO_SDK_PATH)
|
||||||
if (PICO_SDK_FETCH_FROM_GIT)
|
if (PICO_SDK_FETCH_FROM_GIT)
|
||||||
@@ -29,25 +62,40 @@ if (NOT PICO_SDK_PATH)
|
|||||||
if (PICO_SDK_FETCH_FROM_GIT_PATH)
|
if (PICO_SDK_FETCH_FROM_GIT_PATH)
|
||||||
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
|
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
|
||||||
endif ()
|
endif ()
|
||||||
# GIT_SUBMODULES_RECURSE was added in 3.17
|
FetchContent_Declare(
|
||||||
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
|
pico_sdk
|
||||||
FetchContent_Declare(
|
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||||
pico_sdk
|
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
|
||||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
)
|
||||||
GIT_TAG master
|
|
||||||
GIT_SUBMODULES_RECURSE FALSE
|
|
||||||
)
|
|
||||||
else ()
|
|
||||||
FetchContent_Declare(
|
|
||||||
pico_sdk
|
|
||||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
|
||||||
GIT_TAG master
|
|
||||||
)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (NOT pico_sdk)
|
if (NOT pico_sdk)
|
||||||
message("Downloading Raspberry Pi Pico SDK")
|
message("Downloading Raspberry Pi Pico SDK")
|
||||||
FetchContent_Populate(pico_sdk)
|
# GIT_SUBMODULES_RECURSE was added in 3.17
|
||||||
|
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
|
||||||
|
FetchContent_Populate(
|
||||||
|
pico_sdk
|
||||||
|
QUIET
|
||||||
|
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||||
|
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
|
||||||
|
GIT_SUBMODULES_RECURSE FALSE
|
||||||
|
|
||||||
|
SOURCE_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-src
|
||||||
|
BINARY_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-build
|
||||||
|
SUBBUILD_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-subbuild
|
||||||
|
)
|
||||||
|
else ()
|
||||||
|
FetchContent_Populate(
|
||||||
|
pico_sdk
|
||||||
|
QUIET
|
||||||
|
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||||
|
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
|
||||||
|
|
||||||
|
SOURCE_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-src
|
||||||
|
BINARY_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-build
|
||||||
|
SUBBUILD_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-subbuild
|
||||||
|
)
|
||||||
|
endif ()
|
||||||
|
|
||||||
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
|
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
|
||||||
endif ()
|
endif ()
|
||||||
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
|
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user