first and compiling freertos
This commit is contained in:
41
docs/examples/ws2812b/RP2040-ETH-WS2812B/C/CMakeLists.txt
Normal file
41
docs/examples/ws2812b/RP2040-ETH-WS2812B/C/CMakeLists.txt
Normal file
@@ -0,0 +1,41 @@
|
||||
# Generated Cmake Pico project file
|
||||
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# initalize pico_sdk from installed location
|
||||
# (note this can come from environment, CMake cache etc)
|
||||
#set(PICO_SDK_PATH "D:/Raspberry/Pico-Code/pico-sdk")
|
||||
|
||||
# Pull in Raspberry Pi Pico SDK (must be before project)
|
||||
include(pico_sdk_import.cmake)
|
||||
|
||||
project(RP2040_WS2812B_Test C CXX ASM)
|
||||
|
||||
# Initialise the Raspberry Pi Pico SDK
|
||||
pico_sdk_init()
|
||||
|
||||
# Add executable. Default name is the project name, version 0.1
|
||||
|
||||
add_executable(RP2040_WS2812B_Test RP2040_WS2812B_Test.c )
|
||||
|
||||
pico_generate_pio_header(RP2040_WS2812B_Test ${CMAKE_CURRENT_LIST_DIR}/ws2812.pio OUTPUT_DIR ${CMAKE_CURRENT_LIST_DIR}/generated)
|
||||
|
||||
pico_set_program_name(RP2040_WS2812B_Test "RP2040_WS2812B_Test")
|
||||
pico_set_program_version(RP2040_WS2812B_Test "0.1")
|
||||
|
||||
pico_enable_stdio_uart(RP2040_WS2812B_Test 0)
|
||||
pico_enable_stdio_usb(RP2040_WS2812B_Test 0)
|
||||
|
||||
# Add the standard library to the build
|
||||
target_link_libraries(RP2040_WS2812B_Test pico_stdlib)
|
||||
|
||||
# Add any user requested libraries
|
||||
target_link_libraries(RP2040_WS2812B_Test
|
||||
hardware_pio
|
||||
)
|
||||
|
||||
pico_add_extra_outputs(RP2040_WS2812B_Test)
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/pio.h"
|
||||
#include "hardware/clocks.h"
|
||||
#include "ws2812.pio.h"
|
||||
|
||||
void put_pixel(uint32_t pixel_grb)
|
||||
{
|
||||
pio_sm_put_blocking(pio0, 0, pixel_grb << 8u);
|
||||
}
|
||||
void put_rgb(uint8_t red, uint8_t green, uint8_t blue)
|
||||
{
|
||||
uint32_t mask = (green << 16) | (red << 8) | (blue << 0);
|
||||
put_pixel(mask);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
//set_sys_clock_48();
|
||||
stdio_init_all();
|
||||
|
||||
PIO pio = pio0;
|
||||
int sm = 0;
|
||||
uint offset = pio_add_program(pio, &ws2812_program);
|
||||
uint8_t cnt = 0;
|
||||
|
||||
puts("RP2040-Zero WS2812 Test");
|
||||
|
||||
ws2812_program_init(pio, sm, offset, 25, 800000, true);
|
||||
|
||||
while (1)
|
||||
{
|
||||
for (cnt = 0; cnt < 0xff; cnt++)
|
||||
{
|
||||
put_rgb(cnt, 0xff - cnt, 0);
|
||||
sleep_ms(3);
|
||||
}
|
||||
for (cnt = 0; cnt < 0xff; cnt++)
|
||||
{
|
||||
put_rgb(0xff - cnt, 0, cnt);
|
||||
sleep_ms(3);
|
||||
}
|
||||
for (cnt = 0; cnt < 0xff; cnt++)
|
||||
{
|
||||
put_rgb(0, cnt, 0xff - cnt);
|
||||
sleep_ms(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
34
docs/examples/ws2812b/RP2040-ETH-WS2812B/C/ReadmeCN.txt
Normal file
34
docs/examples/ws2812b/RP2040-ETH-WS2812B/C/ReadmeCN.txt
Normal file
@@ -0,0 +1,34 @@
|
||||
/*****************************************************************************
|
||||
* | File : Readme_CN.txt
|
||||
* | Author :
|
||||
* | Function : Help with use
|
||||
* | Info :
|
||||
*----------------
|
||||
* | This version: V1.0
|
||||
* | Date : 2023-04-23
|
||||
* | Info : 在这里提供一个中文版本的使用文档,以便你的快速使用
|
||||
******************************************************************************/
|
||||
这个文件是帮助您使用本例程。
|
||||
由于我们的LCD越来越多,不便于我们的维护,因此把所有的LCD程序做成一个工程。
|
||||
在这里简略的描述本工程的使用:
|
||||
|
||||
1.基本信息:
|
||||
本例程用于测试或者演示RP2040-ETH上WS2812B;
|
||||
|
||||
2.管脚连接:
|
||||
DIN -> 25
|
||||
|
||||
3.基本使用:
|
||||
你需要执行:
|
||||
如果目录已经存在,则可以直接进入。 如果没有目录,执行:
|
||||
mkdir build
|
||||
进入目录,并添加SDK:
|
||||
cd build
|
||||
export PICO_SDK_PATH=../../pico-sdk
|
||||
其中 ../../pico-sdk 是你的SDK的目录。
|
||||
执行cmake,自动生成Makefile文件:
|
||||
cmake ..
|
||||
执行make生成可执行文件,然后在终端中输入:
|
||||
make
|
||||
编译好的uf2文件复制到pico中即可
|
||||
|
||||
35
docs/examples/ws2812b/RP2040-ETH-WS2812B/C/ReadmeEN.txt
Normal file
35
docs/examples/ws2812b/RP2040-ETH-WS2812B/C/ReadmeEN.txt
Normal file
@@ -0,0 +1,35 @@
|
||||
/*****************************************************************************
|
||||
* | File : Readme_EN.txt
|
||||
* | Author :
|
||||
* | Function : Help with use
|
||||
* | Info :
|
||||
*----------------
|
||||
* | This version: V1.0
|
||||
* | Date : 2021-02-04
|
||||
* | Info : Here is an English version of the documentation for your quick use.
|
||||
******************************************************************************/
|
||||
This file is to help you use this routine.
|
||||
Since our ink screens are getting more and more, it is not convenient for our maintenance, so all the ink screen programs are made into one project.
|
||||
A brief description of the use of this project is here:
|
||||
|
||||
1. Basic information:
|
||||
This routine is used to test or demonstrate WS2812B on RP2040-ETH.
|
||||
|
||||
2. Pin connection:
|
||||
Pin connection You can look at dev_config.c/h in \lib\Config. Again, here:
|
||||
DIN -> 25
|
||||
|
||||
3. Basic use:
|
||||
You need to execute:
|
||||
If the directory already exists, you can go directly. If there is no build directory, execute
|
||||
mkdir build
|
||||
Enter the build directory and type in the terminal:
|
||||
cd build
|
||||
export PICO_SDK_PATH=../../pico-sdk
|
||||
Where ../../pico-sdk is your installed SDK directory
|
||||
Execute cmake, automatically generate Makefile file, enter in the terminal:
|
||||
cmake ..
|
||||
Execute make to generate an executable file, and enter in the terminal:
|
||||
make
|
||||
Copy the compiled uf2 file to pico
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
// -------------------------------------------------- //
|
||||
// This file is autogenerated by pioasm; do not edit! //
|
||||
// -------------------------------------------------- //
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !PICO_NO_HARDWARE
|
||||
#include "hardware/pio.h"
|
||||
#endif
|
||||
|
||||
// ------ //
|
||||
// ws2812 //
|
||||
// ------ //
|
||||
|
||||
#define ws2812_wrap_target 0
|
||||
#define ws2812_wrap 3
|
||||
|
||||
#define ws2812_T1 2
|
||||
#define ws2812_T2 5
|
||||
#define ws2812_T3 3
|
||||
|
||||
static const uint16_t ws2812_program_instructions[] = {
|
||||
// .wrap_target
|
||||
0x6221, // 0: out x, 1 side 0 [2]
|
||||
0x1123, // 1: jmp !x, 3 side 1 [1]
|
||||
0x1400, // 2: jmp 0 side 1 [4]
|
||||
0xa442, // 3: nop side 0 [4]
|
||||
// .wrap
|
||||
};
|
||||
|
||||
#if !PICO_NO_HARDWARE
|
||||
static const struct pio_program ws2812_program = {
|
||||
.instructions = ws2812_program_instructions,
|
||||
.length = 4,
|
||||
.origin = -1,
|
||||
};
|
||||
|
||||
static inline pio_sm_config ws2812_program_get_default_config(uint offset) {
|
||||
pio_sm_config c = pio_get_default_sm_config();
|
||||
sm_config_set_wrap(&c, offset + ws2812_wrap_target, offset + ws2812_wrap);
|
||||
sm_config_set_sideset(&c, 1, false, false);
|
||||
return c;
|
||||
}
|
||||
|
||||
#include "hardware/clocks.h"
|
||||
static inline void ws2812_program_init(PIO pio, uint sm, uint offset, uint pin, float freq, bool rgbw) {
|
||||
pio_gpio_init(pio, pin);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
|
||||
pio_sm_config c = ws2812_program_get_default_config(offset);
|
||||
sm_config_set_sideset_pins(&c, pin);
|
||||
sm_config_set_out_shift(&c, false, true, rgbw ? 32 : 24);
|
||||
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
|
||||
int cycles_per_bit = ws2812_T1 + ws2812_T2 + ws2812_T3;
|
||||
float div = clock_get_hz(clk_sys) / (freq * cycles_per_bit);
|
||||
sm_config_set_clkdiv(&c, div);
|
||||
pio_sm_init(pio, sm, offset, &c);
|
||||
pio_sm_set_enabled(pio, sm, true);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake
|
||||
|
||||
# This can be dropped into an external project to help locate this SDK
|
||||
# It should be include()ed prior to project()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
|
||||
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
|
||||
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
|
||||
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
|
||||
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
|
||||
endif ()
|
||||
|
||||
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_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
|
||||
|
||||
if (NOT PICO_SDK_PATH)
|
||||
if (PICO_SDK_FETCH_FROM_GIT)
|
||||
include(FetchContent)
|
||||
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
|
||||
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}")
|
||||
endif ()
|
||||
FetchContent_Declare(
|
||||
pico_sdk
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG master
|
||||
)
|
||||
if (NOT pico_sdk)
|
||||
message("Downloading Raspberry Pi Pico SDK")
|
||||
FetchContent_Populate(pico_sdk)
|
||||
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
|
||||
endif ()
|
||||
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
|
||||
else ()
|
||||
message(FATAL_ERROR
|
||||
"SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
|
||||
)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
|
||||
if (NOT EXISTS ${PICO_SDK_PATH})
|
||||
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
|
||||
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
|
||||
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
|
||||
|
||||
include(${PICO_SDK_INIT_CMAKE_FILE})
|
||||
Binary file not shown.
48
docs/examples/ws2812b/RP2040-ETH-WS2812B/C/ws2812.pio
Normal file
48
docs/examples/ws2812b/RP2040-ETH-WS2812B/C/ws2812.pio
Normal file
@@ -0,0 +1,48 @@
|
||||
;
|
||||
; Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
;
|
||||
; SPDX-License-Identifier: BSD-3-Clause
|
||||
;
|
||||
|
||||
.program ws2812
|
||||
.side_set 1
|
||||
|
||||
.define public T1 2
|
||||
.define public T2 5
|
||||
.define public T3 3
|
||||
|
||||
.lang_opt python sideset_init = pico.PIO.OUT_HIGH
|
||||
.lang_opt python out_init = pico.PIO.OUT_HIGH
|
||||
.lang_opt python out_shiftdir = 1
|
||||
|
||||
.wrap_target
|
||||
bitloop:
|
||||
out x, 1 side 0 [T3 - 1] ; Side-set still takes place when instruction stalls
|
||||
jmp !x do_zero side 1 [T1 - 1] ; Branch on the bit we shifted out. Positive pulse
|
||||
do_one:
|
||||
jmp bitloop side 1 [T2 - 1] ; Continue driving high, for a long pulse
|
||||
do_zero:
|
||||
nop side 0 [T2 - 1] ; Or drive low, for a short pulse
|
||||
.wrap
|
||||
|
||||
% c-sdk {
|
||||
#include "hardware/clocks.h"
|
||||
|
||||
static inline void ws2812_program_init(PIO pio, uint sm, uint offset, uint pin, float freq, bool rgbw) {
|
||||
|
||||
pio_gpio_init(pio, pin);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
|
||||
|
||||
pio_sm_config c = ws2812_program_get_default_config(offset);
|
||||
sm_config_set_sideset_pins(&c, pin);
|
||||
sm_config_set_out_shift(&c, false, true, rgbw ? 32 : 24);
|
||||
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
|
||||
|
||||
int cycles_per_bit = ws2812_T1 + ws2812_T2 + ws2812_T3;
|
||||
float div = clock_get_hz(clk_sys) / (freq * cycles_per_bit);
|
||||
sm_config_set_clkdiv(&c, div);
|
||||
|
||||
pio_sm_init(pio, sm, offset, &c);
|
||||
pio_sm_set_enabled(pio, sm, true);
|
||||
}
|
||||
%}
|
||||
Reference in New Issue
Block a user