瀏覽代碼

update examples

Tobias Müller 1 年之前
父節點
當前提交
7473386cde
共有 8 個文件被更改,包括 106 次插入10 次删除
  1. 0 4
      .vscode/settings.json
  2. 6 2
      CMakeLists.txt
  3. 2 1
      README.md
  4. 1 0
      inc/header.h
  5. 24 0
      libs/foo/CMakeLists.txt
  6. 39 0
      libs/foo/inc/foo.h
  7. 28 0
      libs/foo/src/foo.cpp
  8. 6 3
      src/main.c

+ 0 - 4
.vscode/settings.json

@@ -31,8 +31,4 @@
     "C_Cpp.default.cppStandard": "gnu++17",
     "C_Cpp.default.cStandard": "gnu11",
     "cortex-debug.openocdPath": "${workspaceFolder}/../openocd/src/openocd",
-    "files.associations": {
-        "*.c": "c",
-        "blink.h": "c"
-    }
 }

+ 6 - 2
CMakeLists.txt

@@ -13,20 +13,24 @@ set(CMAKE_CXX_STANDARD 17)
 pico_sdk_init()
 
 # Tell CMake where to find the executable source file
-add_executable(${PROJECT_NAME} 
-    src/main.c
+add_executable(${PROJECT_NAME}
+    src/main.cpp
 )
 
 # Create map/bin/hex/uf2 files
 pico_add_extra_outputs(${PROJECT_NAME})
 
+add_subdirectory(libs/foo)
 target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/inc)
 
+
 # Link to pico_stdlib (gpio, time, etc. functions)
 target_link_libraries(${PROJECT_NAME} 
     pico_stdlib
+    foo
 )
 
+
 # Enable usb output, disable uart output
 pico_enable_stdio_usb(${PROJECT_NAME} 0)
 pico_enable_stdio_uart(${PROJECT_NAME} 1)

文件差異過大導致無法顯示
+ 2 - 1
README.md


+ 1 - 0
inc/header.h

@@ -12,6 +12,7 @@ Main header file.
 //////////////////////////////               Libraries                //////////////////////////////
 #include <stdio.h>
 #include "pico/stdlib.h"
+#include "foo.h"
 
 //////////////////////////////                Symbols                //////////////////////////////
 #ifndef SLEEP_TIME_MS

+ 24 - 0
libs/foo/CMakeLists.txt

@@ -0,0 +1,24 @@
+# Set minimum required version of CMake
+cmake_minimum_required(VERSION 3.12)
+
+# Include build functions from Pico SDK
+include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
+
+# Creates a pico-sdk subdirectory in our project for the libraries
+pico_sdk_init()
+
+# Set name of project (as PROJECT_NAME) and C/C   standards
+project(foo C CXX ASM)
+set(CMAKE_C_STANDARD 11)
+set(CMAKE_CXX_STANDARD 17)
+
+add_library(${PROJECT_NAME}
+    inc/foo.h
+    src/foo.cpp
+)
+
+target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc)
+
+target_link_libraries(${PROJECT_NAME} 
+    pico_stdlib
+)

+ 39 - 0
libs/foo/inc/foo.h

@@ -0,0 +1,39 @@
+/*
+Author:     Tobias Müller
+Date:       30.06.2023
+Version:    1.0
+
+Main header file.
+*/
+
+#ifndef FOO_H
+#define FOO_H
+
+//////////////////////////////               Libraries                //////////////////////////////
+#include <stdio.h>
+#include "pico/stdlib.h"
+
+//////////////////////////////                Symbols                //////////////////////////////
+
+//////////////////////////////                 Class                 //////////////////////////////
+
+class foo {
+
+    public:
+
+    //////////////////////////              Attributes               //////////////////////////
+
+
+    //////////////////////////               Constructor             //////////////////////////
+    foo();
+
+    //////////////////////////              Deconstructor            //////////////////////////
+    ~foo();
+
+    //////////////////////////                Methods                //////////////////////////
+
+    void bar(void);
+    
+};
+
+#endif

+ 28 - 0
libs/foo/src/foo.cpp

@@ -0,0 +1,28 @@
+/*
+Author:     Tobias Müller
+Date:       30.06.2023
+Version:    1.0
+
+Main file.
+*/
+
+//////////////////////////////               Libraries               //////////////////////////////
+#include "foo.h"
+
+//////////////////////////////            Global Variable            //////////////////////////////
+
+
+//////////////////////////////             Constructor               //////////////////////////////
+foo::foo(void) {
+    return;
+}
+
+//////////////////////////////            Deconstructor              //////////////////////////////
+foo::~foo(void) {
+    return;
+}
+
+//////////////////////////////               Methods                 //////////////////////////////
+void foo::bar(void) {
+    printf("class foo, method bar\n");
+}

+ 6 - 3
src/main.c

@@ -10,7 +10,7 @@ Main file.
 #include "header.h"
 
 //////////////////////////////            Global Variable            //////////////////////////////
-
+foo baz = foo();
 
 //////////////////////////////                 Main                  //////////////////////////////
 int main(void) {
@@ -30,11 +30,14 @@ int main(void) {
     // test function
     bar();
 
+    // test class (lib)
+    baz.bar();
+
     // Loop for i-times
     for(iter = 10; iter > 0; iter--) {
 
         // Blink LED
-        printf("Blinking %i-times!\r\n", iter);
+        printf("Blinking %i-times!\n", iter);
         gpio_put(PICO_DEFAULT_LED_PIN, true);
         sleep_ms(SLEEP_TIME_MS);
         gpio_put(PICO_DEFAULT_LED_PIN, false);
@@ -46,5 +49,5 @@ int main(void) {
 void bar(void) {
 
      //////////////////////////                 Code                  //////////////////////////
-    printf("Function bar");
+    printf("Function bar\n");
 }