Updates along with SDK1.3.0 release (#181)

Bug fixes and new examples

Co-authored-by: Paulo Marques <pm@quant-insight.com>
Co-authored-by: martin <admin@crossleys.biz>
Co-authored-by: matiasilva <matias.silva@raspberrypi.com>
Co-authored-by: Uri Shaked <uri@urishaked.com>
Co-authored-by: Diego Solano <diegosolano@gmail.com>
Co-authored-by: Andrew Scheller <andrew.scheller@raspberrypi.com>
Co-authored-by: Adrian Hesketh <a-h@users.noreply.github.com>
Co-authored-by: Emircan Gündoğdu <58917386+emircangun@users.noreply.github.com>
Co-authored-by: Josef Wegner <80200012+josefwegner@users.noreply.github.com>
Co-authored-by: pmarques-dev <72901351+pmarques-dev@users.noreply.github.com>
Co-authored-by: Paulo Marques <pm@quant-insight.com>
Co-authored-by: mjcross <mjcross@users.noreply.github.com>
Co-authored-by: martin <admin@crossleys.biz>
This commit is contained in:
Graham Sanderson
2021-11-01 14:41:54 -05:00
committed by GitHub
parent 146680d625
commit f800a7e303
150 changed files with 4832 additions and 98 deletions

View File

@@ -2,6 +2,8 @@
// This file is autogenerated by pioasm; do not edit! //
// -------------------------------------------------- //
#pragma once
#if !PICO_NO_HARDWARE
#include "hardware/pio.h"
#endif

View File

@@ -12,6 +12,16 @@
#include "hardware/clocks.h"
#include "ws2812.pio.h"
#define IS_RGBW true
#define NUM_PIXELS 150
#ifdef PICO_DEFAULT_WS2812_PIN
#define WS2812_PIN PICO_DEFAULT_WS2812_PIN
#else
// default to pin 2 if the board doesn't have a default WS2812 pin defined
#define WS2812_PIN 2
#endif
static inline void put_pixel(uint32_t pixel_grb) {
pio_sm_put_blocking(pio0, 0, pixel_grb << 8u);
}
@@ -71,19 +81,17 @@ const struct {
{pattern_greys, "Greys"},
};
const int PIN_TX = 0;
int main() {
//set_sys_clock_48();
stdio_init_all();
puts("WS2812 Smoke Test");
printf("WS2812 Smoke Test, using pin %d", WS2812_PIN);
// todo get free sm
PIO pio = pio0;
int sm = 0;
uint offset = pio_add_program(pio, &ws2812_program);
ws2812_program_init(pio, sm, offset, PIN_TX, 800000, true);
ws2812_program_init(pio, sm, offset, WS2812_PIN, 800000, IS_RGBW);
int t = 0;
while (1) {
@@ -92,9 +100,9 @@ int main() {
puts(pattern_table[pat].name);
puts(dir == 1 ? "(forward)" : "(backward)");
for (int i = 0; i < 1000; ++i) {
pattern_table[pat].pat(150, t);
pattern_table[pat].pat(NUM_PIXELS, t);
sleep_ms(10);
t += dir;
}
}
}
}

View File

@@ -16,7 +16,8 @@
#include "ws2812.pio.h"
#define FRAC_BITS 4
#define PIN_TX 0
#define NUM_PIXELS 64
#define WS2812_PIN_BASE 2
// horrible temporary hack to avoid changing pattern code
static uint8_t *current_string_out;
@@ -174,17 +175,15 @@ void dither_values(const value_bits_t *colors, value_bits_t *state, const value_
}
}
#define MAX_LENGTH 100
// requested colors * 4 to allow for WRGB
static value_bits_t colors[MAX_LENGTH * 4];
// requested colors * 4 to allow for RGBW
static value_bits_t colors[NUM_PIXELS * 4];
// double buffer the state of the string, since we update next version in parallel with DMAing out old version
static value_bits_t states[2][MAX_LENGTH * 4];
static value_bits_t states[2][NUM_PIXELS * 4];
// example - string 0 is RGB only
static uint8_t string0_data[MAX_LENGTH * 3];
// example - string 1 is WRGB
static uint8_t string1_data[MAX_LENGTH * 4];
static uint8_t string0_data[NUM_PIXELS * 3];
// example - string 1 is RGBW
static uint8_t string1_data[NUM_PIXELS * 4];
string_t string0 = {
.data = string0_data,
@@ -213,7 +212,7 @@ string_t *strings[] = {
#define DMA_CHANNELS_MASK (DMA_CHANNEL_MASK | DMA_CB_CHANNEL_MASK)
// start of each value fragment (+1 for NULL terminator)
static uintptr_t fragment_start[MAX_LENGTH * 4 + 1];
static uintptr_t fragment_start[NUM_PIXELS * 4 + 1];
// posted when it is safe to output a new set of values
static struct semaphore reset_delay_complete_sem;
@@ -286,7 +285,7 @@ int main() {
int sm = 0;
uint offset = pio_add_program(pio, &ws2812_parallel_program);
ws2812_parallel_program_init(pio, sm, offset, PIN_TX, count_of(strings), 800000);
ws2812_parallel_program_init(pio, sm, offset, WS2812_PIN_BASE, count_of(strings), 800000);
sem_init(&reset_delay_complete_sem, 1, 1); // initially posted so we don't block first time
dma_init(pio, sm);
@@ -300,19 +299,17 @@ int main() {
int brightness = 0;
uint current = 0;
for (int i = 0; i < 1000; ++i) {
int n = 64;
current_string_out = string0.data;
current_string_4color = false;
pattern_table[pat].pat(n, t);
pattern_table[pat].pat(NUM_PIXELS, t);
current_string_out = string1.data;
current_string_4color = true;
pattern_table[pat].pat(n, t);
pattern_table[pat].pat(NUM_PIXELS, t);
transform_strings(strings, count_of(strings), colors, n * 4, brightness);
dither_values(colors, states[current], states[current ^ 1], n * 4);
transform_strings(strings, count_of(strings), colors, NUM_PIXELS * 4, brightness);
dither_values(colors, states[current], states[current ^ 1], NUM_PIXELS * 4);
sem_acquire_blocking(&reset_delay_complete_sem);
output_strings_dma(states[current], n * 4);
output_strings_dma(states[current], NUM_PIXELS * 4);
current ^= 1;
t += dir;