Skip to content

Commit 0aa71ed

Browse files
committed
Tweak the picodvi docs and arg checking
1 parent b08714b commit 0aa71ed

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

ports/raspberrypi/bindings/picodvi/Framebuffer.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
#include "shared-module/framebufferio/FramebufferDisplay.h"
3737

3838
//| class Framebuffer:
39-
//| """A PicoDVI managed frame buffer."""
40-
//|
4139
//| def __init__(
4240
//| self,
4341
//| width: int,
@@ -54,13 +52,14 @@
5452
//| color_depth: int = 8,
5553
//| ) -> None:
5654
//| """Create a Framebuffer object with the given dimensions. Memory is
57-
//| allocated outside of onto the heap and then moved outside on VM
58-
//| end.
55+
//| allocated outside of onto the heap and then moved outside on VM end.
56+
//|
57+
//| .. warning:: This will change the system clock speed to match the DVI signal.
58+
//| Make sure to initialize other objects after this one so they account
59+
//| for the changed clock.
5960
//|
60-
//| This will change the system clock speed to match the DVI signal.
61-
//| Make sure to initialize other objects after this one so they account
62-
//| for the changed clock. This also allocates a very large framebuffer
63-
//| and is most likely to succeed the earlier it is attempted.
61+
//| This allocates a very large framebuffer and is most likely to succeed
62+
//| the earlier it is attempted.
6463
//|
6564
//| Each dp and dn pair of pins must be neighboring, such as 19 and 20.
6665
//| They must also be ordered the same way. In other words, dp must be
@@ -82,7 +81,7 @@
8281
//| `framebufferio.FramebufferDisplay`.
8382
//|
8483
//| :param int width: the width of the target display signal. Only 320, 400, 640 or 800 is currently supported depending on color_depth.
85-
//| :param int height: the height of the target display signal. Only 240 or 480 is currently supported depenting on color_depth.
84+
//| :param int height: the height of the target display signal. Only 240 or 480 is currently supported depending on color_depth.
8685
//| :param ~microcontroller.Pin clk_dp: the positive clock signal pin
8786
//| :param ~microcontroller.Pin clk_dn: the negative clock signal pin
8887
//| :param ~microcontroller.Pin red_dp: the positive red signal pin
@@ -160,8 +159,7 @@ static void check_for_deinit(picodvi_framebuffer_obj_t *self) {
160159
}
161160

162161
//| width: int
163-
//| """The width of the framebuffer, in pixels. It may be doubled for output (and half of what
164-
//| width was given to __init__.)"""
162+
//| """The width of the framebuffer, in pixels. It may be doubled for output."""
165163
STATIC mp_obj_t picodvi_framebuffer_get_width(mp_obj_t self_in) {
166164
picodvi_framebuffer_obj_t *self = (picodvi_framebuffer_obj_t *)self_in;
167165
check_for_deinit(self);
@@ -172,8 +170,7 @@ MP_PROPERTY_GETTER(picodvi_framebuffer_width_obj,
172170
(mp_obj_t)&picodvi_framebuffer_get_width_obj);
173171

174172
//| height: int
175-
//| """The width of the framebuffer, in pixels. It may be doubled for output (and half of what
176-
//| width was given to __init__.)"""
173+
//| """The width of the framebuffer, in pixels. It may be doubled for output."""
177174
//|
178175
STATIC mp_obj_t picodvi_framebuffer_get_height(mp_obj_t self_in) {
179176
picodvi_framebuffer_obj_t *self = (picodvi_framebuffer_obj_t *)self_in;

ports/raspberrypi/common-hal/picodvi/Framebuffer.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self,
144144

145145
bool color_framebuffer = color_depth >= 8;
146146
const struct dvi_timing *timing = NULL;
147-
if ((!color_framebuffer && width == 640 && height == 480) ||
148-
(color_framebuffer && width == 320 && height == 240)) {
147+
if ((width == 640 && height == 480) ||
148+
(width == 320 && height == 240)) {
149149
timing = &dvi_timing_640x480p_60hz;
150-
} else if ((!color_framebuffer && width == 800 && height == 480) ||
151-
(color_framebuffer && width == 400 && height == 240)) {
150+
} else if ((width == 800 && height == 480) ||
151+
(width == 400 && height == 240)) {
152152
timing = &dvi_timing_800x480p_60hz;
153153
} else {
154154
if (height != 480 && height != 240) {
@@ -157,6 +157,12 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self,
157157
mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_width);
158158
}
159159

160+
// If the width is > 400, then it must not be color frame buffer and vice
161+
// versa.
162+
if ((width > 400) == color_framebuffer) {
163+
mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_color_depth);
164+
}
165+
160166
bool invert_diffpairs = clk_dn->number < clk_dp->number;
161167
int8_t other_pins[4];
162168
int8_t *a;

0 commit comments

Comments
 (0)