init
This commit is contained in:
commit
32f4d1057b
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.vscode
|
57
CMakeLists.txt
Normal file
57
CMakeLists.txt
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# Generated Cmake Pico project file
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.13)
|
||||||
|
|
||||||
|
set(CMAKE_C_STANDARD 11)
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
|
# Initialise pico_sdk from installed location
|
||||||
|
# (note this can come from environment, CMake cache etc)
|
||||||
|
set(PICO_SDK_PATH "/usr/share/pico-sdk")
|
||||||
|
|
||||||
|
set(PICO_BOARD pico_w CACHE STRING "Board type")
|
||||||
|
|
||||||
|
# Pull in Raspberry Pi Pico SDK (must be before project)
|
||||||
|
include(pico_sdk_import.cmake)
|
||||||
|
|
||||||
|
if (PICO_SDK_VERSION_STRING VERSION_LESS "1.4.0")
|
||||||
|
message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.4.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
project(ARGB_emulator 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(ARGB_emulator main.cpp tx_rx.cpp)
|
||||||
|
|
||||||
|
pico_set_program_name(ARGB_emulator "ARGB_emulator")
|
||||||
|
pico_set_program_version(ARGB_emulator "0.1")
|
||||||
|
|
||||||
|
pico_enable_stdio_uart(ARGB_emulator 0)
|
||||||
|
pico_enable_stdio_usb(ARGB_emulator 1)
|
||||||
|
|
||||||
|
pico_generate_pio_header(argb_emulator ${CMAKE_CURRENT_SOURCE_DIR}/argb_tx.pio)
|
||||||
|
|
||||||
|
|
||||||
|
# Add the standard library to the build
|
||||||
|
target_link_libraries(ARGB_emulator
|
||||||
|
pico_stdlib)
|
||||||
|
|
||||||
|
# Add the standard include files to the build
|
||||||
|
target_include_directories(ARGB_emulator PRIVATE
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts or any other standard includes, if required
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add any user requested libraries
|
||||||
|
target_link_libraries(ARGB_emulator
|
||||||
|
hardware_pio
|
||||||
|
hardware_dma
|
||||||
|
pico_cyw43_arch_none
|
||||||
|
)
|
||||||
|
|
||||||
|
pico_add_extra_outputs(ARGB_emulator)
|
||||||
|
|
43
argb_tx.pio
Normal file
43
argb_tx.pio
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
.program argb_tx
|
||||||
|
|
||||||
|
.side_set 1 opt
|
||||||
|
|
||||||
|
.wrap_target
|
||||||
|
pull ; Get data from FIFO
|
||||||
|
mov y, osr ; Store bit count in Y (lower 8 bits)
|
||||||
|
pull ; Get first data word
|
||||||
|
mov x, osr ; Store in X
|
||||||
|
set y, 24 ; Remaining bits in first word (32-8)
|
||||||
|
|
||||||
|
bit_loop:
|
||||||
|
out pins, 1 ; Shift 1 bit to pins (side-set 0)
|
||||||
|
jmp y--, delay ; Decrement Y, handle delay
|
||||||
|
|
||||||
|
pull ; Load new data when Y underflows
|
||||||
|
mov x, osr
|
||||||
|
set y, 31 ; Reset bit counter for new word
|
||||||
|
|
||||||
|
delay:
|
||||||
|
jmp x--, nobit ; Check if current bit is set [1]
|
||||||
|
nop ; [1] Align timing
|
||||||
|
|
||||||
|
; Bit=1 pattern (0.8µs high, 0.45µs low)
|
||||||
|
set pins, 1 [99] ; 1 + 99 = 100 cycles (0.8µs)
|
||||||
|
set pins, 0 [55] ; 1 + 55 = 56 cycles (0.448µs)
|
||||||
|
jmp end_bit
|
||||||
|
|
||||||
|
nobit:
|
||||||
|
; Bit=0 pattern (0.4µs high, 0.85µs low)
|
||||||
|
set pins, 1 [49] ; 50 cycles (0.4µs)
|
||||||
|
set pins, 0 [105] ; 106 cycles (0.848µs)
|
||||||
|
|
||||||
|
end_bit:
|
||||||
|
jmp bit_loop ; Total per bit: 156 cycles (1.248µs)
|
||||||
|
|
||||||
|
post_delay:
|
||||||
|
set pins, 0 ; 70µs low period
|
||||||
|
set y, 8749 ; (70µs / 8ns) - 1 = 8749 cycles
|
||||||
|
delay_loop:
|
||||||
|
jmp y--, delay_loop
|
||||||
|
irq 0 ; Signal completion
|
||||||
|
.wrap
|
21523
compile_commands.json
Normal file
21523
compile_commands.json
Normal file
File diff suppressed because it is too large
Load Diff
7
main.cpp
Normal file
7
main.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "pico/stdio.h"
|
||||||
|
#include "pico/stdlib.h"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
stdio_init_all();
|
||||||
|
puts("Hello, world!");
|
||||||
|
}
|
121
pico_sdk_import.cmake
Normal file
121
pico_sdk_import.cmake
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
# 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()
|
||||||
|
|
||||||
|
# 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))
|
||||||
|
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 ()
|
||||||
|
|
||||||
|
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_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_TAG "${PICO_SDK_FETCH_FROM_GIT_TAG}" CACHE FILEPATH "release tag for 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 ${PICO_SDK_FETCH_FROM_GIT_TAG}
|
||||||
|
)
|
||||||
|
|
||||||
|
if (NOT pico_sdk)
|
||||||
|
message("Downloading Raspberry Pi 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})
|
||||||
|
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})
|
57
tx_rx.cpp
Normal file
57
tx_rx.cpp
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
// --- C/C++ Integration Code ---
|
||||||
|
#include "hardware/irq.h"
|
||||||
|
#include "hardware/pio.h"
|
||||||
|
#include "pico/stdlib.h"
|
||||||
|
|
||||||
|
#include "argb_tx.pio.h"
|
||||||
|
|
||||||
|
#define PIN_BASE 0
|
||||||
|
#define PIN_COUNT 1
|
||||||
|
|
||||||
|
PIO pio = pio0;
|
||||||
|
uint sm = 0;
|
||||||
|
volatile bool transmission_done = false;
|
||||||
|
|
||||||
|
void pio_irq_handler() {
|
||||||
|
pio->irq = 1; // Clear interrupt
|
||||||
|
transmission_done = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_pio() {
|
||||||
|
uint offset = pio_add_program(pio, &argb_tx_program);
|
||||||
|
pio_sm_config c = argb_tx_program_get_default_config(offset);
|
||||||
|
|
||||||
|
sm_config_set_out_pins(&c, PIN_BASE, PIN_COUNT);
|
||||||
|
sm_config_set_sideset_pins(&c, PIN_BASE);
|
||||||
|
sm_config_set_out_shift(&c, true, true, 32);
|
||||||
|
|
||||||
|
pio_sm_init(pio, sm, offset, &c);
|
||||||
|
pio_set_irq0_source_enabled(pio, pis_interrupt0, true);
|
||||||
|
irq_set_exclusive_handler(PIO0_IRQ_0, pio_irq_handler);
|
||||||
|
irq_set_enabled(PIO0_IRQ_0, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void send_bits(const uint8_t *bits, uint num_bits) {
|
||||||
|
transmission_done = false;
|
||||||
|
|
||||||
|
// Send bit count (first word)
|
||||||
|
uint32_t count_word = num_bits;
|
||||||
|
pio_sm_put_blocking(pio, sm, count_word);
|
||||||
|
|
||||||
|
// Pack bits into 32-bit words
|
||||||
|
uint num_words = (num_bits + 31) / 32;
|
||||||
|
for (uint i = 0; i < num_words; ++i) {
|
||||||
|
uint32_t word = 0;
|
||||||
|
for (uint b = 0; b < 32; ++b) {
|
||||||
|
uint idx = i * 32 + b;
|
||||||
|
if (idx < num_bits) {
|
||||||
|
word |= (bits[idx] & 1) << b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pio_sm_put_blocking(pio, sm, word);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for completion
|
||||||
|
while (!transmission_done)
|
||||||
|
;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user