Skip to content

Commit f80ae1e

Browse files
authored
Merge pull request #33 from adafruit/reduce-post-addr-delay
Reduce post addr delay
2 parents 0a9e578 + a2827b6 commit f80ae1e

File tree

20 files changed

+2346
-2293
lines changed

20 files changed

+2346
-2293
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#
1313
# See https://github.com/pre-commit/pre-commit
1414

15+
# Don't re-format vendored files
16+
exclude: "^src/piolib/.*$"
17+
1518
ci:
1619
autoupdate_commit_msg: "chore: update pre-commit hooks"
1720
autofix_commit_msg: "style: pre-commit fixes"

src/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
3+
project(protodemo C CXX)
4+
set(CMAKE_C_STANDARD 11)
5+
set(CMAKE_CXX_STANDARD 20)
6+
7+
add_compile_options(-Wall -g3 -Og)
8+
add_executable(protodemo
9+
protodemo.cpp
10+
piolib/piolib.c
11+
piolib/pio_rp1.c
12+
)
13+
14+
add_custom_command(
15+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/protomatter.pio.h
16+
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/assemble.py ${CMAKE_CURRENT_SOURCE_DIR}/protomatter.pio ${CMAKE_CURRENT_BINARY_DIR}/protomatter.pio.h
17+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/assemble.py ${CMAKE_CURRENT_SOURCE_DIR}/protomatter.pio
18+
)
19+
20+
target_include_directories(protodemo PRIVATE include piolib/include)

src/Makefile

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/adafruit_blinka_raspberry_pi5_piomatter/click.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def convert(
2727
return r
2828

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

3434
def standard_options(

src/include/piomatter/matrixmap.h

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -134,47 +134,27 @@ schedule_sequence make_temporal_dither_schedule(int n_planes,
134134
if (n_temporal_planes >= n_planes) {
135135
throw std::range_error("n_temporal_planes can't exceed n_planes");
136136
}
137-
if (n_temporal_planes != 2 && n_temporal_planes != 4) {
138-
// the code can generate a schedule for 8 temporal planes, but it
139-
// flickers intolerably
140-
throw std::range_error("n_temporal_planes must be 0, 1, 2, or 4");
141-
}
142137

143138
int n_real_planes = n_planes - n_temporal_planes;
144139

145-
schedule base_sched;
146-
for (int j = 0; j < n_real_planes; j++) {
147-
base_sched.emplace_back(
148-
9 - j, (1 << (n_temporal_planes + n_real_planes - j - 1)) /
149-
n_temporal_planes);
150-
}
151-
152140
schedule_sequence result;
153141

154-
auto add_sched = [&result, &base_sched](int plane, int count) {
155-
auto sched = base_sched;
142+
auto add_sched = [&result, n_real_planes,
143+
n_temporal_planes](int i, int plane, int count) {
144+
schedule sched;
145+
for (int j = 0; j < n_real_planes; j++) {
146+
int k = 1 << (n_temporal_planes + n_real_planes - j - 1);
147+
sched.emplace_back(9 - j, (k + i) / n_temporal_planes);
148+
}
156149
sched.emplace_back(9 - plane, count);
157150
result.emplace_back(sched);
158151
};
159152

160153
for (int i = 0; i < n_temporal_planes; i++) {
161-
add_sched(n_real_planes + i, 1 << (n_temporal_planes - i - 1));
162-
}
163-
#if 0
164-
std::vector<uint32_t> counts(10, 0);
165-
for (auto s : result) {
166-
for(auto t: s) {
167-
counts[t.shift] += t.active_time;
168-
}
169-
}
170-
for (auto s : counts) {
171-
printf("%d ", s);
154+
add_sched(i, n_real_planes + i, 1 << (n_temporal_planes - i - 1));
172155
}
173-
printf("\n");
174-
#endif
175156

176157
return rescale_schedule(result, pixels_across);
177-
;
178158
}
179159

180160
struct matrix_geometry {

src/include/piomatter/pins.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct adafruit_matrix_bonnet_pinout {
1919

2020
static constexpr uint32_t post_oe_delay = 0;
2121
static constexpr uint32_t post_latch_delay = 0;
22-
static constexpr uint32_t post_addr_delay = 500;
22+
static constexpr uint32_t post_addr_delay = 5;
2323
};
2424

2525
struct adafruit_matrix_bonnet_pinout_bgr {
@@ -37,7 +37,7 @@ struct adafruit_matrix_bonnet_pinout_bgr {
3737

3838
static constexpr uint32_t post_oe_delay = 0;
3939
static constexpr uint32_t post_latch_delay = 0;
40-
static constexpr uint32_t post_addr_delay = 500;
40+
static constexpr uint32_t post_addr_delay = 5;
4141
};
4242

4343
struct active3_pinout {
@@ -56,7 +56,7 @@ struct active3_pinout {
5656

5757
static constexpr uint32_t post_oe_delay = 0;
5858
static constexpr uint32_t post_latch_delay = 0;
59-
static constexpr uint32_t post_addr_delay = 500;
59+
static constexpr uint32_t post_addr_delay = 5;
6060
};
6161

6262
struct active3_pinout_bgr {
@@ -75,7 +75,7 @@ struct active3_pinout_bgr {
7575

7676
static constexpr uint32_t post_oe_delay = 0;
7777
static constexpr uint32_t post_latch_delay = 0;
78-
static constexpr uint32_t post_addr_delay = 500;
78+
static constexpr uint32_t post_addr_delay = 5;
7979
};
8080

8181
} // namespace piomatter

src/include/piomatter/piomatter.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,6 @@ static uint64_t monotonicns64() {
2020

2121
constexpr size_t MAX_XFER = 65532;
2222

23-
void pio_sm_xfer_data_large(PIO pio, int sm, int direction, size_t size,
24-
uint32_t *databuf) {
25-
while (size) {
26-
size_t xfersize = std::min(size_t{MAX_XFER}, size);
27-
int r = pio_sm_xfer_data(pio, sm, direction, xfersize, databuf);
28-
if (r) {
29-
throw std::runtime_error(
30-
"pio_sm_xfer_data (reboot may be required)");
31-
}
32-
size -= xfersize;
33-
databuf += xfersize / sizeof(*databuf);
34-
}
35-
}
36-
3723
struct piomatter_base {
3824
piomatter_base() {}
3925
piomatter_base(const piomatter_base &) = delete;
@@ -106,7 +92,7 @@ struct piomatter : piomatter_base {
10692
if (sm < 0) {
10793
throw std::runtime_error("pio_claim_unused_sm");
10894
}
109-
int r = pio_sm_config_xfer(pio, sm, PIO_DIR_TO_SM, MAX_XFER, 2);
95+
int r = pio_sm_config_xfer(pio, sm, PIO_DIR_TO_SM, MAX_XFER, 3);
11096
if (r) {
11197
throw std::runtime_error("pio_sm_config_xfer");
11298
}
@@ -188,8 +174,7 @@ struct piomatter : piomatter_base {
188174
const auto &data = cur_buf[seq_idx];
189175
auto datasize = sizeof(uint32_t) * data.size();
190176
auto dataptr = const_cast<uint32_t *>(&data[0]);
191-
pio_sm_xfer_data_large(pio, sm, PIO_DIR_TO_SM, datasize,
192-
dataptr);
177+
pio_sm_xfer_data(pio, sm, PIO_DIR_TO_SM, datasize, dataptr);
193178
t1 = monotonicns64();
194179
if (t0 != t1) {
195180
fps = 1e9 / (t1 - t0);

src/piolib/include/hardware/clocks.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
#define _HARDWARE_CLOCKS_H
99

1010
enum clock_index {
11-
clk_gpout0 = 0, ///< GPIO Muxing 0
12-
clk_gpout1, ///< GPIO Muxing 1
13-
clk_gpout2, ///< GPIO Muxing 2
14-
clk_gpout3, ///< GPIO Muxing 3
15-
clk_ref, ///< Watchdog and timers reference clock
16-
clk_sys, ///< Processors, bus fabric, memory, memory mapped registers
17-
clk_peri, ///< Peripheral clock for UART and SPI
18-
clk_usb, ///< USB clock
19-
clk_adc, ///< ADC clock
20-
clk_rtc, ///< Real time clock
11+
clk_gpout0 = 0, ///< GPIO Muxing 0
12+
clk_gpout1, ///< GPIO Muxing 1
13+
clk_gpout2, ///< GPIO Muxing 2
14+
clk_gpout3, ///< GPIO Muxing 3
15+
clk_ref, ///< Watchdog and timers reference clock
16+
clk_sys, ///< Processors, bus fabric, memory, memory mapped registers
17+
clk_peri, ///< Peripheral clock for UART and SPI
18+
clk_usb, ///< USB clock
19+
clk_adc, ///< ADC clock
20+
clk_rtc, ///< Real time clock
2121
CLK_COUNT
2222
};
2323

src/piolib/include/hardware/gpio.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,14 @@ enum gpio_irq_level {
3939
};
4040

4141
enum gpio_override {
42-
GPIO_OVERRIDE_NORMAL =
43-
0, ///< peripheral signal selected via \ref gpio_set_function
44-
GPIO_OVERRIDE_INVERT =
45-
1, ///< invert peripheral signal selected via \ref gpio_set_function
46-
GPIO_OVERRIDE_LOW = 2, ///< drive low/disable output
47-
GPIO_OVERRIDE_HIGH = 3, ///< drive high/enable output
42+
GPIO_OVERRIDE_NORMAL = 0, ///< peripheral signal selected via \ref gpio_set_function
43+
GPIO_OVERRIDE_INVERT = 1, ///< invert peripheral signal selected via \ref gpio_set_function
44+
GPIO_OVERRIDE_LOW = 2, ///< drive low/disable output
45+
GPIO_OVERRIDE_HIGH = 3, ///< drive high/enable output
4846
};
4947
enum gpio_slew_rate {
50-
GPIO_SLEW_RATE_SLOW = 0, ///< Slew rate limiting enabled
51-
GPIO_SLEW_RATE_FAST = 1 ///< Slew rate limiting disabled
48+
GPIO_SLEW_RATE_SLOW = 0, ///< Slew rate limiting enabled
49+
GPIO_SLEW_RATE_FAST = 1 ///< Slew rate limiting disabled
5250
};
5351

5452
enum gpio_drive_strength {

0 commit comments

Comments
 (0)