wip
This commit is contained in:
parent
0802b22ed6
commit
1b7f3d11e7
@ -28,10 +28,24 @@
|
||||
#include "shared-bindings/supervisor/Runtime.h"
|
||||
#include "supervisor/serial.h"
|
||||
|
||||
bool common_hal_get_serial_connected(void) {
|
||||
bool common_hal_supervisor_runtime_get_serial_connected(void) {
|
||||
return (bool) serial_connected();
|
||||
}
|
||||
|
||||
bool common_hal_get_serial_bytes_available(void) {
|
||||
bool common_hal_get_supervisor_runtime_serial_bytes_available(void) {
|
||||
return (bool) serial_bytes_available();
|
||||
}
|
||||
|
||||
#if CIRCUITPY_USB_SERIAL2
|
||||
mp_obj_t common_hal_supervisor_runtime_get_serial2(void) {
|
||||
return (bool) serial_connected();
|
||||
}
|
||||
|
||||
bool common_hal_supervisor_runtime_get_serial2_connected(void) {
|
||||
return (bool) serial_connected();
|
||||
}
|
||||
|
||||
bool common_hal_get_supervisor_runtime_serial2_bytes_available(void) {
|
||||
return (bool) serial_bytes_available();
|
||||
}
|
||||
#endif
|
||||
|
@ -55,43 +55,96 @@ STATIC supervisor_run_reason_t _run_reason;
|
||||
//| serial_connected: bool
|
||||
//| """Returns the USB serial communication status (read-only)."""
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t supervisor_get_serial_connected(mp_obj_t self){
|
||||
if (!common_hal_get_serial_connected()) {
|
||||
return mp_const_false;
|
||||
}
|
||||
else {
|
||||
return mp_const_true;
|
||||
}
|
||||
STATIC mp_obj_t supervisor_runtime_get_serial_connected(mp_obj_t self){
|
||||
return mp_obj_new_bool(common_hal_supervisor_runtime_get_serial_connected());
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(supervisor_get_serial_connected_obj, supervisor_get_serial_connected);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_serial_connected_obj, supervisor_runtime_get_serial_connected);
|
||||
|
||||
const mp_obj_property_t supervisor_serial_connected_obj = {
|
||||
//| serial2: io.BytesIO
|
||||
//| """Returns the USB secondary serial communication channel.
|
||||
//| Raises `NotImplementedError` if it does not exist.
|
||||
//| """
|
||||
//|
|
||||
STATIC mp_obj_t supervisor_runtime_get_serial2(mp_obj_t self){
|
||||
#if CIRCUITPY_USB_SERIAL2
|
||||
return mp_obj_new_bool(common_hal_supervisor_runtime_get_serial2());
|
||||
#else
|
||||
mp_raise_NotImplementedError(translate("serial2 not available"));
|
||||
#endif
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_serial2_obj, supervisor_runtime_get_serial2);
|
||||
|
||||
const mp_obj_property_t supervisor_runtime_serial2_connected_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&supervisor_get_serial_connected_obj,
|
||||
.proxy = {(mp_obj_t)&supervisor_runtime_get_serial2_connected_obj,
|
||||
(mp_obj_t)&mp_const_none_obj,
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
const mp_obj_property_t supervisor_runtime_serial_connected_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&supervisor_runtime_get_serial_connected_obj,
|
||||
(mp_obj_t)&mp_const_none_obj,
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| serial2_connected: bool
|
||||
//| """Returns the USB secondary serial communication status (read-only).
|
||||
//| Raises `NotImplementedError` if there is no secondary serial channel.
|
||||
//| """
|
||||
//|
|
||||
STATIC mp_obj_t supervisor_runtime_get_serial2_connected(mp_obj_t self){
|
||||
#if CIRCUITPY_USB_SERIAL2
|
||||
return mp_obj_new_bool(common_hal_supervisor_runtime_get_serial2_connected());
|
||||
#else
|
||||
mp_raise_NotImplementedError(translate("serial2 not available"));
|
||||
#endif
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_serial2_connected_obj, supervisor_runtime_get_serial2_connected);
|
||||
|
||||
const mp_obj_property_t supervisor_runtime_serial2_connected_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&supervisor_runtime_get_serial2_connected_obj,
|
||||
(mp_obj_t)&mp_const_none_obj,
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| serial_bytes_available: int
|
||||
//| """Returns the whether any bytes are available to read
|
||||
//| on the USB serial input. Allows for polling to see whether
|
||||
//| to call the built-in input() or wait. (read-only)"""
|
||||
//|
|
||||
STATIC mp_obj_t supervisor_get_serial_bytes_available(mp_obj_t self){
|
||||
if (!common_hal_get_serial_bytes_available()) {
|
||||
return mp_const_false;
|
||||
}
|
||||
else {
|
||||
return mp_const_true;
|
||||
}
|
||||
STATIC mp_obj_t supervisor_runtime_get_serial_bytes_available(mp_obj_t self){
|
||||
return mp_obj_new_bool(common_hal_supervisor_runtime_get_serial_bytes_available());
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(supervisor_get_serial_bytes_available_obj, supervisor_get_serial_bytes_available);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_serial_bytes_available_obj, supervisor_runtime_get_serial_bytes_available);
|
||||
|
||||
const mp_obj_property_t supervisor_serial_bytes_available_obj = {
|
||||
const mp_obj_property_t supervisor_runtime_serial_bytes_available_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&supervisor_get_serial_bytes_available_obj,
|
||||
.proxy = {(mp_obj_t)&supervisor_runtime_get_serial_bytes_available_obj,
|
||||
(mp_obj_t)&mp_const_none_obj,
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
|
||||
//| serial2_bytes_available: int
|
||||
//| """Returns the whether any bytes are available to read
|
||||
//| on the secondary USB serial input (read-only).
|
||||
//| Raises `NotImplementedError` if there is no secondary serial input.
|
||||
//| """
|
||||
//|
|
||||
STATIC mp_obj_t supervisor_runtime_get_serial2_bytes_available(mp_obj_t self){
|
||||
#if CIRCUITPY_USB_SERIAL2
|
||||
return mp_obj_new_bool(common_hal_supervisor_runtime_get_serial2_bytes_available());
|
||||
#else
|
||||
mp_raise_NotImplementedError(translate("serial2 not available"));
|
||||
#endif
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_serial2_bytes_available_obj, supervisor_runtime_get_serial2_bytes_available);
|
||||
|
||||
const mp_obj_property_t supervisor_runtime_serial2_bytes_available_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&supervisor_runtime_get_serial2_bytes_available_obj,
|
||||
(mp_obj_t)&mp_const_none_obj,
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
@ -100,26 +153,28 @@ const mp_obj_property_t supervisor_serial_bytes_available_obj = {
|
||||
//| run_reason: RunReason
|
||||
//| """Returns why CircuitPython started running this particular time."""
|
||||
//|
|
||||
STATIC mp_obj_t supervisor_get_run_reason(mp_obj_t self) {
|
||||
STATIC mp_obj_t supervisor_runtime_get_run_reason(mp_obj_t self) {
|
||||
return cp_enum_find(&supervisor_run_reason_type, _run_reason);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(supervisor_get_run_reason_obj, supervisor_get_run_reason);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_run_reason_obj, supervisor_runtime_get_run_reason);
|
||||
|
||||
const mp_obj_property_t supervisor_run_reason_obj = {
|
||||
const mp_obj_property_t supervisor_runtime_run_reason_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&supervisor_get_run_reason_obj,
|
||||
.proxy = {(mp_obj_t)&supervisor_runtime_get_run_reason_obj,
|
||||
(mp_obj_t)&mp_const_none_obj,
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
void supervisor_set_run_reason(supervisor_run_reason_t run_reason) {
|
||||
void supervisor_runtime_set_run_reason(supervisor_runtime_run_reason_t run_reason) {
|
||||
_run_reason = run_reason;
|
||||
}
|
||||
|
||||
STATIC const mp_rom_map_elem_t supervisor_runtime_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_serial_connected), MP_ROM_PTR(&supervisor_serial_connected_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_serial_bytes_available), MP_ROM_PTR(&supervisor_serial_bytes_available_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_run_reason), MP_ROM_PTR(&supervisor_run_reason_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_serial_connected), MP_ROM_PTR(&supervisor_runtime_serial_connected_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_serial2_connected), MP_ROM_PTR(&supervisor_runtime_serial2_connected_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_serial_bytes_available), MP_ROM_PTR(&supervisor_runtime_serial_bytes_available_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_serial2_bytes_available), MP_ROM_PTR(&supervisor_runtime_serial2_bytes_available_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_run_reason), MP_ROM_PTR(&supervisor_runtime_run_reason_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(supervisor_runtime_locals_dict, supervisor_runtime_locals_dict_table);
|
||||
|
@ -36,12 +36,12 @@ extern const mp_obj_type_t supervisor_runtime_type;
|
||||
|
||||
void supervisor_set_run_reason(supervisor_run_reason_t run_reason);
|
||||
|
||||
bool common_hal_get_serial_connected(void);
|
||||
bool common_hal_supervisor_runtime_get_serial_connected(void);
|
||||
|
||||
bool common_hal_get_serial_bytes_available(void);
|
||||
bool common_hal_supervisor_runtime_get_serial_bytes_available(void);
|
||||
|
||||
//TODO: placeholders for future functions
|
||||
//bool common_hal_get_repl_active(void);
|
||||
//bool common_hal_get_usb_enumerated(void);
|
||||
//bool common_hal_get_supervisor_runtime_repl_active(void);
|
||||
//bool common_hal_get_supervisor_runtime_usb_enumerated(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR_RUNTIME_H
|
||||
|
@ -94,7 +94,6 @@ bool serial_bytes_available(void) {
|
||||
return tud_cdc_available() > 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void serial_write_substring(const char* text, uint32_t length) {
|
||||
if (length == 0) {
|
||||
return;
|
||||
@ -119,3 +118,13 @@ void serial_write_substring(const char* text, uint32_t length) {
|
||||
void serial_write(const char* text) {
|
||||
serial_write_substring(text, strlen(text));
|
||||
}
|
||||
|
||||
#if CIRCUITPY_USB_SERIAL2
|
||||
bool serial2_bytes_available(void) {
|
||||
return tud_cdc_n_available(1) > 0;
|
||||
}
|
||||
|
||||
bool serial2_connected(void) {
|
||||
return tud_cdc_n_connected(1);
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user