Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#
# See https://github.com/pre-commit/pre-commit

# Don't re-format vendored files
exclude: "^src/piolib/.*$"

ci:
autoupdate_commit_msg: "chore: update pre-commit hooks"
autofix_commit_msg: "style: pre-commit fixes"
Expand Down
20 changes: 20 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.12)

project(protodemo C CXX)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)

add_compile_options(-Wall -g3 -Og)
add_executable(protodemo
protodemo.cpp
piolib/piolib.c
piolib/pio_rp1.c
)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/protomatter.pio.h
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/assemble.py ${CMAKE_CURRENT_SOURCE_DIR}/protomatter.pio ${CMAKE_CURRENT_BINARY_DIR}/protomatter.pio.h
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/assemble.py ${CMAKE_CURRENT_SOURCE_DIR}/protomatter.pio
)

target_include_directories(protodemo PRIVATE include piolib/include)
7 changes: 0 additions & 7 deletions src/Makefile

This file was deleted.

4 changes: 2 additions & 2 deletions src/adafruit_blinka_raspberry_pi5_piomatter/click.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def convert(
return r

def _validate_temporal_planes(ctx, param, value):
if value not in (0, 2, 4):
raise click.BadParameter("must be 0, 2, or 4")
if value not in (0, 1, 2, 3, 4, 5):
raise click.BadParameter("must be from 0 to 5 (0 and 1 both disable temporal planes)")
return value

def standard_options(
Expand Down
36 changes: 8 additions & 28 deletions src/include/piomatter/matrixmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,47 +134,27 @@ schedule_sequence make_temporal_dither_schedule(int n_planes,
if (n_temporal_planes >= n_planes) {
throw std::range_error("n_temporal_planes can't exceed n_planes");
}
if (n_temporal_planes != 2 && n_temporal_planes != 4) {
// the code can generate a schedule for 8 temporal planes, but it
// flickers intolerably
throw std::range_error("n_temporal_planes must be 0, 1, 2, or 4");
}

int n_real_planes = n_planes - n_temporal_planes;

schedule base_sched;
for (int j = 0; j < n_real_planes; j++) {
base_sched.emplace_back(
9 - j, (1 << (n_temporal_planes + n_real_planes - j - 1)) /
n_temporal_planes);
}

schedule_sequence result;

auto add_sched = [&result, &base_sched](int plane, int count) {
auto sched = base_sched;
auto add_sched = [&result, n_real_planes,
n_temporal_planes](int i, int plane, int count) {
schedule sched;
for (int j = 0; j < n_real_planes; j++) {
int k = 1 << (n_temporal_planes + n_real_planes - j - 1);
sched.emplace_back(9 - j, (k + i) / n_temporal_planes);
}
sched.emplace_back(9 - plane, count);
result.emplace_back(sched);
};

for (int i = 0; i < n_temporal_planes; i++) {
add_sched(n_real_planes + i, 1 << (n_temporal_planes - i - 1));
}
#if 0
std::vector<uint32_t> counts(10, 0);
for (auto s : result) {
for(auto t: s) {
counts[t.shift] += t.active_time;
}
}
for (auto s : counts) {
printf("%d ", s);
add_sched(i, n_real_planes + i, 1 << (n_temporal_planes - i - 1));
}
printf("\n");
#endif

return rescale_schedule(result, pixels_across);
;
}

struct matrix_geometry {
Expand Down
8 changes: 4 additions & 4 deletions src/include/piomatter/pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct adafruit_matrix_bonnet_pinout {

static constexpr uint32_t post_oe_delay = 0;
static constexpr uint32_t post_latch_delay = 0;
static constexpr uint32_t post_addr_delay = 500;
static constexpr uint32_t post_addr_delay = 5;
};

struct adafruit_matrix_bonnet_pinout_bgr {
Expand All @@ -37,7 +37,7 @@ struct adafruit_matrix_bonnet_pinout_bgr {

static constexpr uint32_t post_oe_delay = 0;
static constexpr uint32_t post_latch_delay = 0;
static constexpr uint32_t post_addr_delay = 500;
static constexpr uint32_t post_addr_delay = 5;
};

struct active3_pinout {
Expand All @@ -56,7 +56,7 @@ struct active3_pinout {

static constexpr uint32_t post_oe_delay = 0;
static constexpr uint32_t post_latch_delay = 0;
static constexpr uint32_t post_addr_delay = 500;
static constexpr uint32_t post_addr_delay = 5;
};

struct active3_pinout_bgr {
Expand All @@ -75,7 +75,7 @@ struct active3_pinout_bgr {

static constexpr uint32_t post_oe_delay = 0;
static constexpr uint32_t post_latch_delay = 0;
static constexpr uint32_t post_addr_delay = 500;
static constexpr uint32_t post_addr_delay = 5;
};

} // namespace piomatter
19 changes: 2 additions & 17 deletions src/include/piomatter/piomatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@ static uint64_t monotonicns64() {

constexpr size_t MAX_XFER = 65532;

void pio_sm_xfer_data_large(PIO pio, int sm, int direction, size_t size,
uint32_t *databuf) {
while (size) {
size_t xfersize = std::min(size_t{MAX_XFER}, size);
int r = pio_sm_xfer_data(pio, sm, direction, xfersize, databuf);
if (r) {
throw std::runtime_error(
"pio_sm_xfer_data (reboot may be required)");
}
size -= xfersize;
databuf += xfersize / sizeof(*databuf);
}
}

struct piomatter_base {
piomatter_base() {}
piomatter_base(const piomatter_base &) = delete;
Expand Down Expand Up @@ -106,7 +92,7 @@ struct piomatter : piomatter_base {
if (sm < 0) {
throw std::runtime_error("pio_claim_unused_sm");
}
int r = pio_sm_config_xfer(pio, sm, PIO_DIR_TO_SM, MAX_XFER, 2);
int r = pio_sm_config_xfer(pio, sm, PIO_DIR_TO_SM, MAX_XFER, 3);
if (r) {
throw std::runtime_error("pio_sm_config_xfer");
}
Expand Down Expand Up @@ -188,8 +174,7 @@ struct piomatter : piomatter_base {
const auto &data = cur_buf[seq_idx];
auto datasize = sizeof(uint32_t) * data.size();
auto dataptr = const_cast<uint32_t *>(&data[0]);
pio_sm_xfer_data_large(pio, sm, PIO_DIR_TO_SM, datasize,
dataptr);
pio_sm_xfer_data(pio, sm, PIO_DIR_TO_SM, datasize, dataptr);
t1 = monotonicns64();
if (t0 != t1) {
fps = 1e9 / (t1 - t0);
Expand Down
20 changes: 10 additions & 10 deletions src/piolib/include/hardware/clocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
#define _HARDWARE_CLOCKS_H

enum clock_index {
clk_gpout0 = 0, ///< GPIO Muxing 0
clk_gpout1, ///< GPIO Muxing 1
clk_gpout2, ///< GPIO Muxing 2
clk_gpout3, ///< GPIO Muxing 3
clk_ref, ///< Watchdog and timers reference clock
clk_sys, ///< Processors, bus fabric, memory, memory mapped registers
clk_peri, ///< Peripheral clock for UART and SPI
clk_usb, ///< USB clock
clk_adc, ///< ADC clock
clk_rtc, ///< Real time clock
clk_gpout0 = 0, ///< GPIO Muxing 0
clk_gpout1, ///< GPIO Muxing 1
clk_gpout2, ///< GPIO Muxing 2
clk_gpout3, ///< GPIO Muxing 3
clk_ref, ///< Watchdog and timers reference clock
clk_sys, ///< Processors, bus fabric, memory, memory mapped registers
clk_peri, ///< Peripheral clock for UART and SPI
clk_usb, ///< USB clock
clk_adc, ///< ADC clock
clk_rtc, ///< Real time clock
CLK_COUNT
};

Expand Down
14 changes: 6 additions & 8 deletions src/piolib/include/hardware/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@ enum gpio_irq_level {
};

enum gpio_override {
GPIO_OVERRIDE_NORMAL =
0, ///< peripheral signal selected via \ref gpio_set_function
GPIO_OVERRIDE_INVERT =
1, ///< invert peripheral signal selected via \ref gpio_set_function
GPIO_OVERRIDE_LOW = 2, ///< drive low/disable output
GPIO_OVERRIDE_HIGH = 3, ///< drive high/enable output
GPIO_OVERRIDE_NORMAL = 0, ///< peripheral signal selected via \ref gpio_set_function
GPIO_OVERRIDE_INVERT = 1, ///< invert peripheral signal selected via \ref gpio_set_function
GPIO_OVERRIDE_LOW = 2, ///< drive low/disable output
GPIO_OVERRIDE_HIGH = 3, ///< drive high/enable output
};
enum gpio_slew_rate {
GPIO_SLEW_RATE_SLOW = 0, ///< Slew rate limiting enabled
GPIO_SLEW_RATE_FAST = 1 ///< Slew rate limiting disabled
GPIO_SLEW_RATE_SLOW = 0, ///< Slew rate limiting enabled
GPIO_SLEW_RATE_FAST = 1 ///< Slew rate limiting disabled
};

enum gpio_drive_strength {
Expand Down
Loading