Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 8:6c5fa976a1e3, committed 2016-04-27
- Comitter:
- Colin Hogben
- Date:
- Wed Apr 27 19:58:16 2016 +0100
- Parent:
- 7:379d46fd02c2
- Child:
- 9:88f582853243
- Commit message:
- Use MicroPython's printf; more DigitalOut methods
Changed in this revision
--- a/genhdr/qstrdefs.generated.h Tue Apr 26 22:50:06 2016 +0100 +++ b/genhdr/qstrdefs.generated.h Wed Apr 27 19:58:16 2016 +0100 @@ -2373,7 +2373,9 @@ #if (MICROPY_PY_BUILTINS_SET) QDEF(MP_QSTR_intersection_update, (const byte*)"\x06\xdd\x13" "intersection_update") #endif -#if (MICROPY_PY_MBED) && (MICROPY_MBED_DIGITALIN) +#if (MICROPY_PY_MBED) && (MICROPY_MBED_DIGITALOUT) +QDEF(MP_QSTR_is_connected, (const byte*)"\x1f\xcb\x0c" "is_connected") +#elif (MICROPY_PY_MBED) && (MICROPY_MBED_DIGITALIN) QDEF(MP_QSTR_is_connected, (const byte*)"\x1f\xcb\x0c" "is_connected") #endif QDEF(MP_QSTR_isalpha, (const byte*)"\xeb\x37\x07" "isalpha") @@ -2753,6 +2755,8 @@ #endif #if (MICROPY_PY_IO) QDEF(MP_QSTR_read, (const byte*)"\xb7\xf9\x04" "read") +#elif (MICROPY_PY_MBED) && (MICROPY_MBED_DIGITALOUT) +QDEF(MP_QSTR_read, (const byte*)"\xb7\xf9\x04" "read") #elif (MICROPY_PY_MBED) && (MICROPY_MBED_DIGITALIN) QDEF(MP_QSTR_read, (const byte*)"\xb7\xf9\x04" "read") #endif
--- a/modmbed.c Tue Apr 26 22:50:06 2016 +0100
+++ b/modmbed.c Wed Apr 27 19:58:16 2016 +0100
@@ -45,9 +45,15 @@
//-----------------------------------------------------------------------
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mbed_DigitalOut_write_obj,
mbed_DigitalOut_write);
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(mbed_DigitalOut_read_obj,
+ mbed_DigitalOut_read);
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(mbed_DigitalOut_is_connected_obj,
+ mbed_DigitalOut_is_connected);
STATIC const mp_map_elem_t mbed_DigitalOut_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mbed_DigitalOut_write_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mbed_DigitalOut_read_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_is_connected), (mp_obj_t)&mbed_DigitalOut_is_connected_obj },
};
STATIC MP_DEFINE_CONST_DICT(mbed_DigitalOut_locals_dict,
@@ -76,7 +82,7 @@
STATIC const mp_map_elem_t mbed_DigitalIn_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mbed_DigitalIn_read_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_mode), (mp_obj_t)&mbed_DigitalIn_read_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_mode), (mp_obj_t)&mbed_DigitalIn_mode_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_is_connected), (mp_obj_t)&mbed_DigitalIn_is_connected_obj },
};
--- a/modmbed_i.cpp Tue Apr 26 22:50:06 2016 +0100
+++ b/modmbed_i.cpp Wed Apr 27 19:58:16 2016 +0100
@@ -91,6 +91,18 @@
return mp_const_none;
}
+mp_obj_t mbed_DigitalOut_read(mp_obj_t self_in) {
+ mbed_DigitalOut_obj_t *self = (mbed_DigitalOut_obj_t *)self_in;
+ int value = self->dout->read(); // 0 or 1
+ return MP_OBJ_NEW_SMALL_INT(value);
+}
+
+mp_obj_t mbed_DigitalOut_is_connected(mp_obj_t self_in) {
+ mbed_DigitalOut_obj_t *self = (mbed_DigitalOut_obj_t *)self_in;
+ int conn = self->dout->is_connected();
+ return conn ? mp_const_true : mp_const_false;
+}
+
#if MICROPY_MBED_DIGITALIN
//-----------------------------------------------------------------------
// DigitalIn
--- a/modmbed_i.h Tue Apr 26 22:50:06 2016 +0100 +++ b/modmbed_i.h Wed Apr 27 19:58:16 2016 +0100 @@ -35,6 +35,8 @@ extern const mp_obj_type_t mbed_DigitalOut_type; extern mp_obj_t mbed_DigitalOut_make_new(const mp_obj_type_t *, mp_uint_t, mp_uint_t, const mp_obj_t *); extern mp_obj_t mbed_DigitalOut_write(mp_obj_t self_in, mp_obj_t value_in); +extern mp_obj_t mbed_DigitalOut_read(mp_obj_t self_in); +extern mp_obj_t mbed_DigitalOut_is_connected(mp_obj_t self_in); // DigitalIn extern const mp_obj_type_t mbed_DigitalIn_type;
--- a/mpconfigport.h Tue Apr 26 22:50:06 2016 +0100 +++ b/mpconfigport.h Wed Apr 27 19:58:16 2016 +0100 @@ -26,6 +26,14 @@ */ #include <stdint.h> +// mbed's printf outputs to USB serial but does not do LF->CRLF conversion. +// Ensure lib/utils/printf.c implementation is used instead. +// But not for C++ where cstdio would get upset. +#ifndef __cplusplus +extern int mp__printf(const char *, ...); +#define printf mp__printf +#endif + // options to control how Micro Python is built // The mbed online compiler uses different assembler syntax, so avoid