forked from adafruit/circuitpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUSBFramebuffer.c
More file actions
147 lines (127 loc) · 6 KB
/
Copy pathUSBFramebuffer.c
File metadata and controls
147 lines (127 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2024 Jeff Epler for Adafruit Industries
//
// SPDX-License-Identifier: MIT
#include "py/obj.h"
#include "py/objproperty.h"
#include "shared-bindings/usb_video/__init__.h"
#include "shared-bindings/usb_video/USBFramebuffer.h"
#include "shared-module/displayio/__init__.h"
#include "shared-module/framebufferio/FramebufferDisplay.h"
#include "shared-module/framebufferio/__init__.h"
#include "shared-module/usb_video/__init__.h"
#include "shared-module/usb_video/USBFramebuffer.h"
#include "shared-bindings/util.h"
static void check_for_deinit(usb_video_uvcframebuffer_obj_t *self) {
if (!shared_module_usb_video_uvcframebuffer_get_width(self)) {
raise_deinited_error();
}
}
//| class USBFramebuffer:
//| """Displays to a USB connected computer using the UVC protocol
//|
//| The data in the framebuffer is in RGB565_SWAPPED format.
//|
//| This object is most often used with `framebufferio.FramebufferDisplay`. However,
//| it also supports the ``WritableBuffer`` protocol and can be accessed
//| as an array of ``H`` (unsigned 16-bit values)."""
//|
//| def __init__(self) -> None:
//| """Returns the singleton framebuffer object, if USB video is enabled"""
//|
static mp_obj_t usb_video_uvcframebuffer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
static const mp_arg_t allowed_args[] = {};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
usb_video_uvcframebuffer_obj_t *self = &usb_video_uvcframebuffer_singleton_obj;
return self;
}
//| def refresh(self) -> None:
//| """Transmits the color data in the buffer to the pixels so that
//| they are shown."""
//| ...
//|
static mp_obj_t usb_video_uvcframebuffer_refresh(mp_obj_t self_in) {
usb_video_uvcframebuffer_obj_t *self = (usb_video_uvcframebuffer_obj_t *)self_in;
check_for_deinit(self);
shared_module_usb_video_uvcframebuffer_refresh(self);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(usb_video_uvcframebuffer_refresh_obj, usb_video_uvcframebuffer_refresh);
//| width: int
//| """The width of the display, in pixels"""
static mp_obj_t usb_video_uvcframebuffer_get_width(mp_obj_t self_in) {
usb_video_uvcframebuffer_obj_t *self = (usb_video_uvcframebuffer_obj_t *)self_in;
check_for_deinit(self);
return MP_OBJ_NEW_SMALL_INT(shared_module_usb_video_uvcframebuffer_get_width(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(usb_video_uvcframebuffer_get_width_obj, usb_video_uvcframebuffer_get_width);
MP_PROPERTY_GETTER(usb_video_uvcframebuffer_width_obj,
(mp_obj_t)&usb_video_uvcframebuffer_get_width_obj);
//| height: int
//| """The height of the display, in pixels"""
//|
//|
static mp_obj_t usb_video_uvcframebuffer_get_height(mp_obj_t self_in) {
usb_video_uvcframebuffer_obj_t *self = (usb_video_uvcframebuffer_obj_t *)self_in;
check_for_deinit(self);
return MP_OBJ_NEW_SMALL_INT(shared_module_usb_video_uvcframebuffer_get_height(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(usb_video_uvcframebuffer_get_height_obj, usb_video_uvcframebuffer_get_height);
MP_PROPERTY_GETTER(usb_video_uvcframebuffer_height_obj,
(mp_obj_t)&usb_video_uvcframebuffer_get_height_obj);
static const mp_rom_map_elem_t usb_video_uvcframebuffer_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_refresh), MP_ROM_PTR(&usb_video_uvcframebuffer_refresh_obj) },
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&usb_video_uvcframebuffer_width_obj) },
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&usb_video_uvcframebuffer_height_obj) },
};
static MP_DEFINE_CONST_DICT(usb_video_uvcframebuffer_locals_dict, usb_video_uvcframebuffer_locals_dict_table);
static void usb_video_uvcframebuffer_get_bufinfo(mp_obj_t self_in, mp_buffer_info_t *bufinfo) {
shared_module_usb_video_uvcframebuffer_get_bufinfo(self_in, bufinfo);
}
// These version exists so that the prototype matches the protocol,
// avoiding a type cast that can hide errors
static void usb_video_uvcframebuffer_swapbuffers(mp_obj_t self_in, uint8_t *dirty_row_bitmap) {
(void)dirty_row_bitmap;
shared_module_usb_video_uvcframebuffer_refresh(self_in);
}
static void usb_video_uvcframebuffer_deinit_proto(mp_obj_t self_in) {
/* NOTHING */
}
static int usb_video_uvcframebuffer_get_width_proto(mp_obj_t self_in) {
return shared_module_usb_video_uvcframebuffer_get_width(self_in);
}
static int usb_video_uvcframebuffer_get_height_proto(mp_obj_t self_in) {
return shared_module_usb_video_uvcframebuffer_get_height(self_in);
}
static int usb_video_uvcframebuffer_get_native_frames_per_second_proto(mp_obj_t self_in) {
return 10;
}
static bool usb_video_uvcframebuffer_get_reverse_pixels_in_word_proto(mp_obj_t self_in) {
return true;
}
static const framebuffer_p_t usb_video_uvcframebuffer_proto = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_framebuffer)
.get_bufinfo = usb_video_uvcframebuffer_get_bufinfo,
.get_width = usb_video_uvcframebuffer_get_width_proto,
.get_height = usb_video_uvcframebuffer_get_height_proto,
.get_native_frames_per_second = usb_video_uvcframebuffer_get_native_frames_per_second_proto,
.swapbuffers = usb_video_uvcframebuffer_swapbuffers,
.deinit = usb_video_uvcframebuffer_deinit_proto,
.get_reverse_pixels_in_word = usb_video_uvcframebuffer_get_reverse_pixels_in_word_proto,
};
static mp_int_t usb_video_uvcframebuffer_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
shared_module_usb_video_uvcframebuffer_get_bufinfo(self_in, bufinfo);
bufinfo->typecode = 'H';
return 0;
}
MP_DEFINE_CONST_OBJ_TYPE(
usb_video_USBFramebuffer_type,
MP_QSTR_USBFramebuffer,
MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS,
locals_dict, &usb_video_uvcframebuffer_locals_dict,
make_new, usb_video_uvcframebuffer_make_new,
buffer, usb_video_uvcframebuffer_get_buffer,
protocol, &usb_video_uvcframebuffer_proto
);