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 7:379d46fd02c2, committed 2016-04-26
- Comitter:
- Colin Hogben
- Date:
- Tue Apr 26 22:50:06 2016 +0100
- Parent:
- 6:3e98ebcedb4c
- Child:
- 8:6c5fa976a1e3
- Commit message:
- Add help, DigitalIn etc.
Changed in this revision
--- a/genhdr/qstrdefs.generated.h Mon Apr 25 19:55:21 2016 +0100 +++ b/genhdr/qstrdefs.generated.h Tue Apr 26 22:50:06 2016 +0100 @@ -217,9 +217,12 @@ #if (defined(TARGET_K64F)) QDEF(MP_QSTR_DAC0_OUT, (const byte*)"\xc2\x01\x08" "DAC0_OUT") #endif -#if (MICROPY_PY_MBED) -QDEF(MP_QSTR_DigitalOut, (const byte*)"\x11\xcb\x0a" "DigitalOut") -#elif (MICROPY_PY_MBED) && (MICROPY_MBED_DIGITALOUT) +#if (MICROPY_PY_MBED) && (MICROPY_MBED_DIGITALIN) +QDEF(MP_QSTR_DigitalIn, (const byte*)"\x18\x73\x09" "DigitalIn") +#elif (MICROPY_PY_MBED) && (MICROPY_MBED_DIGITALIN) +QDEF(MP_QSTR_DigitalIn, (const byte*)"\x18\x73\x09" "DigitalIn") +#endif +#if (MICROPY_PY_MBED) && (MICROPY_MBED_DIGITALOUT) QDEF(MP_QSTR_DigitalOut, (const byte*)"\x11\xcb\x0a" "DigitalOut") #elif (MICROPY_PY_MBED) && (MICROPY_MBED_DIGITALOUT) QDEF(MP_QSTR_DigitalOut, (const byte*)"\x11\xcb\x0a" "DigitalOut") @@ -263,11 +266,11 @@ QDEF(MP_QSTR_LED1, (const byte*)"\xb9\x6d\x04" "LED1") #elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && (defined(TARGET_LPC1768)) && (defined(MCB1700)) QDEF(MP_QSTR_LED1, (const byte*)"\xb9\x6d\x04" "LED1") -#elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && (defined(TARGET_LPC1768)) && (defined(MCB1700)) +#elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && (defined(TARGET_LPC1768)) && !(defined(MCB1700)) && (1) QDEF(MP_QSTR_LED1, (const byte*)"\xb9\x6d\x04" "LED1") #elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && !(defined(TARGET_LPC1768)) && (defined(TARGET_NUCLEO_F401RE)) QDEF(MP_QSTR_LED1, (const byte*)"\xb9\x6d\x04" "LED1") -#elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && !(defined(TARGET_LPC1768)) && (defined(TARGET_NUCLEO_F401RE)) +#elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && !(defined(TARGET_LPC1768)) && !(defined(TARGET_NUCLEO_F401RE)) && (1) QDEF(MP_QSTR_LED1, (const byte*)"\xb9\x6d\x04" "LED1") #endif #if (defined(TARGET_K64F)) @@ -276,7 +279,7 @@ QDEF(MP_QSTR_LED2, (const byte*)"\xba\x6d\x04" "LED2") #elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && (defined(TARGET_LPC1768)) && (defined(MCB1700)) QDEF(MP_QSTR_LED2, (const byte*)"\xba\x6d\x04" "LED2") -#elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && (defined(TARGET_LPC1768)) && (defined(MCB1700)) +#elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && (defined(TARGET_LPC1768)) && !(defined(MCB1700)) && (1) QDEF(MP_QSTR_LED2, (const byte*)"\xba\x6d\x04" "LED2") #elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && !(defined(TARGET_LPC1768)) && (defined(TARGET_NUCLEO_F401RE)) QDEF(MP_QSTR_LED2, (const byte*)"\xba\x6d\x04" "LED2") @@ -287,7 +290,7 @@ QDEF(MP_QSTR_LED3, (const byte*)"\xbb\x6d\x04" "LED3") #elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && (defined(TARGET_LPC1768)) && (defined(MCB1700)) QDEF(MP_QSTR_LED3, (const byte*)"\xbb\x6d\x04" "LED3") -#elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && (defined(TARGET_LPC1768)) && (defined(MCB1700)) +#elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && (defined(TARGET_LPC1768)) && !(defined(MCB1700)) && (1) QDEF(MP_QSTR_LED3, (const byte*)"\xbb\x6d\x04" "LED3") #elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && !(defined(TARGET_LPC1768)) && (defined(TARGET_NUCLEO_F401RE)) QDEF(MP_QSTR_LED3, (const byte*)"\xbb\x6d\x04" "LED3") @@ -298,29 +301,23 @@ QDEF(MP_QSTR_LED4, (const byte*)"\xbc\x6d\x04" "LED4") #elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && (defined(TARGET_LPC1768)) && (defined(MCB1700)) QDEF(MP_QSTR_LED4, (const byte*)"\xbc\x6d\x04" "LED4") -#elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && (defined(TARGET_LPC1768)) && (defined(MCB1700)) +#elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && (defined(TARGET_LPC1768)) && !(defined(MCB1700)) && (1) QDEF(MP_QSTR_LED4, (const byte*)"\xbc\x6d\x04" "LED4") #elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && !(defined(TARGET_LPC1768)) && (defined(TARGET_NUCLEO_F401RE)) QDEF(MP_QSTR_LED4, (const byte*)"\xbc\x6d\x04" "LED4") #endif #if (defined(TARGET_K64F)) QDEF(MP_QSTR_LED_BLUE, (const byte*)"\x69\x98\x08" "LED_BLUE") -#elif (defined(TARGET_K64F)) -QDEF(MP_QSTR_LED_BLUE, (const byte*)"\x69\x98\x08" "LED_BLUE") #elif !(defined(TARGET_K64F)) && (defined(TARGET_KL25Z)) QDEF(MP_QSTR_LED_BLUE, (const byte*)"\x69\x98\x08" "LED_BLUE") #endif #if (defined(TARGET_K64F)) QDEF(MP_QSTR_LED_GREEN, (const byte*)"\x4c\x68\x09" "LED_GREEN") -#elif (defined(TARGET_K64F)) -QDEF(MP_QSTR_LED_GREEN, (const byte*)"\x4c\x68\x09" "LED_GREEN") #elif !(defined(TARGET_K64F)) && (defined(TARGET_KL25Z)) QDEF(MP_QSTR_LED_GREEN, (const byte*)"\x4c\x68\x09" "LED_GREEN") #endif #if (defined(TARGET_K64F)) QDEF(MP_QSTR_LED_RED, (const byte*)"\x84\xfd\x07" "LED_RED") -#elif (defined(TARGET_K64F)) -QDEF(MP_QSTR_LED_RED, (const byte*)"\x84\xfd\x07" "LED_RED") #elif !(defined(TARGET_K64F)) && (defined(TARGET_KL25Z)) QDEF(MP_QSTR_LED_RED, (const byte*)"\x84\xfd\x07" "LED_RED") #endif @@ -334,7 +331,7 @@ QDEF(MP_QSTR_NC, (const byte*)"\x08\x73\x02" "NC") #elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && !(defined(TARGET_LPC1768)) && (defined(TARGET_NUCLEO_F401RE)) QDEF(MP_QSTR_NC, (const byte*)"\x08\x73\x02" "NC") -#elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && !(defined(TARGET_LPC1768)) && (defined(TARGET_NUCLEO_F401RE)) +#elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && !(defined(TARGET_LPC1768)) && !(defined(TARGET_NUCLEO_F401RE)) && (1) QDEF(MP_QSTR_NC, (const byte*)"\x08\x73\x02" "NC") #endif QDEF(MP_QSTR_NameError, (const byte*)"\xba\x2d\x09" "NameError") @@ -987,8 +984,6 @@ #endif #if (defined(TARGET_K64F)) QDEF(MP_QSTR_PTA0, (const byte*)"\x90\xa0\x04" "PTA0") -#elif (defined(TARGET_K64F)) -QDEF(MP_QSTR_PTA0, (const byte*)"\x90\xa0\x04" "PTA0") #elif !(defined(TARGET_K64F)) && (defined(TARGET_KL25Z)) QDEF(MP_QSTR_PTA0, (const byte*)"\x90\xa0\x04" "PTA0") #endif @@ -1815,9 +1810,7 @@ #if (defined(TARGET_K64F)) QDEF(MP_QSTR_SW3, (const byte*)"\x32\x11\x03" "SW3") #endif -#if (MICROPY_PY_MBED) -QDEF(MP_QSTR_Serial, (const byte*)"\xe5\xe5\x06" "Serial") -#elif (MICROPY_PY_MBED) && (MICROPY_MBED_SERIAL) +#if (MICROPY_PY_MBED) && (MICROPY_MBED_SERIAL) QDEF(MP_QSTR_Serial, (const byte*)"\xe5\xe5\x06" "Serial") #elif (MICROPY_PY_MBED) && (MICROPY_MBED_SERIAL) QDEF(MP_QSTR_Serial, (const byte*)"\xe5\xe5\x06" "Serial") @@ -1847,28 +1840,24 @@ QDEF(MP_QSTR_TypeError, (const byte*)"\x25\x96\x09" "TypeError") #if (defined(TARGET_K64F)) QDEF(MP_QSTR_USBRX, (const byte*)"\xcb\xf6\x05" "USBRX") -#elif (defined(TARGET_K64F)) -QDEF(MP_QSTR_USBRX, (const byte*)"\xcb\xf6\x05" "USBRX") #elif !(defined(TARGET_K64F)) && (defined(TARGET_KL25Z)) QDEF(MP_QSTR_USBRX, (const byte*)"\xcb\xf6\x05" "USBRX") #elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && (defined(TARGET_LPC1768)) QDEF(MP_QSTR_USBRX, (const byte*)"\xcb\xf6\x05" "USBRX") #elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && !(defined(TARGET_LPC1768)) && (defined(TARGET_NUCLEO_F401RE)) QDEF(MP_QSTR_USBRX, (const byte*)"\xcb\xf6\x05" "USBRX") -#elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && !(defined(TARGET_LPC1768)) && (defined(TARGET_NUCLEO_F401RE)) +#elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && !(defined(TARGET_LPC1768)) && !(defined(TARGET_NUCLEO_F401RE)) && (1) QDEF(MP_QSTR_USBRX, (const byte*)"\xcb\xf6\x05" "USBRX") #endif #if (defined(TARGET_K64F)) QDEF(MP_QSTR_USBTX, (const byte*)"\x8d\xf6\x05" "USBTX") -#elif (defined(TARGET_K64F)) -QDEF(MP_QSTR_USBTX, (const byte*)"\x8d\xf6\x05" "USBTX") #elif !(defined(TARGET_K64F)) && (defined(TARGET_KL25Z)) QDEF(MP_QSTR_USBTX, (const byte*)"\x8d\xf6\x05" "USBTX") #elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && (defined(TARGET_LPC1768)) QDEF(MP_QSTR_USBTX, (const byte*)"\x8d\xf6\x05" "USBTX") #elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && !(defined(TARGET_LPC1768)) && (defined(TARGET_NUCLEO_F401RE)) QDEF(MP_QSTR_USBTX, (const byte*)"\x8d\xf6\x05" "USBTX") -#elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && !(defined(TARGET_LPC1768)) && (defined(TARGET_NUCLEO_F401RE)) +#elif !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && !(defined(TARGET_LPC1768)) && !(defined(TARGET_NUCLEO_F401RE)) && (1) QDEF(MP_QSTR_USBTX, (const byte*)"\x8d\xf6\x05" "USBTX") #endif #if !(defined(TARGET_K64F)) && !(defined(TARGET_KL25Z)) && !(defined(TARGET_LPC1768)) && (defined(TARGET_NUCLEO_F401RE)) @@ -2113,7 +2102,10 @@ #if (MICROPY_EMIT_INLINE_THUMB) QDEF(MP_QSTR_b, (const byte*)"\xc7\xb5\x01" "b") #endif -#if (MICROPY_PY_SYS) && (MP_ENDIANNESS_LITTLE) +#if (MICROPY_PY_MBED) && (MICROPY_MBED_SERIAL) +QDEF(MP_QSTR_baud, (const byte*)"\x37\x46\x04" "baud") +#endif +#if (MICROPY_PY_SYS) && !(MP_ENDIANNESS_LITTLE) && (1) QDEF(MP_QSTR_big, (const byte*)"\xe9\x48\x03" "big") #endif QDEF(MP_QSTR_bin, (const byte*)"\xe0\x48\x03" "bin") @@ -2136,7 +2128,7 @@ #endif #if (MICROPY_PY_SYS) && (MP_ENDIANNESS_LITTLE) QDEF(MP_QSTR_byteorder, (const byte*)"\x61\x99\x09" "byteorder") -#elif (MICROPY_PY_SYS) && (MP_ENDIANNESS_LITTLE) +#elif (MICROPY_PY_SYS) && !(MP_ENDIANNESS_LITTLE) && (1) QDEF(MP_QSTR_byteorder, (const byte*)"\x61\x99\x09" "byteorder") #endif QDEF(MP_QSTR_bytes, (const byte*)"\x5c\xb2\x05" "bytes") @@ -2345,9 +2337,7 @@ QDEF(MP_QSTR_generator, (const byte*)"\x96\xc3\x09" "generator") QDEF(MP_QSTR_get, (const byte*)"\x33\x3b\x03" "get") QDEF(MP_QSTR_getattr, (const byte*)"\xc0\x17\x07" "getattr") -#if (MICROPY_PY_MBED) -QDEF(MP_QSTR_getc, (const byte*)"\xf0\xa1\x04" "getc") -#elif (MICROPY_PY_MBED) && (MICROPY_MBED_SERIAL) +#if (MICROPY_PY_MBED) && (MICROPY_MBED_SERIAL) QDEF(MP_QSTR_getc, (const byte*)"\xf0\xa1\x04" "getc") #endif #if (MICROPY_PY_BUILTINS_PROPERTY) @@ -2365,6 +2355,7 @@ #if (MICROPY_ENABLE_GC) QDEF(MP_QSTR_heap_unlock, (const byte*)"\x56\x2d\x0b" "heap_unlock") #endif +QDEF(MP_QSTR_help, (const byte*)"\x94\x5c\x04" "help") QDEF(MP_QSTR_hex, (const byte*)"\x70\x50\x03" "hex") QDEF(MP_QSTR_id, (const byte*)"\x28\x6f\x02" "id") #if (MICROPY_PY_BUILTINS_COMPLEX) @@ -2382,6 +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) +QDEF(MP_QSTR_is_connected, (const byte*)"\x1f\xcb\x0c" "is_connected") +#endif QDEF(MP_QSTR_isalpha, (const byte*)"\xeb\x37\x07" "isalpha") QDEF(MP_QSTR_isdigit, (const byte*)"\xa8\x9a\x07" "isdigit") #if (MICROPY_PY_BUILTINS_SET) @@ -2481,6 +2475,8 @@ #endif #if (MICROPY_PY_MACHINE) QDEF(MP_QSTR_machine, (const byte*)"\x60\xab\x07" "machine") +#elif (MICROPY_PY_MACHINE) +QDEF(MP_QSTR_machine, (const byte*)"\x60\xab\x07" "machine") #endif QDEF(MP_QSTR_map, (const byte*)"\xb9\x43\x03" "map") #if (MICROPY_PY_BUILTINS_FLOAT && MICROPY_PY_MATH) @@ -2496,15 +2492,13 @@ QDEF(MP_QSTR_maximum_space_recursion_space_depth_space_exceeded, (const byte*)"\x73\x1e\x20" "maximum recursion depth exceeded") #if (MICROPY_PY_SYS) && (MICROPY_PY_SYS_MAXSIZE) && (MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE) QDEF(MP_QSTR_maxsize, (const byte*)"\xd4\x70\x07" "maxsize") -#elif (MICROPY_PY_SYS) && (MICROPY_PY_SYS_MAXSIZE) && (MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE) +#elif (MICROPY_PY_SYS) && (MICROPY_PY_SYS_MAXSIZE) && !(MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE) && (1) QDEF(MP_QSTR_maxsize, (const byte*)"\xd4\x70\x07" "maxsize") #endif #if (MICROPY_PY_MBED) QDEF(MP_QSTR_mbed, (const byte*)"\x0b\xb5\x04" "mbed") #elif (MICROPY_PY_MBED) QDEF(MP_QSTR_mbed, (const byte*)"\x0b\xb5\x04" "mbed") -#elif (MICROPY_PY_MBED) -QDEF(MP_QSTR_mbed, (const byte*)"\x0b\xb5\x04" "mbed") #endif #if (MICROPY_PY_MACHINE) QDEF(MP_QSTR_mem, (const byte*)"\x20\x44\x03" "mem") @@ -2545,6 +2539,9 @@ #if (MICROPY_PY_BUILTINS_MIN_MAX) QDEF(MP_QSTR_min, (const byte*)"\xaf\x42\x03" "min") #endif +#if (MICROPY_PY_MBED) && (MICROPY_MBED_DIGITALIN) +QDEF(MP_QSTR_mode, (const byte*)"\x26\xc0\x04" "mode") +#endif #if (MICROPY_PY_BUILTINS_FLOAT && MICROPY_PY_MATH) QDEF(MP_QSTR_modf, (const byte*)"\x25\xc0\x04" "modf") #endif @@ -2684,7 +2681,11 @@ #elif (MICROPY_PY_BUILTINS_FLOAT && MICROPY_PY_MATH) QDEF(MP_QSTR_pi, (const byte*)"\x1c\x70\x02" "pi") #endif +#if (MICROPY_PY_PINS) QDEF(MP_QSTR_pins, (const byte*)"\x41\xf2\x04" "pins") +#elif (MICROPY_PY_PINS) +QDEF(MP_QSTR_pins, (const byte*)"\x41\xf2\x04" "pins") +#endif #if (MICROPY_PY_SYS) && (defined(MICROPY_PY_SYS_PLATFORM)) QDEF(MP_QSTR_platform, (const byte*)"\x3a\x19\x08" "platform") #endif @@ -2734,14 +2735,10 @@ #if (MICROPY_EMIT_INLINE_THUMB) QDEF(MP_QSTR_push, (const byte*)"\xbb\x7e\x04" "push") #endif -#if (MICROPY_PY_MBED) -QDEF(MP_QSTR_putc, (const byte*)"\x97\x7e\x04" "putc") -#elif (MICROPY_PY_MBED) && (MICROPY_MBED_SERIAL) +#if (MICROPY_PY_MBED) && (MICROPY_MBED_SERIAL) QDEF(MP_QSTR_putc, (const byte*)"\x97\x7e\x04" "putc") #endif -#if (MICROPY_PY_MBED) -QDEF(MP_QSTR_puts, (const byte*)"\x87\x7e\x04" "puts") -#elif (MICROPY_PY_MBED) && (MICROPY_MBED_SERIAL) +#if (MICROPY_PY_MBED) && (MICROPY_MBED_SERIAL) QDEF(MP_QSTR_puts, (const byte*)"\x87\x7e\x04" "puts") #endif #if (MICROPY_PY_MICROPYTHON_MEM_INFO) @@ -2756,6 +2753,11 @@ #endif #if (MICROPY_PY_IO) 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 +#if (MICROPY_PY_MBED) && (MICROPY_MBED_SERIAL) +QDEF(MP_QSTR_readable, (const byte*)"\x5d\x91\x08" "readable") #endif #if (MICROPY_PY_IO) QDEF(MP_QSTR_readall, (const byte*)"\x76\x4b\x07" "readall") @@ -2774,8 +2776,6 @@ QDEF(MP_QSTR_repr, (const byte*)"\xd0\xf7\x04" "repr") #if (MICROPY_PY_MACHINE) QDEF(MP_QSTR_reset, (const byte*)"\x10\xf4\x05" "reset") -#elif (MICROPY_PY_MACHINE) -QDEF(MP_QSTR_reset, (const byte*)"\x10\xf4\x05" "reset") #endif QDEF(MP_QSTR_reverse, (const byte*)"\x25\x2a\x07" "reverse") #if (MICROPY_PY_BUILTINS_REVERSED) @@ -2793,6 +2793,9 @@ QDEF(MP_QSTR_sdiv, (const byte*)"\xcd\x7a\x04" "sdiv") #endif QDEF(MP_QSTR_send, (const byte*)"\xb9\x76\x04" "send") +#if (MICROPY_PY_MBED) && (MICROPY_MBED_SERIAL) +QDEF(MP_QSTR_send_break, (const byte*)"\x19\x62\x0a" "send_break") +#endif QDEF(MP_QSTR_sep, (const byte*)"\x23\x8f\x03" "sep") #if (MICROPY_PY_BUILTINS_SET) QDEF(MP_QSTR_set, (const byte*)"\x27\x8f\x03" "set") @@ -2941,11 +2944,6 @@ #if (MICROPY_PY_UJSON) QDEF(MP_QSTR_ujson, (const byte*)"\xe8\x30\x05" "ujson") #endif -#if (MICROPY_PY_MACHINE) -QDEF(MP_QSTR_umachine, (const byte*)"\x95\x7f\x08" "umachine") -#elif (MICROPY_PY_MACHINE) -QDEF(MP_QSTR_umachine, (const byte*)"\x95\x7f\x08" "umachine") -#endif #if (MICROPY_PY_BUILTINS_SET) QDEF(MP_QSTR_union, (const byte*)"\xf6\x7c\x05" "union") #endif @@ -3017,6 +3015,15 @@ #if (MICROPY_EMIT_INLINE_THUMB) && (MICROPY_EMIT_INLINE_THUMB_FLOAT) QDEF(MP_QSTR_vstr, (const byte*)"\xc6\x7e\x04" "vstr") #endif +#if (MICROPY_PY_MBED) && (MICROPY_PY_BUILTINS_FLOAT) +QDEF(MP_QSTR_wait, (const byte*)"\x8e\x55\x04" "wait") +#endif +#if (MICROPY_PY_MBED) +QDEF(MP_QSTR_wait_ms, (const byte*)"\xaf\x14\x07" "wait_ms") +#endif +#if (MICROPY_PY_MBED) +QDEF(MP_QSTR_wait_us, (const byte*)"\xb7\x11\x07" "wait_us") +#endif #if (MICROPY_PY_WEBSOCKET) QDEF(MP_QSTR_websocket, (const byte*)"\x90\x8d\x09" "websocket") #endif @@ -3027,10 +3034,11 @@ QDEF(MP_QSTR_write, (const byte*)"\x98\xa8\x05" "write") #elif (MICROPY_PY_IO) QDEF(MP_QSTR_write, (const byte*)"\x98\xa8\x05" "write") -#elif (MICROPY_PY_MBED) -QDEF(MP_QSTR_write, (const byte*)"\x98\xa8\x05" "write") #elif (MICROPY_PY_MBED) && (MICROPY_MBED_DIGITALOUT) QDEF(MP_QSTR_write, (const byte*)"\x98\xa8\x05" "write") #endif +#if (MICROPY_PY_MBED) && (MICROPY_MBED_SERIAL) +QDEF(MP_QSTR_writeable, (const byte*)"\xf2\x01\x09" "writeable") +#endif QDEF(MP_QSTR_xxxx, (const byte*)"\x05\xcd\x04" "xxxx") QDEF(MP_QSTR_zip, (const byte*)"\xe6\xac\x03" "zip")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/utils/printf.c Tue Apr 26 22:50:06 2016 +0100
@@ -0,0 +1,129 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2013, 2014 Damien P. George
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stdint.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include "py/obj.h"
+#include "py/mphal.h"
+
+#if MICROPY_PY_BUILTINS_FLOAT
+#include "py/formatfloat.h"
+#endif
+
+#undef putchar // Some stdlibs have a #define for putchar
+int printf(const char *fmt, ...);
+int vprintf(const char *fmt, va_list ap);
+int putchar(int c);
+int puts(const char *s);
+int vsnprintf(char *str, size_t size, const char *fmt, va_list ap);
+int snprintf(char *str, size_t size, const char *fmt, ...);
+
+int printf(const char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ int ret = mp_vprintf(&mp_plat_print, fmt, ap);
+ va_end(ap);
+ return ret;
+}
+
+int vprintf(const char *fmt, va_list ap) {
+ return mp_vprintf(&mp_plat_print, fmt, ap);
+}
+
+#if MICROPY_DEBUG_PRINTERS
+int DEBUG_printf(const char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ #ifndef MICROPY_DEBUG_PRINTER_DEST
+ #define MICROPY_DEBUG_PRINTER_DEST mp_plat_print
+ #endif
+ extern const mp_print_t MICROPY_DEBUG_PRINTER_DEST;
+ int ret = mp_vprintf(&MICROPY_DEBUG_PRINTER_DEST, fmt, ap);
+ va_end(ap);
+ return ret;
+}
+#endif
+
+// need this because gcc optimises printf("%c", c) -> putchar(c), and printf("a") -> putchar('a')
+int putchar(int c) {
+ char chr = c;
+ mp_hal_stdout_tx_strn_cooked(&chr, 1);
+ return chr;
+}
+
+// need this because gcc optimises printf("string\n") -> puts("string")
+int puts(const char *s) {
+ mp_hal_stdout_tx_strn_cooked(s, strlen(s));
+ char chr = '\n';
+ mp_hal_stdout_tx_strn_cooked(&chr, 1);
+ return 1;
+}
+
+typedef struct _strn_print_env_t {
+ char *cur;
+ size_t remain;
+} strn_print_env_t;
+
+STATIC void strn_print_strn(void *data, const char *str, size_t len) {
+ strn_print_env_t *strn_print_env = data;
+ if (len > strn_print_env->remain) {
+ len = strn_print_env->remain;
+ }
+ memcpy(strn_print_env->cur, str, len);
+ strn_print_env->cur += len;
+ strn_print_env->remain -= len;
+}
+
+#if defined(__GNUC__) && !defined(__clang__)
+// uClibc requires this alias to be defined, or there may be link errors
+// when linkings against it statically.
+int __GI_vsnprintf(char *str, size_t size, const char *fmt, va_list ap) __attribute__((weak, alias ("vsnprintf")));
+#endif
+
+int vsnprintf(char *str, size_t size, const char *fmt, va_list ap) {
+ strn_print_env_t strn_print_env = {str, size};
+ mp_print_t print = {&strn_print_env, strn_print_strn};
+ int len = mp_vprintf(&print, fmt, ap);
+ // add terminating null byte
+ if (size > 0) {
+ if (strn_print_env.remain == 0) {
+ strn_print_env.cur[-1] = 0;
+ } else {
+ strn_print_env.cur[0] = 0;
+ }
+ }
+ return len;
+}
+
+int snprintf(char *str, size_t size, const char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ int ret = vsnprintf(str, size, fmt, ap);
+ va_end(ap);
+ return ret;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/utils/pyhelp.c Tue Apr 26 22:50:06 2016 +0100
@@ -0,0 +1,85 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2013-2016 Damien P. George
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stdio.h>
+
+#include "lib/utils/pyhelp.h"
+
+STATIC void pyhelp_print_info_about_object(mp_obj_t name_o, mp_obj_t value) {
+ printf(" ");
+ mp_obj_print(name_o, PRINT_STR);
+ printf(" -- ");
+ mp_obj_print(value, PRINT_STR);
+ printf("\n");
+}
+
+// Helper for 1-argument form of builtin help
+//
+// Typically a port will define a help function thus:
+//
+// STATIC const char *const myport_help_text =
+// "Welcome to MicroPython!\n"
+// "\n"
+// "...information specific to this port e.g. modules available...";
+//
+// STATIC mp_obj_t myport_help(mp_uint_t n_args, const mp_obj_t *args) {
+// if (n_args == 0) {
+// printf("%s", myport_help_text);
+// } else {
+// pyhelp_print_obj(args[0]);
+// }
+// return mp_const_none;
+// }
+// MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_help_obj, 0, 1, myport_help);
+//
+void pyhelp_print_obj(const mp_obj_t obj) {
+ // try to print something sensible about the given object
+ printf("object ");
+ mp_obj_print(obj, PRINT_STR);
+ printf(" is of type %s\n", mp_obj_get_type_str(obj));
+
+ mp_map_t *map = NULL;
+ if (MP_OBJ_IS_TYPE(obj, &mp_type_module)) {
+ map = mp_obj_dict_get_map(mp_obj_module_get_globals(obj));
+ } else {
+ mp_obj_type_t *type;
+ if (MP_OBJ_IS_TYPE(obj, &mp_type_type)) {
+ type = obj;
+ } else {
+ type = mp_obj_get_type(obj);
+ }
+ if (type->locals_dict != MP_OBJ_NULL && MP_OBJ_IS_TYPE(type->locals_dict, &mp_type_dict)) {
+ map = mp_obj_dict_get_map(type->locals_dict);
+ }
+ }
+ if (map != NULL) {
+ for (uint i = 0; i < map->alloc; i++) {
+ if (map->table[i].key != MP_OBJ_NULL) {
+ pyhelp_print_info_about_object(map->table[i].key, map->table[i].value);
+ }
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/utils/pyhelp.h Tue Apr 26 22:50:06 2016 +0100 @@ -0,0 +1,33 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013-2016 Damien P. George + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef __MICROPY_INCLUDED_LIB_UTILS_PYHELP_H__ +#define __MICROPY_INCLUDED_LIB_UTILS_PYHELP_H__ + +#include "py/obj.h" + +void pyhelp_print_obj(const mp_obj_t obj); + +#endif // __MICROPY_INCLUDED_LIB_UTILS_PYHELP_H__
--- a/modmachine.c Mon Apr 25 19:55:21 2016 +0100
+++ b/modmachine.c Tue Apr 26 22:50:06 2016 +0100
@@ -50,7 +50,7 @@
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
- { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) },
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) },
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) },
{ MP_ROM_QSTR(MP_QSTR_mem8), MP_ROM_PTR(&machine_mem8_obj) },
{ MP_ROM_QSTR(MP_QSTR_mem16), MP_ROM_PTR(&machine_mem16_obj) },
@@ -61,7 +61,7 @@
const mp_obj_module_t mp_module_machine = {
.base = { &mp_type_module },
- .name = MP_QSTR_umachine,
+ .name = MP_QSTR_machine,
.globals = (mp_obj_dict_t*)&machine_module_globals,
};
--- a/modmbed.c Mon Apr 25 19:55:21 2016 +0100
+++ b/modmbed.c Tue Apr 26 22:50:06 2016 +0100
@@ -30,80 +30,140 @@
#include "modmbed_i.h"
+#if MICROPY_PY_BUILTINS_FLOAT
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(mbed_wait_obj,
+ mbed_wait);
+#endif
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(mbed_wait_ms_obj,
+ mbed_wait_ms);
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(mbed_wait_us_obj,
+ mbed_wait_us);
+
#if MICROPY_MBED_DIGITALOUT
//-----------------------------------------------------------------------
-// DigitalOut class
+// DigitalOut class
//-----------------------------------------------------------------------
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mbed_DigitalOut_write_obj,
- mbed_DigitalOut_write);
+ mbed_DigitalOut_write);
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_write), (mp_obj_t)&mbed_DigitalOut_write_obj },
};
-
+
STATIC MP_DEFINE_CONST_DICT(mbed_DigitalOut_locals_dict,
- mbed_DigitalOut_locals_dict_table);
+ mbed_DigitalOut_locals_dict_table);
const mp_obj_type_t mbed_DigitalOut_type = {
- { &mp_type_type },
- .name = MP_QSTR_DigitalOut,
- // .print
- .make_new = mbed_DigitalOut_make_new,
- .locals_dict = (mp_obj_t)&mbed_DigitalOut_locals_dict,
+ { &mp_type_type },
+ .name = MP_QSTR_DigitalOut,
+ // .print
+ .make_new = mbed_DigitalOut_make_new,
+ .locals_dict = (mp_obj_t)&mbed_DigitalOut_locals_dict,
};
#endif // MICROPY_MBED_DIGITALOUT
+#if MICROPY_MBED_DIGITALIN
+//-----------------------------------------------------------------------
+// DigitalIn class
+//-----------------------------------------------------------------------
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(mbed_DigitalIn_read_obj,
+ mbed_DigitalIn_read);
+STATIC MP_DEFINE_CONST_FUN_OBJ_2(mbed_DigitalIn_mode_obj,
+ mbed_DigitalIn_mode);
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(mbed_DigitalIn_is_connected_obj,
+ mbed_DigitalIn_is_connected);
+
+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_is_connected), (mp_obj_t)&mbed_DigitalIn_is_connected_obj },
+};
+
+STATIC MP_DEFINE_CONST_DICT(mbed_DigitalIn_locals_dict,
+ mbed_DigitalIn_locals_dict_table);
+
+const mp_obj_type_t mbed_DigitalIn_type = {
+ { &mp_type_type },
+ .name = MP_QSTR_DigitalIn,
+ // .print
+ .make_new = mbed_DigitalIn_make_new,
+ .locals_dict = (mp_obj_t)&mbed_DigitalIn_locals_dict,
+};
+
+#endif // MICROPY_MBED_DIGITALIN
+
#if MICROPY_MBED_SERIAL
/*-----------------------------------------------------------------------
- * Serial class
+ * Serial class
*-----------------------------------------------------------------------*/
+STATIC MP_DEFINE_CONST_FUN_OBJ_2(mbed_Serial_baud_obj,
+ mbed_Serial_baud);
+STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mbed_Serial_format_obj, 1, 4,
+ mbed_Serial_format);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mbed_Serial_putc_obj,
- mbed_Serial_putc);
-
+ mbed_Serial_putc);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mbed_Serial_puts_obj,
- mbed_Serial_puts);
-
+ mbed_Serial_puts);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mbed_Serial_getc_obj,
- mbed_Serial_getc);
+ mbed_Serial_getc);
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(mbed_Serial_readable_obj,
+ mbed_Serial_readable);
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(mbed_Serial_writeable_obj,
+ mbed_Serial_writeable);
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(mbed_Serial_send_break_obj,
+ mbed_Serial_send_break);
STATIC const mp_map_elem_t mbed_Serial_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_putc), (mp_obj_t)&mbed_Serial_putc_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_puts), (mp_obj_t)&mbed_Serial_puts_obj },
- { MP_OBJ_NEW_QSTR(MP_QSTR_getc), (mp_obj_t)&mbed_Serial_getc_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_baud), (mp_obj_t)&mbed_Serial_baud_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_format), (mp_obj_t)&mbed_Serial_format_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_putc), (mp_obj_t)&mbed_Serial_putc_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_puts), (mp_obj_t)&mbed_Serial_puts_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_getc), (mp_obj_t)&mbed_Serial_getc_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_readable), (mp_obj_t)&mbed_Serial_readable_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_writeable), (mp_obj_t)&mbed_Serial_writeable_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_send_break), (mp_obj_t)&mbed_Serial_send_break_obj },
};
-
+
STATIC MP_DEFINE_CONST_DICT(mbed_Serial_locals_dict,
- mbed_Serial_locals_dict_table);
+ mbed_Serial_locals_dict_table);
const mp_obj_type_t mbed_Serial_type = {
- { &mp_type_type },
- .name = MP_QSTR_Serial,
- // .print
- .make_new = mbed_Serial_make_new,
- .locals_dict = (mp_obj_t)&mbed_Serial_locals_dict,
+ { &mp_type_type },
+ .name = MP_QSTR_Serial,
+ // .print
+ .make_new = mbed_Serial_make_new,
+ .locals_dict = (mp_obj_t)&mbed_Serial_locals_dict,
};
#endif // MICROPY_MBED_SERIAL
// Module
-STATIC const mp_rom_map_elem_t mp_mbed_module_globals_table[] = {
- { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_mbed) },
+STATIC const mp_rom_map_elem_t mbed_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_mbed) },
+#if MICROPY_PY_BUILTINS_FLOAT
+ { MP_ROM_QSTR(MP_QSTR_wait), MP_ROM_PTR(&mbed_wait_obj) },
+#endif
+ { MP_ROM_QSTR(MP_QSTR_wait_ms), MP_ROM_PTR(&mbed_wait_ms_obj) },
+ { MP_ROM_QSTR(MP_QSTR_wait_us), MP_ROM_PTR(&mbed_wait_us_obj) },
#if MICROPY_MBED_DIGITALOUT
- { MP_ROM_QSTR(MP_QSTR_DigitalOut), MP_ROM_PTR(&mbed_DigitalOut_type) },
+ { MP_ROM_QSTR(MP_QSTR_DigitalOut), MP_ROM_PTR(&mbed_DigitalOut_type) },
+#endif
+#if MICROPY_MBED_DIGITALIN
+ { MP_ROM_QSTR(MP_QSTR_DigitalIn), MP_ROM_PTR(&mbed_DigitalIn_type) },
#endif
#if MICROPY_MBED_SERIAL
- { MP_ROM_QSTR(MP_QSTR_Serial), MP_ROM_PTR(&mbed_Serial_type) },
+ { MP_ROM_QSTR(MP_QSTR_Serial), MP_ROM_PTR(&mbed_Serial_type) },
#endif
};
-STATIC MP_DEFINE_CONST_DICT(mp_mbed_module_globals,
- mp_mbed_module_globals_table);
+STATIC MP_DEFINE_CONST_DICT(mbed_module_globals,
+ mbed_module_globals_table);
const mp_obj_module_t mp_module_mbed = {
- .base = { &mp_type_module },
- .name = MP_QSTR_mbed,
- .globals = (mp_obj_dict_t *)&mp_mbed_module_globals,
+ .base = { &mp_type_module },
+ .name = MP_QSTR_mbed,
+ .globals = (mp_obj_dict_t *)&mbed_module_globals,
};
#endif
--- a/modmbed_i.cpp Mon Apr 25 19:55:21 2016 +0100
+++ b/modmbed_i.cpp Tue Apr 26 22:50:06 2016 +0100
@@ -35,85 +35,186 @@
#include "mbed.h"
extern "C" {
- #include "py/runtime.h"
- #include "modmbed_i.h"
+#include "py/runtime.h"
+#include "modmbed_i.h"
}
-typedef struct _mbed_DigitalOut_obj_t {
- mp_obj_base_t base;
- DigitalOut *dout;
-} mbed_DigitalOut_obj_t;
+//-----------------------------------------------------------------------
+// Functions
+//-----------------------------------------------------------------------
+#if MICROPY_PY_BUILTINS_FLOAT
+mp_obj_t mbed_wait(mp_obj_t s_in) {
+ mp_float_t s = mp_obj_get_float(s_in);
+ wait((float)s);
+ return mp_const_none;
+}
+#endif
+
+mp_obj_t mbed_wait_ms(mp_obj_t ms_in) {
+ int ms = mp_obj_get_int(ms_in);
+ wait_ms(ms);
+ return mp_const_none;
+}
+
+mp_obj_t mbed_wait_us(mp_obj_t us_in) {
+ int us = mp_obj_get_int(us_in);
+ wait_us(us);
+ return mp_const_none;
+}
+
+//-----------------------------------------------------------------------
+// DigitalOut
+//-----------------------------------------------------------------------
+struct mbed_DigitalOut_obj_t {
+ mp_obj_base_t base;
+ DigitalOut *dout;
+};
// constructor DigitalOut(pin)
mp_obj_t mbed_DigitalOut_make_new(const mp_obj_type_t *type,
- mp_uint_t n_args, mp_uint_t n_kw,
- const mp_obj_t *args)
-{
- (void)type;
- mp_arg_check_num(n_args, n_kw, 1, 1, false);
- int pin = mp_obj_get_int(args[0]);
+ mp_uint_t n_args, mp_uint_t n_kw,
+ const mp_obj_t *args) {
+ (void)type;
+ mp_arg_check_num(n_args, n_kw, 1, 1, false);
+ int pin = mp_obj_get_int(args[0]);
+ mbed_DigitalOut_obj_t *o =
+ m_new_obj_with_finaliser(mbed_DigitalOut_obj_t);
+ o->base.type = &mbed_DigitalOut_type;
+ o->dout = new DigitalOut((PinName)pin);
+ return o;
+}
- mbed_DigitalOut_obj_t *o = m_new_obj_with_finaliser(mbed_DigitalOut_obj_t);
- o->base.type = &mbed_DigitalOut_type;
- o->dout = new DigitalOut((PinName)pin);
-
- return o;
+mp_obj_t mbed_DigitalOut_write(mp_obj_t self_in, mp_obj_t value_in) {
+ mbed_DigitalOut_obj_t *self = (mbed_DigitalOut_obj_t *)self_in;
+ int value = mp_obj_get_int(value_in);
+ self->dout->write(value);
+ return mp_const_none;
}
-mp_obj_t mbed_DigitalOut_write(mp_obj_t self_in, mp_obj_t value_in)
+#if MICROPY_MBED_DIGITALIN
+//-----------------------------------------------------------------------
+// DigitalIn
+//-----------------------------------------------------------------------
+struct mbed_DigitalIn_obj_t {
+ mp_obj_base_t base;
+ DigitalIn *din;
+};
+
+mp_obj_t mbed_DigitalIn_make_new(const mp_obj_type_t *type,
+ size_t n_args, size_t n_kw,
+ const mp_obj_t *args)
{
- mbed_DigitalOut_obj_t *self = (mbed_DigitalOut_obj_t *)self_in;
- int value = mp_obj_get_int(value_in);
-
- self->dout->write(value);
- return mp_const_none;
+ (void)type;
+ mp_arg_check_num(n_args, n_kw, 1, 2, false);
+ int pin = mp_obj_get_int(args[0]);
+ int mode = (n_args == 2) ? mp_obj_get_int(args[1]) : 0;
+ mbed_DigitalIn_obj_t *o = m_new_obj_with_finaliser(mbed_DigitalIn_obj_t);
+ o->base.type = &mbed_DigitalIn_type;
+ if (n_args == 2) {
+ o->din = new DigitalIn((PinName)pin, (PinMode)mode);
+ } else {
+ o->din = new DigitalIn((PinName)pin);
+ }
+ return o;
}
-typedef struct _mbed_Serial_obj_t {
- mp_obj_base_t base;
- Serial *serial;
-} mbed_Serial_obj_t;
+mp_obj_t mbed_DigitalIn_read(mp_obj_t self_in) {
+ mbed_DigitalIn_obj_t *self = (mbed_DigitalIn_obj_t *)self_in;
+ int value = self->din->read(); // 0 or 1
+ return MP_OBJ_NEW_SMALL_INT(value);
+}
+
+mp_obj_t mbed_DigitalIn_mode(mp_obj_t self_in, mp_obj_t mode_in) {
+ mbed_DigitalIn_obj_t *self = (mbed_DigitalIn_obj_t *)self_in;
+ int mode = mp_obj_get_int(mode_in);
+ self->din->mode((PinMode)mode);
+ return mp_const_none;
+}
+
+mp_obj_t mbed_DigitalIn_is_connected(mp_obj_t self_in) {
+ mbed_DigitalIn_obj_t *self = (mbed_DigitalIn_obj_t *)self_in;
+ int conn = self->din->is_connected();
+ return conn ? mp_const_true : mp_const_false;
+}
+
+#endif // MICROPY_MBED_DIGITALIN
+
+//-----------------------------------------------------------------------
+// Serial
+//-----------------------------------------------------------------------
+struct mbed_Serial_obj_t {
+ mp_obj_base_t base;
+ Serial *serial;
+};
// constructor Serial(pin)
mp_obj_t mbed_Serial_make_new(const mp_obj_type_t *type,
- mp_uint_t n_args, mp_uint_t n_kw,
- const mp_obj_t *args)
-{
- (void)type;
- mp_arg_check_num(n_args, n_kw, 2, 2, false);
- int tx = mp_obj_get_int(args[0]);
- int rx = mp_obj_get_int(args[1]);
+ mp_uint_t n_args, mp_uint_t n_kw,
+ const mp_obj_t *args) {
+ (void)type;
+ mp_arg_check_num(n_args, n_kw, 2, 2, false);
+ int tx = mp_obj_get_int(args[0]);
+ int rx = mp_obj_get_int(args[1]);
+ mbed_Serial_obj_t *o = m_new_obj_with_finaliser(mbed_Serial_obj_t);
+ o->base.type = &mbed_Serial_type;
+ o->serial = new Serial((PinName)tx, (PinName)rx);
+ return o;
+}
- mbed_Serial_obj_t *o = m_new_obj_with_finaliser(mbed_Serial_obj_t);
- o->base.type = &mbed_Serial_type;
- o->serial = new Serial((PinName)tx, (PinName)rx);
+mp_obj_t mbed_Serial_baud(mp_obj_t self_in, mp_obj_t baud_in) {
+ mbed_Serial_obj_t *self = (mbed_Serial_obj_t *)self_in;
+ int baud = mp_obj_get_int(baud_in);
+ self->serial->baud(baud);
+ return mp_const_none;
+}
- return o;
+mp_obj_t mbed_Serial_format(size_t n_args, const mp_obj_t *args) {
+ mbed_Serial_obj_t *self = (mbed_Serial_obj_t *)args[0];
+ int bits = (n_args > 1) ? mp_obj_get_int(args[1]) : 8;
+ int parity = (n_args > 2) ? mp_obj_get_int(args[2]) : SerialBase::None;
+ int stop_bits = (n_args > 3) ? mp_obj_get_int(args[3]) : 1;
+ self->serial->format(bits, (SerialBase::Parity)parity, stop_bits);
+ return mp_const_none;
}
-mp_obj_t mbed_Serial_putc(mp_obj_t self_in, mp_obj_t chr_in)
-{
- mbed_Serial_obj_t *self = (mbed_Serial_obj_t *)self_in;
- int chr = mp_obj_get_int(chr_in);
+mp_obj_t mbed_Serial_readable(mp_obj_t self_in) {
+ mbed_Serial_obj_t *self = (mbed_Serial_obj_t *)self_in;
+ int value = self->serial->readable();
+ return value ? mp_const_true : mp_const_false;
+}
- self->serial->putc(chr);
- return mp_const_none;
+mp_obj_t mbed_Serial_writeable(mp_obj_t self_in) {
+ mbed_Serial_obj_t *self = (mbed_Serial_obj_t *)self_in;
+ int value = self->serial->writeable();
+ return value ? mp_const_true : mp_const_false;
}
-mp_obj_t mbed_Serial_puts(mp_obj_t self_in, mp_obj_t str_in)
-{
- mbed_Serial_obj_t *self = (mbed_Serial_obj_t *)self_in;
- const char *str = mp_obj_str_get_str(str_in);
+// TODO attach - interrupt handler
- self->serial->puts(str);
- return mp_const_none;
+mp_obj_t mbed_Serial_send_break(mp_obj_t self_in) {
+ mbed_Serial_obj_t *self = (mbed_Serial_obj_t *)self_in;
+ self->serial->send_break();
+ return mp_const_none;
}
-mp_obj_t mbed_Serial_getc(mp_obj_t self_in)
-{
- mbed_Serial_obj_t *self = (mbed_Serial_obj_t *)self_in;
- int chr = self->serial->getc();
- return MP_OBJ_NEW_SMALL_INT(chr);
+mp_obj_t mbed_Serial_putc(mp_obj_t self_in, mp_obj_t chr_in) {
+ mbed_Serial_obj_t *self = (mbed_Serial_obj_t *)self_in;
+ int chr = mp_obj_get_int(chr_in);
+ self->serial->putc(chr);
+ return mp_const_none;
+}
+
+mp_obj_t mbed_Serial_puts(mp_obj_t self_in, mp_obj_t str_in) {
+ mbed_Serial_obj_t *self = (mbed_Serial_obj_t *)self_in;
+ const char *str = mp_obj_str_get_str(str_in);
+ self->serial->puts(str);
+ return mp_const_none;
+}
+
+mp_obj_t mbed_Serial_getc(mp_obj_t self_in) {
+ mbed_Serial_obj_t *self = (mbed_Serial_obj_t *)self_in;
+ int chr = self->serial->getc();
+ return MP_OBJ_NEW_SMALL_INT(chr);
}
#endif
--- a/modmbed_i.h Mon Apr 25 19:55:21 2016 +0100 +++ b/modmbed_i.h Tue Apr 26 22:50:06 2016 +0100 @@ -21,15 +21,40 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef __MICROPY_INCLUDED_MODMBED_I_H +#define __MICROPY_INCLUDED_MODMBED_I_H +// Functions +#if MICROPY_PY_BUILTINS_FLOAT +mp_obj_t mbed_wait(mp_obj_t s_in); +#endif +extern mp_obj_t mbed_wait_ms(mp_obj_t ms_in); +extern mp_obj_t mbed_wait_us(mp_obj_t us_in); + +// DigitalOut 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); +// DigitalIn +extern const mp_obj_type_t mbed_DigitalIn_type; +extern mp_obj_t mbed_DigitalIn_make_new(const mp_obj_type_t *, mp_uint_t, mp_uint_t, const mp_obj_t *); +extern mp_obj_t mbed_DigitalIn_read(mp_obj_t self_in); +extern mp_obj_t mbed_DigitalIn_mode(mp_obj_t self_in, mp_obj_t mode_in); +extern mp_obj_t mbed_DigitalIn_is_connected(mp_obj_t self_in); + +// Serial extern const mp_obj_type_t mbed_Serial_type; extern mp_obj_t mbed_Serial_make_new(const mp_obj_type_t *type, - mp_uint_t n_args, mp_uint_t n_kw, - const mp_obj_t *args); + mp_uint_t n_args, mp_uint_t n_kw, + const mp_obj_t *args); +extern mp_obj_t mbed_Serial_baud(mp_obj_t self_in, mp_obj_t baud_in); +extern mp_obj_t mbed_Serial_format(size_t n_args, const mp_obj_t *args); extern mp_obj_t mbed_Serial_putc(mp_obj_t self_in, mp_obj_t chr_in); extern mp_obj_t mbed_Serial_puts(mp_obj_t self_in, mp_obj_t str_in); extern mp_obj_t mbed_Serial_getc(mp_obj_t self_in); +extern mp_obj_t mbed_Serial_readable(mp_obj_t self_in); +extern mp_obj_t mbed_Serial_writeable(mp_obj_t self_in); +extern mp_obj_t mbed_Serial_send_break(mp_obj_t self_in); + +#endif // __MICROPY_INCLUDED_MODMBED_I_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/modpins.c Tue Apr 26 22:50:06 2016 +0100
@@ -0,0 +1,45 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2016 Colin Hogben
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "py/mpconfig.h"
+#include "py/runtime.h"
+
+#if MICROPY_PY_PINS
+
+#include "mbed_interface.h"
+
+STATIC const mp_rom_map_elem_t mp_pins_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pins) },
+#include "mbedpins.h"
+};
+
+STATIC MP_DEFINE_CONST_DICT(mp_pins_module_globals,
+ mp_pins_module_globals_table);
+
+const mp_obj_module_t mp_module_pins = {
+ .base = { &mp_type_module },
+ .name = MP_QSTR_pins,
+ .globals = (mp_obj_dict_t *)&mp_pins_module_globals,
+};
+
+#endif // MICROPY_PY_PINS
--- a/modpins.cpp Mon Apr 25 19:55:21 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2016 Colin Hogben
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-extern "C" {
-#include "py/mpconfig.h"
-#include "py/runtime.h"
-}
-
-#if MICROPY_PY_PINS
-
-#include "mbed.h"
-
-STATIC const mp_rom_map_elem_t mp_pins_module_globals_table[] = {
- { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pins) },
-#include "mbedpins.h"
-};
-
-STATIC MP_DEFINE_CONST_DICT(mp_pins_module_globals,
- mp_pins_module_globals_table);
-
-const mp_obj_module_t mp_module_pins = {
- .base = { &mp_type_module },
- .name = MP_QSTR_pins,
- .globals = (mp_obj_dict_t *)&mp_pins_module_globals,
-};
-
-#endif // MICROPY_PY_PINS
--- a/mpconfigport.h Mon Apr 25 19:55:21 2016 +0100
+++ b/mpconfigport.h Tue Apr 26 22:50:06 2016 +0100
@@ -29,7 +29,7 @@
// options to control how Micro Python is built
// The mbed online compiler uses different assembler syntax, so avoid
-#define MICROPY_NLR_SETJMP 1
+#define MICROPY_NLR_SETJMP (1)
#define MICROPY_ALLOC_PATH_MAX (256)
#define MICROPY_ALLOC_PARSE_CHUNK_INIT (16)
@@ -71,13 +71,14 @@
#define MICROPY_PY_STRUCT (1)
#define MICROPY_PY_SYS (1)
// Build "machine" module (port-specific)
-#define MICROPY_PY_MACHINE 1
+#define MICROPY_PY_MACHINE (1)
// Build "mbed" module
-#define MICROPY_PY_MBED 1
+#define MICROPY_PY_MBED (1)
// Select which mbed features wanted
-#define MICROPY_MBED_DIGITALOUT 1
-#define MICROPY_MBED_SERIAL 1
-#define MICROPY_PY_PINS 1
+#define MICROPY_MBED_DIGITALOUT (1)
+#define MICROPY_MBED_DIGITALIN (1)
+#define MICROPY_MBED_SERIAL (1)
+#define MICROPY_PY_PINS (1)
#define MICROPY_MODULE_FROZEN (0)
#define MICROPY_CPYTHON_COMPAT (0)
@@ -106,16 +107,15 @@
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
-#if 0
// extra built in names to add to the global namespace
-extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
+extern const struct _mp_obj_fun_builtin_t mp_builtin_help_obj;
#define MICROPY_PORT_BUILTINS \
- { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
-#endif
+ { MP_OBJ_NEW_QSTR(MP_QSTR_help), (mp_obj_t)&mp_builtin_help_obj },
// We need to provide a declaration/definition of alloca()
#include <alloca.h>
+#define MICROPY_PY_SYS_PLATFORM "mbed"
#define MICROPY_HW_BOARD_NAME "mbed"
#define MICROPY_HW_MCU_NAME "arm"
@@ -125,9 +125,9 @@
extern const struct _mp_obj_module_t mp_module_mbed;
extern const struct _mp_obj_module_t mp_module_pins;
#define MICROPY_PORT_BUILTIN_MODULES \
- { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&mp_module_machine) }, \
- { MP_ROM_QSTR(MP_QSTR_mbed), MP_ROM_PTR(&mp_module_mbed) }, \
- { MP_ROM_QSTR(MP_QSTR_pins), MP_ROM_PTR(&mp_module_pins) }, \
+ { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&mp_module_machine) }, \
+ { MP_ROM_QSTR(MP_QSTR_mbed), MP_ROM_PTR(&mp_module_mbed) }, \
+ { MP_ROM_QSTR(MP_QSTR_pins), MP_ROM_PTR(&mp_module_pins) }, \
// Use by readline.c
#define MICROPY_PORT_ROOT_POINTERS \
--- a/mphalport.c Mon Apr 25 19:55:21 2016 +0100
+++ b/mphalport.c Tue Apr 26 22:50:06 2016 +0100
@@ -35,20 +35,21 @@
#include "py/lexer.h"
// Since we have no filesystem, no file exists
-mp_import_stat_t mp_import_stat(const char *path)
-{
- (void)path;
- return MP_IMPORT_STAT_NO_EXIST;
+mp_import_stat_t mp_import_stat(const char *path) {
+ (void)path;
+ return MP_IMPORT_STAT_NO_EXIST;
}
-mp_lexer_t *mp_lexer_new_from_file(const char *filename)
-{
- (void)filename;
- return NULL;
+mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
+ (void)filename;
+ return NULL;
}
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
- return mp_const_none;
+ (void)n_args;
+ (void)args;
+ (void)kwargs;
+ return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
@@ -56,27 +57,27 @@
// Text output
void mp_hal_stdout_tx_strn(const char *str, size_t len) {
- while (len--) {
- mp_hal_stdout_tx_chr(*str++);
- }
+ while (len--) {
+ mp_hal_stdout_tx_chr(*str++);
+ }
}
void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
- while (len--) {
- char c = *str++;
- if (c == '\n') {
- mp_hal_stdout_tx_chr('\r');
+ while (len--) {
+ char c = *str++;
+ if (c == '\n') {
+ mp_hal_stdout_tx_chr('\r');
+ }
+ mp_hal_stdout_tx_chr(c);
}
- mp_hal_stdout_tx_chr(c);
- }
}
void mp_hal_stdout_tx_str(const char *str) {
mp_hal_stdout_tx_strn(str, strlen(str));
}
-void mp_hal_set_interrupt_char(int c)
-{
+void mp_hal_set_interrupt_char(int c) {
+ (void)c;
}
mp_uint_t mp_hal_ticks_ms(void) {
@@ -84,6 +85,7 @@
}
void mp_hal_delay_ms(mp_uint_t ms) {
+ (void)ms;
}
void gc_collect(void) {}
--- a/qstrdefsport.h Mon Apr 25 19:55:21 2016 +0100 +++ b/qstrdefsport.h Tue Apr 26 22:50:06 2016 +0100 @@ -26,30 +26,4 @@ * Extra qstr values needed by this port */ -// modmachine.c -#if MICROPY_PY_MACHINE -Q(machine) -Q(reset) -#endif - -// modmbed.cpp -#if MICROPY_PY_MBED -Q(mbed) -Q(DigitalOut) -Q(write) -Q(Serial) -Q(putc) -Q(puts) -Q(getc) -#endif - -// modpins.cpp -Q(pins) -#if defined(TARGET_K64F) -Q(USBTX) -Q(USBRX) -Q(PTA0) -Q(LED_RED) -Q(LED_GREEN) -Q(LED_BLUE) -#endif +Q(help)