Skip to content

Use micropython #defines for stream polling operations #7058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2022
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
2 changes: 1 addition & 1 deletion extmod/moduselect.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <stdio.h>

#include "py/ioctl.h"
#include "py/stream.h"
#include "py/runtime.h"
#include "py/obj.h"
#include "py/objlist.h"
Expand Down
38 changes: 0 additions & 38 deletions py/ioctl.h

This file was deleted.

12 changes: 6 additions & 6 deletions shared-bindings/_bleio/CharacteristicBuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

#include "py/mperrno.h"
#include "py/ioctl.h"
#include "py/stream.h"
#include "py/objproperty.h"
#include "py/runtime.h"
#include "py/stream.h"
Expand Down Expand Up @@ -138,15 +138,15 @@ STATIC mp_uint_t bleio_characteristic_buffer_ioctl(mp_obj_t self_in, mp_uint_t r
check_for_deinit(self);
raise_error_if_not_connected(self);
mp_uint_t ret;
if (request == MP_IOCTL_POLL) {
if (request == MP_STREAM_POLL) {
mp_uint_t flags = arg;
ret = 0;
if ((flags & MP_IOCTL_POLL_RD) && common_hal_bleio_characteristic_buffer_rx_characters_available(self) > 0) {
ret |= MP_IOCTL_POLL_RD;
if ((flags & MP_STREAM_POLL_RD) && common_hal_bleio_characteristic_buffer_rx_characters_available(self) > 0) {
ret |= MP_STREAM_POLL_RD;
}
// No writing provided.
// if ((flags & MP_IOCTL_POLL_WR) && common_hal_busio_uart_ready_to_tx(self)) {
// ret |= MP_IOCTL_POLL_WR;
// if ((flags & MP_STREAM_POLL_WR) && common_hal_busio_uart_ready_to_tx(self)) {
// ret |= MP_STREAM_POLL_WR;
// }
} else {
*errcode = MP_EINVAL;
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/_bleio/PacketBuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

#include "py/mperrno.h"
#include "py/ioctl.h"
#include "py/stream.h"
#include "py/objproperty.h"
#include "py/runtime.h"
#include "py/stream.h"
Expand Down
12 changes: 6 additions & 6 deletions shared-bindings/busio/UART.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "shared/runtime/context_manager_helpers.h"
#include "shared/runtime/interrupt_char.h"

#include "py/ioctl.h"
#include "py/stream.h"
#include "py/objproperty.h"
#include "py/objtype.h"
#include "py/runtime.h"
Expand Down Expand Up @@ -276,14 +276,14 @@ STATIC mp_uint_t busio_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t
busio_uart_obj_t *self = native_uart(self_in);
check_for_deinit(self);
mp_uint_t ret;
if (request == MP_IOCTL_POLL) {
if (request == MP_STREAM_POLL) {
mp_uint_t flags = arg;
ret = 0;
if ((flags & MP_IOCTL_POLL_RD) && common_hal_busio_uart_rx_characters_available(self) > 0) {
ret |= MP_IOCTL_POLL_RD;
if ((flags & MP_STREAM_POLL_RD) && common_hal_busio_uart_rx_characters_available(self) > 0) {
ret |= MP_STREAM_POLL_RD;
}
if ((flags & MP_IOCTL_POLL_WR) && common_hal_busio_uart_ready_to_tx(self)) {
ret |= MP_IOCTL_POLL_WR;
if ((flags & MP_STREAM_POLL_WR) && common_hal_busio_uart_ready_to_tx(self)) {
ret |= MP_STREAM_POLL_WR;
}
} else {
*errcode = MP_EINVAL;
Expand Down
6 changes: 3 additions & 3 deletions shared-bindings/keypad/EventQueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* THE SOFTWARE.
*/

#include "py/ioctl.h"
#include "py/stream.h"
#include "py/mperrno.h"
#include "py/objproperty.h"
#include "py/runtime.h"
Expand Down Expand Up @@ -147,8 +147,8 @@ STATIC mp_uint_t eventqueue_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t
case MP_STREAM_POLL: {
mp_uint_t flags = arg;
mp_uint_t ret = 0;
if ((flags & MP_IOCTL_POLL_RD) && common_hal_keypad_eventqueue_get_length(self)) {
ret |= MP_IOCTL_POLL_RD;
if ((flags & MP_STREAM_POLL_RD) && common_hal_keypad_eventqueue_get_length(self)) {
ret |= MP_STREAM_POLL_RD;
}
return ret;
}
Expand Down
8 changes: 4 additions & 4 deletions shared-bindings/terminalio/Terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "shared-bindings/terminalio/Terminal.h"
#include "shared-bindings/util.h"

#include "py/ioctl.h"
#include "py/stream.h"
#include "py/objproperty.h"
#include "py/objstr.h"
#include "py/runtime.h"
Expand Down Expand Up @@ -111,11 +111,11 @@ STATIC mp_uint_t terminalio_terminal_write(mp_obj_t self_in, const void *buf_in,
STATIC mp_uint_t terminalio_terminal_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
terminalio_terminal_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret;
if (request == MP_IOCTL_POLL) {
if (request == MP_STREAM_POLL) {
mp_uint_t flags = arg;
ret = 0;
if ((flags & MP_IOCTL_POLL_WR) && common_hal_terminalio_terminal_ready_to_tx(self)) {
ret |= MP_IOCTL_POLL_WR;
if ((flags & MP_STREAM_POLL_WR) && common_hal_terminalio_terminal_ready_to_tx(self)) {
ret |= MP_STREAM_POLL_WR;
}
} else {
*errcode = MP_EINVAL;
Expand Down
12 changes: 6 additions & 6 deletions shared-bindings/usb_cdc/Serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "shared-bindings/usb_cdc/Serial.h"
#include "shared-bindings/util.h"

#include "py/ioctl.h"
#include "py/stream.h"
#include "py/objproperty.h"
#include "py/runtime.h"
#include "py/stream.h"
Expand Down Expand Up @@ -114,14 +114,14 @@ STATIC mp_uint_t usb_cdc_serial_ioctl_stream(mp_obj_t self_in, mp_uint_t request
usb_cdc_serial_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret = 0;
switch (request) {
case MP_IOCTL_POLL: {
case MP_STREAM_POLL: {
mp_uint_t flags = arg;
ret = 0;
if ((flags & MP_IOCTL_POLL_RD) && common_hal_usb_cdc_serial_get_in_waiting(self) > 0) {
ret |= MP_IOCTL_POLL_RD;
if ((flags & MP_STREAM_POLL_RD) && common_hal_usb_cdc_serial_get_in_waiting(self) > 0) {
ret |= MP_STREAM_POLL_RD;
}
if ((flags & MP_IOCTL_POLL_WR) && common_hal_usb_cdc_serial_get_out_waiting(self) == 0) {
ret |= MP_IOCTL_POLL_WR;
if ((flags & MP_STREAM_POLL_WR) && common_hal_usb_cdc_serial_get_out_waiting(self) == 0) {
ret |= MP_STREAM_POLL_WR;
}
break;
}
Expand Down
8 changes: 4 additions & 4 deletions shared-bindings/usb_midi/PortIn.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "shared-bindings/usb_midi/PortIn.h"
#include "shared-bindings/util.h"

#include "py/ioctl.h"
#include "py/stream.h"
#include "py/objproperty.h"
#include "py/runtime.h"
#include "py/stream.h"
Expand Down Expand Up @@ -81,11 +81,11 @@ STATIC mp_uint_t usb_midi_portin_read(mp_obj_t self_in, void *buf_in, mp_uint_t
STATIC mp_uint_t usb_midi_portin_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
usb_midi_portin_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret;
if (request == MP_IOCTL_POLL) {
if (request == MP_STREAM_POLL) {
mp_uint_t flags = arg;
ret = 0;
if ((flags & MP_IOCTL_POLL_RD) && common_hal_usb_midi_portin_bytes_available(self) > 0) {
ret |= MP_IOCTL_POLL_RD;
if ((flags & MP_STREAM_POLL_RD) && common_hal_usb_midi_portin_bytes_available(self) > 0) {
ret |= MP_STREAM_POLL_RD;
}
} else {
*errcode = MP_EINVAL;
Expand Down
8 changes: 4 additions & 4 deletions shared-bindings/usb_midi/PortOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "shared-bindings/usb_midi/PortOut.h"
#include "shared-bindings/util.h"

#include "py/ioctl.h"
#include "py/stream.h"
#include "py/objproperty.h"
#include "py/runtime.h"
#include "py/stream.h"
Expand Down Expand Up @@ -64,11 +64,11 @@ STATIC mp_uint_t usb_midi_portout_write(mp_obj_t self_in, const void *buf_in, mp
STATIC mp_uint_t usb_midi_portout_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
usb_midi_portout_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret;
if (request == MP_IOCTL_POLL) {
if (request == MP_STREAM_POLL) {
mp_uint_t flags = arg;
ret = 0;
if ((flags & MP_IOCTL_POLL_WR) && common_hal_usb_midi_portout_ready_to_tx(self)) {
ret |= MP_IOCTL_POLL_WR;
if ((flags & MP_STREAM_POLL_WR) && common_hal_usb_midi_portout_ready_to_tx(self)) {
ret |= MP_STREAM_POLL_WR;
}
} else {
*errcode = MP_EINVAL;
Expand Down