all: Add py/mphal.h and use it in all ports.
py/mphal.h contains declarations for generic mp_hal_XXX functions, such
as stdio and delay/ticks, which ports should provide definitions for. A
port will also provide mphalport.h with further HAL declarations.
diff --git a/bare-arm/mphalport.h b/bare-arm/mphalport.h
new file mode 100644
index 0000000..4bd8276
--- /dev/null
+++ b/bare-arm/mphalport.h
@@ -0,0 +1 @@
+// empty file
diff --git a/cc3200/bootmgr/main.c b/cc3200/bootmgr/main.c
index 1ec7d29..d20cd5d 100644
--- a/cc3200/bootmgr/main.c
+++ b/cc3200/bootmgr/main.c
@@ -30,7 +30,6 @@
#include "std.h"
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "hw_ints.h"
#include "hw_types.h"
#include "hw_gpio.h"
diff --git a/cc3200/fatfs/src/drivers/sd_diskio.c b/cc3200/fatfs/src/drivers/sd_diskio.c
index cdc0cf0..a1fd723 100644
--- a/cc3200/fatfs/src/drivers/sd_diskio.c
+++ b/cc3200/fatfs/src/drivers/sd_diskio.c
@@ -38,7 +38,7 @@
#include <stdbool.h>
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
#include "hw_types.h"
#include "hw_memmap.h"
#include "hw_ints.h"
diff --git a/cc3200/fatfs/src/drivers/sflash_diskio.c b/cc3200/fatfs/src/drivers/sflash_diskio.c
index 5bb2296..d0cfe0f 100644
--- a/cc3200/fatfs/src/drivers/sflash_diskio.c
+++ b/cc3200/fatfs/src/drivers/sflash_diskio.c
@@ -3,7 +3,6 @@
#include "std.h"
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
#include "simplelink.h"
#include "diskio.h"
diff --git a/cc3200/ftp/ftp.c b/cc3200/ftp/ftp.c
index dc21ebb..252a3d7 100644
--- a/cc3200/ftp/ftp.c
+++ b/cc3200/ftp/ftp.c
@@ -29,7 +29,6 @@
#include "std.h"
#include "py/mpstate.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
diff --git a/cc3200/ftp/updater.c b/cc3200/ftp/updater.c
index 2a2d470..fece700 100644
--- a/cc3200/ftp/updater.c
+++ b/cc3200/ftp/updater.c
@@ -28,7 +28,6 @@
#include <stdbool.h>
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
#include "simplelink.h"
#include "flc.h"
diff --git a/cc3200/hal/cc3200_hal.c b/cc3200/hal/cc3200_hal.c
index e5ac4f0..f0987ae 100644
--- a/cc3200/hal/cc3200_hal.c
+++ b/cc3200/hal/cc3200_hal.c
@@ -34,7 +34,7 @@
#include "py/mpstate.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
#include "py/runtime.h"
#include "py/objstr.h"
#include "inc/hw_types.h"
@@ -104,11 +104,11 @@
HAL_tickCount++;
}
-uint32_t mp_hal_ticks_ms(void) {
+mp_uint_t mp_hal_ticks_ms(void) {
return HAL_tickCount;
}
-void mp_hal_delay_ms(uint32_t delay) {
+void mp_hal_delay_ms(mp_uint_t delay) {
// only if we are not within interrupt context and interrupts are enabled
if ((HAL_NVIC_INT_CTRL_REG & HAL_VECTACTIVE_MASK) == 0 && query_irq() == IRQ_STATE_ENABLED) {
#ifdef USE_FREERTOS
@@ -140,7 +140,7 @@
mp_hal_stdout_tx_strn(str, strlen(str));
}
-void mp_hal_stdout_tx_strn(const char *str, uint32_t len) {
+void mp_hal_stdout_tx_strn(const char *str, size_t len) {
if (MP_STATE_PORT(os_term_dup_obj)) {
if (MP_OBJ_IS_TYPE(MP_STATE_PORT(os_term_dup_obj)->stream_o, &pyb_uart_type)) {
uart_tx_strn(MP_STATE_PORT(os_term_dup_obj)->stream_o, str, len);
@@ -153,7 +153,7 @@
telnet_tx_strn(str, len);
}
-void mp_hal_stdout_tx_strn_cooked (const char *str, uint32_t len) {
+void mp_hal_stdout_tx_strn_cooked (const char *str, size_t len) {
int32_t nslen = 0;
const char *_str = str;
diff --git a/cc3200/hal/cc3200_hal.h b/cc3200/hal/cc3200_hal.h
index c0dc9eb..054d503 100644
--- a/cc3200/hal/cc3200_hal.h
+++ b/cc3200/hal/cc3200_hal.h
@@ -62,14 +62,7 @@
extern void HAL_SystemInit (void);
extern void HAL_SystemDeInit (void);
extern void HAL_IncrementTick(void);
-extern uint32_t mp_hal_ticks_ms(void);
-extern void mp_hal_delay_ms(uint32_t delay);
extern NORETURN void mp_hal_raise(int errno);
extern void mp_hal_set_interrupt_char (int c);
-int mp_hal_stdin_rx_chr(void);
-void mp_hal_stdout_tx_str(const char *str);
-void mp_hal_stdout_tx_strn(const char *str, uint32_t len);
-void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len);
-
#endif /* CC3200_LAUNCHXL_HAL_CC3200_HAL_H_ */
diff --git a/cc3200/main.c b/cc3200/main.c
index b217e20..78b4e31 100644
--- a/cc3200/main.c
+++ b/cc3200/main.c
@@ -29,7 +29,7 @@
#include <ctype.h>
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
#include "mptask.h"
#include "simplelink.h"
#include "pybwdt.h"
diff --git a/cc3200/misc/FreeRTOSHooks.c b/cc3200/misc/FreeRTOSHooks.c
index 2497145..dac9a92 100644
--- a/cc3200/misc/FreeRTOSHooks.c
+++ b/cc3200/misc/FreeRTOSHooks.c
@@ -29,7 +29,7 @@
#include <string.h>
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
#include "py/obj.h"
#include "inc/hw_memmap.h"
#include "pybuart.h"
diff --git a/cc3200/misc/mperror.c b/cc3200/misc/mperror.c
index 5fa8442..044994b 100644
--- a/cc3200/misc/mperror.c
+++ b/cc3200/misc/mperror.c
@@ -30,9 +30,9 @@
#include <string.h>
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
#include "py/runtime.h"
+#include "py/mphal.h"
#include "hw_ints.h"
#include "hw_types.h"
#include "hw_gpio.h"
diff --git a/cc3200/misc/mpirq.c b/cc3200/misc/mpirq.c
index e780c78..29cc4a7 100644
--- a/cc3200/misc/mpirq.c
+++ b/cc3200/misc/mpirq.c
@@ -27,7 +27,6 @@
#include "std.h"
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
#include "py/runtime.h"
#include "py/gc.h"
diff --git a/cc3200/misc/mpsystick.c b/cc3200/misc/mpsystick.c
index 63b6c2d..7c35354 100644
--- a/cc3200/misc/mpsystick.c
+++ b/cc3200/misc/mpsystick.c
@@ -26,8 +26,8 @@
*/
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
+#include "py/mphal.h"
#include "mpsystick.h"
#include "systick.h"
#include "inc/hw_types.h"
diff --git a/cc3200/mods/modmachine.c b/cc3200/mods/modmachine.c
index 2508c66..896aa99 100644
--- a/cc3200/mods/modmachine.c
+++ b/cc3200/mods/modmachine.c
@@ -30,7 +30,7 @@
#include "py/mpstate.h"
#include "py/runtime.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
#include "irq.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
diff --git a/cc3200/mods/modnetwork.c b/cc3200/mods/modnetwork.c
index f8dbd9c..b11b036 100644
--- a/cc3200/mods/modnetwork.c
+++ b/cc3200/mods/modnetwork.c
@@ -28,10 +28,10 @@
#include <std.h>
#include "py/mpstate.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
#include "py/nlr.h"
#include "py/runtime.h"
+#include "py/mphal.h"
#include "modnetwork.h"
#include "mpexception.h"
#include "serverstask.h"
diff --git a/cc3200/mods/modubinascii.c b/cc3200/mods/modubinascii.c
index 563c44a..add46f9 100644
--- a/cc3200/mods/modubinascii.c
+++ b/cc3200/mods/modubinascii.c
@@ -26,7 +26,6 @@
*/
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/binary.h"
diff --git a/cc3200/mods/modusocket.c b/cc3200/mods/modusocket.c
index 6b69e91..622a026 100644
--- a/cc3200/mods/modusocket.c
+++ b/cc3200/mods/modusocket.c
@@ -30,7 +30,6 @@
#include "simplelink.h"
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
#include "py/objstr.h"
#include "py/runtime.h"
diff --git a/cc3200/mods/modussl.c b/cc3200/mods/modussl.c
index ce3067d..4239c44 100644
--- a/cc3200/mods/modussl.c
+++ b/cc3200/mods/modussl.c
@@ -29,7 +29,6 @@
#include "simplelink.h"
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
#include "py/objstr.h"
#include "py/runtime.h"
diff --git a/cc3200/mods/modutime.c b/cc3200/mods/modutime.c
index 14ac10a..c669d32 100644
--- a/cc3200/mods/modutime.c
+++ b/cc3200/mods/modutime.c
@@ -29,10 +29,10 @@
#include <string.h>
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/nlr.h"
#include "py/obj.h"
#include "py/smallint.h"
+#include "py/mphal.h"
#include "timeutils.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
diff --git a/cc3200/mods/modwipy.c b/cc3200/mods/modwipy.c
index 08c3f00..2cfd640 100644
--- a/cc3200/mods/modwipy.c
+++ b/cc3200/mods/modwipy.c
@@ -1,5 +1,4 @@
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
#include "py/runtime.h"
#include "mperror.h"
diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c
index fb7a8a6..2997e8d 100644
--- a/cc3200/mods/modwlan.c
+++ b/cc3200/mods/modwlan.c
@@ -30,10 +30,10 @@
#include "simplelink.h"
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
#include "py/objstr.h"
#include "py/runtime.h"
+#include "py/mphal.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
diff --git a/cc3200/mods/pybadc.c b/cc3200/mods/pybadc.c
index 2cb1cad..005c365 100644
--- a/cc3200/mods/pybadc.c
+++ b/cc3200/mods/pybadc.c
@@ -29,7 +29,6 @@
#include <string.h>
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/binary.h"
diff --git a/cc3200/mods/pybi2c.c b/cc3200/mods/pybi2c.c
index e9c6343..52a0851 100644
--- a/cc3200/mods/pybi2c.c
+++ b/cc3200/mods/pybi2c.c
@@ -29,8 +29,8 @@
#include <string.h>
#include "py/mpstate.h"
-#include MICROPY_HAL_H
#include "py/runtime.h"
+#include "py/mphal.h"
#include "bufhelper.h"
#include "inc/hw_types.h"
#include "inc/hw_i2c.h"
diff --git a/cc3200/mods/pybpin.c b/cc3200/mods/pybpin.c
index 4a2c313..ce0e386 100644
--- a/cc3200/mods/pybpin.c
+++ b/cc3200/mods/pybpin.c
@@ -30,7 +30,6 @@
#include <string.h>
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
#include "py/runtime.h"
#include "py/gc.h"
diff --git a/cc3200/mods/pybrtc.c b/cc3200/mods/pybrtc.c
index ce5b128..8d6b9b1 100644
--- a/cc3200/mods/pybrtc.c
+++ b/cc3200/mods/pybrtc.c
@@ -28,7 +28,6 @@
#include <std.h>
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
#include "py/runtime.h"
#include "inc/hw_types.h"
diff --git a/cc3200/mods/pybsd.c b/cc3200/mods/pybsd.c
index 74eaa42..ea81f30 100644
--- a/cc3200/mods/pybsd.c
+++ b/cc3200/mods/pybsd.c
@@ -25,7 +25,6 @@
*/
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
#include "py/runtime.h"
#include "inc/hw_types.h"
diff --git a/cc3200/mods/pybsleep.c b/cc3200/mods/pybsleep.c
index e3a9dee..ced7fef 100644
--- a/cc3200/mods/pybsleep.c
+++ b/cc3200/mods/pybsleep.c
@@ -28,8 +28,8 @@
#include <string.h>
#include "py/mpstate.h"
-#include MICROPY_HAL_H
#include "py/runtime.h"
+#include "py/mphal.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_nvic.h"
diff --git a/cc3200/mods/pybspi.c b/cc3200/mods/pybspi.c
index ed3abf5..b7e4310 100644
--- a/cc3200/mods/pybspi.c
+++ b/cc3200/mods/pybspi.c
@@ -29,7 +29,6 @@
#include <string.h>
#include "py/mpstate.h"
-#include MICROPY_HAL_H
#include "py/runtime.h"
#include "bufhelper.h"
#include "inc/hw_types.h"
diff --git a/cc3200/mods/pybtimer.c b/cc3200/mods/pybtimer.c
index 089724b..95eeb08 100644
--- a/cc3200/mods/pybtimer.c
+++ b/cc3200/mods/pybtimer.c
@@ -30,11 +30,11 @@
#include <string.h>
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/gc.h"
+#include "py/mphal.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
diff --git a/cc3200/mods/pybuart.c b/cc3200/mods/pybuart.c
index f4c29d7..660453b 100644
--- a/cc3200/mods/pybuart.c
+++ b/cc3200/mods/pybuart.c
@@ -31,11 +31,11 @@
#include <string.h>
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
#include "py/runtime.h"
#include "py/objlist.h"
#include "py/stream.h"
+#include "py/mphal.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
diff --git a/cc3200/mods/pybwdt.c b/cc3200/mods/pybwdt.c
index 7619404..8448054 100644
--- a/cc3200/mods/pybwdt.c
+++ b/cc3200/mods/pybwdt.c
@@ -27,9 +27,9 @@
#include <stdint.h>
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
#include "py/runtime.h"
+#include "py/mphal.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_ints.h"
diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h
index 8584eaa..8e6d174 100644
--- a/cc3200/mpconfigport.h
+++ b/cc3200/mpconfigport.h
@@ -180,7 +180,6 @@
typedef const void *machine_const_ptr_t; // must be of pointer size
typedef long mp_off_t;
-void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len);
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
#define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq()
@@ -204,7 +203,7 @@
// Include board specific configuration
#include "mpconfigboard.h"
-#define MICROPY_HAL_H "cc3200_hal.h"
+#define MICROPY_MPHALPORT_H "cc3200_hal.h"
#define MICROPY_PORT_HAS_TELNET (1)
#define MICROPY_PORT_HAS_FTP (1)
#define MICROPY_PY_SYS_PLATFORM "WiPy"
diff --git a/cc3200/mptask.c b/cc3200/mptask.c
index ec904f8..7346dda 100644
--- a/cc3200/mptask.c
+++ b/cc3200/mptask.c
@@ -28,10 +28,10 @@
#include <stdint.h>
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
#include "py/runtime.h"
#include "py/gc.h"
+#include "py/mphal.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
diff --git a/cc3200/serverstask.c b/cc3200/serverstask.c
index e22f7f9..3559664 100644
--- a/cc3200/serverstask.c
+++ b/cc3200/serverstask.c
@@ -28,9 +28,9 @@
#include <string.h>
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/misc.h"
#include "py/nlr.h"
+#include "py/mphal.h"
#include "serverstask.h"
#include "simplelink.h"
#include "debug.h"
diff --git a/cc3200/telnet/telnet.c b/cc3200/telnet/telnet.c
index 70e6068..6980ed5 100644
--- a/cc3200/telnet/telnet.c
+++ b/cc3200/telnet/telnet.c
@@ -27,8 +27,8 @@
#include <stdint.h>
#include "py/mpconfig.h"
-#include MICROPY_HAL_H
#include "py/obj.h"
+#include "py/mphal.h"
#include "telnet.h"
#include "simplelink.h"
#include "modnetwork.h"
diff --git a/cc3200/util/gccollect.c b/cc3200/util/gccollect.c
index a1b0f80..094ca73 100644
--- a/cc3200/util/gccollect.c
+++ b/cc3200/util/gccollect.c
@@ -32,7 +32,6 @@
#include "py/gc.h"
#include "gccollect.h"
#include "gchelper.h"
-#include MICROPY_HAL_H
/******************************************************************************
DECLARE PRIVATE DATA
diff --git a/esp8266/esp_mphal.h b/esp8266/esp_mphal.h
index e3ba0c4..dc6a79f 100644
--- a/esp8266/esp_mphal.h
+++ b/esp8266/esp_mphal.h
@@ -32,13 +32,7 @@
void mp_hal_init(void);
void mp_hal_feed_watchdog(void);
-int mp_hal_stdin_rx_chr(void);
-void mp_hal_stdout_tx_str(const char *str);
-void mp_hal_stdout_tx_strn(const char *str, uint32_t len);
-void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len);
-uint32_t mp_hal_ticks_ms(void);
-void mp_hal_delay_ms(uint32_t delay);
void mp_hal_delay_us(uint32_t);
void mp_hal_set_interrupt_char(int c);
uint32_t mp_hal_get_cpu_freq(void);
diff --git a/esp8266/main.c b/esp8266/main.c
index 18fd2bd..0d8b372 100644
--- a/esp8266/main.c
+++ b/esp8266/main.c
@@ -33,10 +33,10 @@
#include "py/runtime.h"
#include "py/stackctrl.h"
#include "py/frozenmod.h"
+#include "py/mphal.h"
#include "py/gc.h"
#include "pyexec.h"
#include "gccollect.h"
-#include MICROPY_HAL_H
#include "user_interface.h"
STATIC char heap[16384];
diff --git a/esp8266/modesp.c b/esp8266/modesp.c
index 5e7d5fb..4e46b7a 100644
--- a/esp8266/modesp.c
+++ b/esp8266/modesp.c
@@ -32,7 +32,6 @@
#include "py/obj.h"
#include "py/gc.h"
#include "py/runtime.h"
-#include MICROPY_HAL_H
#include "netutils.h"
#include "queue.h"
#include "user_interface.h"
diff --git a/esp8266/modpyb.c b/esp8266/modpyb.c
index c5c24c0..36a9d6b 100644
--- a/esp8266/modpyb.c
+++ b/esp8266/modpyb.c
@@ -29,9 +29,9 @@
#include "py/nlr.h"
#include "py/obj.h"
#include "py/gc.h"
+#include "py/mphal.h"
#include "gccollect.h"
#include "pyexec.h"
-#include MICROPY_HAL_H
#include "user_interface.h"
#include "modpyb.h"
diff --git a/esp8266/modpybadc.c b/esp8266/modpybadc.c
index b4dfa67..ade63df 100644
--- a/esp8266/modpybadc.c
+++ b/esp8266/modpybadc.c
@@ -30,7 +30,6 @@
#include "py/nlr.h"
#include "py/obj.h"
#include "py/runtime.h"
-#include MICROPY_HAL_H
#include "user_interface.h"
const mp_obj_type_t pyb_adc_type;
diff --git a/esp8266/modpybrtc.c b/esp8266/modpybrtc.c
index 2608948..1156216 100644
--- a/esp8266/modpybrtc.c
+++ b/esp8266/modpybrtc.c
@@ -30,7 +30,6 @@
#include "py/nlr.h"
#include "py/obj.h"
#include "py/runtime.h"
-#include MICROPY_HAL_H
#include "timeutils.h"
#include "user_interface.h"
#include "modpyb.h"
diff --git a/esp8266/modutime.c b/esp8266/modutime.c
index 241d3cc..5c55833 100644
--- a/esp8266/modutime.c
+++ b/esp8266/modutime.c
@@ -32,7 +32,7 @@
#include "py/obj.h"
#include "py/gc.h"
#include "py/runtime.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
#include "modpyb.h"
#include "modpybrtc.h"
#include "timeutils.h"
diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h
index 6635d26..3cc2d9a 100644
--- a/esp8266/mpconfigport.h
+++ b/esp8266/mpconfigport.h
@@ -54,7 +54,6 @@
typedef const void *machine_const_ptr_t; // must be of pointer size
typedef long mp_off_t;
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
// extra built in names to add to the global namespace
@@ -94,7 +93,7 @@
// board specifics
-#define MICROPY_HAL_H "esp_mphal.h"
+#define MICROPY_MPHALPORT_H "esp_mphal.h"
#define MICROPY_HW_BOARD_NAME "ESP module"
#define MICROPY_HW_MCU_NAME "ESP8266"
#define MICROPY_PY_SYS_PLATFORM "ESP8266"
diff --git a/lib/mp-readline/readline.c b/lib/mp-readline/readline.c
index 68e0e24..b7c64ae 100644
--- a/lib/mp-readline/readline.c
+++ b/lib/mp-readline/readline.c
@@ -30,10 +30,8 @@
#include "py/mpstate.h"
#include "py/repl.h"
+#include "py/mphal.h"
#include "readline.h"
-#ifdef MICROPY_HAL_H
-#include MICROPY_HAL_H
-#endif
#if 0 // print debugging info
#define DEBUG_PRINT (1)
diff --git a/minimal/mpconfigport.h b/minimal/mpconfigport.h
index c585593..caa31d3 100644
--- a/minimal/mpconfigport.h
+++ b/minimal/mpconfigport.h
@@ -65,7 +65,6 @@
typedef const void *machine_const_ptr_t; // must be of pointer size
typedef long mp_off_t;
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
// extra built in names to add to the global namespace
@@ -76,14 +75,6 @@
// We need to provide a declaration/definition of alloca()
#include <alloca.h>
-#define mp_hal_ticks_ms() 0
-int mp_hal_stdin_rx_chr(void);
-void mp_hal_stdout_tx_str(const char *str);
-void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
-
-static inline void mp_hal_set_interrupt_char(char c) {}
-
#define MICROPY_HW_BOARD_NAME "minimal"
#define MICROPY_HW_MCU_NAME "unknown-cpu"
diff --git a/minimal/mphalport.h b/minimal/mphalport.h
new file mode 100644
index 0000000..60d68bd
--- /dev/null
+++ b/minimal/mphalport.h
@@ -0,0 +1,2 @@
+static inline mp_uint_t mp_hal_ticks_ms(void) { return 0; }
+static inline void mp_hal_set_interrupt_char(char c) {}
diff --git a/minimal/uart_extra.c b/minimal/uart_extra.c
index e266904..1c3fc2e 100644
--- a/minimal/uart_extra.c
+++ b/minimal/uart_extra.c
@@ -1,6 +1,7 @@
#include <string.h>
#include <unistd.h>
#include "py/mpconfig.h"
+#include "py/mphal.h"
/*
* Extra UART functions
diff --git a/pic16bit/main.c b/pic16bit/main.c
index 9b993fd..ad6f9e3 100644
--- a/pic16bit/main.c
+++ b/pic16bit/main.c
@@ -32,9 +32,9 @@
#include "py/compile.h"
#include "py/runtime.h"
#include "py/gc.h"
+#include "py/mphal.h"
#include "pyexec.h"
#include "readline.h"
-#include MICROPY_HAL_H
#include "board.h"
#include "modpyb.h"
@@ -59,7 +59,7 @@
led_state(1, 0);
led_state(2, 0);
led_state(3, 1);
- mp_hal_milli_delay(150);
+ mp_hal_delay_ms(150);
led_state(3, 0);
// init MicroPython runtime
diff --git a/pic16bit/modpyb.c b/pic16bit/modpyb.c
index f632d94..f59163a 100644
--- a/pic16bit/modpyb.c
+++ b/pic16bit/modpyb.c
@@ -27,17 +27,17 @@
#include <stdio.h>
#include "py/obj.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
#include "modpyb.h"
STATIC mp_obj_t pyb_millis(void) {
- return MP_OBJ_NEW_SMALL_INT(mp_hal_get_milliseconds());
+ return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_millis_obj, pyb_millis);
STATIC mp_obj_t pyb_elapsed_millis(mp_obj_t start) {
uint32_t startMillis = mp_obj_get_int(start);
- uint32_t currMillis = mp_hal_get_milliseconds();
+ uint32_t currMillis = mp_hal_ticks_ms();
return MP_OBJ_NEW_SMALL_INT((currMillis - startMillis) & 0x1fff);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_millis_obj, pyb_elapsed_millis);
@@ -45,7 +45,7 @@
STATIC mp_obj_t pyb_delay(mp_obj_t ms_in) {
mp_int_t ms = mp_obj_get_int(ms_in);
if (ms >= 0) {
- mp_hal_milli_delay(ms);
+ mp_hal_delay_ms(ms);
}
return mp_const_none;
}
diff --git a/pic16bit/mpconfigport.h b/pic16bit/mpconfigport.h
index d58401a..e5cb666 100644
--- a/pic16bit/mpconfigport.h
+++ b/pic16bit/mpconfigport.h
@@ -86,7 +86,6 @@
typedef const void *machine_const_ptr_t; // must be pointer size
typedef int mp_off_t;
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
// extra builtin names to add to the global namespace
@@ -108,6 +107,6 @@
char *readline_hist[8]; \
mp_obj_t keyboard_interrupt_obj; \
-#define MICROPY_HAL_H "pic16bit_mphal.h"
+#define MICROPY_MPHALPORT_H "pic16bit_mphal.h"
#define MICROPY_HW_BOARD_NAME "dsPICSK"
#define MICROPY_HW_MCU_NAME "dsPIC33"
diff --git a/pic16bit/pic16bit_mphal.c b/pic16bit/pic16bit_mphal.c
index dccea76..557b1e0 100644
--- a/pic16bit/pic16bit_mphal.c
+++ b/pic16bit/pic16bit_mphal.c
@@ -25,7 +25,7 @@
*/
#include <string.h>
-#include "pic16bit_mphal.h"
+#include "py/mphal.h"
#include "board.h"
static int interrupt_char;
@@ -34,12 +34,12 @@
MP_STATE_PORT(keyboard_interrupt_obj) = mp_obj_new_exception(&mp_type_KeyboardInterrupt);
}
-mp_uint_t mp_hal_get_milliseconds(void) {
+mp_uint_t mp_hal_ticks_ms(void) {
// TODO
return 0;
}
-void mp_hal_milli_delay(mp_uint_t ms) {
+void mp_hal_delay_ms(mp_uint_t ms) {
// tuned for fixed CPU frequency
for (int i = ms; i > 0; i--) {
for (volatile int j = 0; j < 5000; j++) {
@@ -63,13 +63,13 @@
mp_hal_stdout_tx_strn(str, strlen(str));
}
-void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
+void mp_hal_stdout_tx_strn(const char *str, size_t len) {
for (; len > 0; --len) {
uart_tx_char(*str++);
}
}
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
+void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
for (; len > 0; --len) {
if (*str == '\n') {
uart_tx_char('\r');
diff --git a/pic16bit/pic16bit_mphal.h b/pic16bit/pic16bit_mphal.h
index 8dde61f..a858f7e 100644
--- a/pic16bit/pic16bit_mphal.h
+++ b/pic16bit/pic16bit_mphal.h
@@ -26,19 +26,10 @@
#ifndef __MICROPY_INCLUDED_PIC16BIT_PIC16BIT_MPHAL_H__
#define __MICROPY_INCLUDED_PIC16BIT_PIC16BIT_MPHAL_H__
-#define HAL_GetTick mp_hal_get_milliseconds
-
#include "py/mpstate.h"
void mp_hal_init(void);
-mp_uint_t mp_hal_get_milliseconds(void);
-void mp_hal_milli_delay(mp_uint_t ms);
-
void mp_hal_set_interrupt_char(int c);
-int mp_hal_stdin_rx_chr(void);
-void mp_hal_stdout_tx_str(const char *str);
-void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
#endif // __MICROPY_INCLUDED_PIC16BIT_PIC16BIT_MPHAL_H__
diff --git a/py/mphal.h b/py/mphal.h
new file mode 100644
index 0000000..a0b642f
--- /dev/null
+++ b/py/mphal.h
@@ -0,0 +1,61 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015 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_PY_MPHAL_H__
+#define __MICROPY_INCLUDED_PY_MPHAL_H__
+
+#include "py/mpconfig.h"
+
+#ifdef MICROPY_MPHALPORT_H
+#include MICROPY_MPHALPORT_H
+#else
+#include <mphalport.h>
+#endif
+
+#ifndef mp_hal_stdin_rx_chr
+int mp_hal_stdin_rx_chr(void);
+#endif
+
+#ifndef mp_hal_stdout_tx_str
+void mp_hal_stdout_tx_str(const char *str);
+#endif
+
+#ifndef mp_hal_stdout_tx_strn
+void mp_hal_stdout_tx_strn(const char *str, size_t len);
+#endif
+
+#ifndef mp_hal_stdout_tx_strn_cooked
+void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len);
+#endif
+
+#ifndef mp_hal_delay_ms
+void mp_hal_delay_ms(mp_uint_t ms);
+#endif
+
+#ifndef mp_hal_ticks_ms
+mp_uint_t mp_hal_ticks_ms(void);
+#endif
+
+#endif // __MICROPY_INCLUDED_PY_MPHAL_H__
diff --git a/py/mpprint.c b/py/mpprint.c
index 6da6614..0aecf5c 100644
--- a/py/mpprint.c
+++ b/py/mpprint.c
@@ -30,6 +30,7 @@
#include <stdio.h>
#include <string.h>
+#include "py/mphal.h"
#include "py/mpprint.h"
#include "py/obj.h"
#include "py/objint.h"
diff --git a/qemu-arm/mphalport.h b/qemu-arm/mphalport.h
new file mode 100644
index 0000000..4bd8276
--- /dev/null
+++ b/qemu-arm/mphalport.h
@@ -0,0 +1 @@
+// empty file
diff --git a/stmhal/Makefile b/stmhal/Makefile
index 222e19b..8c0cd21 100644
--- a/stmhal/Makefile
+++ b/stmhal/Makefile
@@ -113,7 +113,7 @@
usbd_desc.c \
usbd_cdc_interface.c \
usbd_msc_storage.c \
- mphal.c \
+ mphalport.c \
irq.c \
pendsv.c \
systick.c \
diff --git a/stmhal/adc.c b/stmhal/adc.c
index c70d88e..d8ce90c 100644
--- a/stmhal/adc.c
+++ b/stmhal/adc.c
@@ -25,16 +25,15 @@
*/
#include <stdio.h>
-#include STM32_HAL_H
#include <string.h>
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/binary.h"
+#include "py/mphal.h"
#include "adc.h"
#include "pin.h"
#include "genhdr/pins.h"
-#include "mphal.h"
#include "timer.h"
/// \moduleref pyb
diff --git a/stmhal/boards/stm32f4xx_prefix.c b/stmhal/boards/stm32f4xx_prefix.c
index 529e0f0..f4ffdab 100644
--- a/stmhal/boards/stm32f4xx_prefix.c
+++ b/stmhal/boards/stm32f4xx_prefix.c
@@ -3,8 +3,8 @@
#include <stdio.h>
#include "py/obj.h"
+#include "py/mphal.h"
#include "pin.h"
-#include MICROPY_HAL_H
#define AF(af_idx, af_fn, af_unit, af_type, af_ptr) \
{ \
diff --git a/stmhal/can.c b/stmhal/can.c
index 18fd31e..38ddf74 100644
--- a/stmhal/can.c
+++ b/stmhal/can.c
@@ -33,10 +33,10 @@
#include "py/objtuple.h"
#include "py/runtime.h"
#include "py/gc.h"
+#include "py/mphal.h"
#include "bufhelper.h"
#include "can.h"
#include "pybioctl.h"
-#include MICROPY_HAL_H
#if MICROPY_HW_ENABLE_CAN
diff --git a/stmhal/extint.c b/stmhal/extint.c
index ebd9d3e..1fcf587 100644
--- a/stmhal/extint.c
+++ b/stmhal/extint.c
@@ -31,7 +31,7 @@
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/gc.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
#include "pin.h"
#include "extint.h"
diff --git a/stmhal/i2c.c b/stmhal/i2c.c
index af37abf..eb6716c 100644
--- a/stmhal/i2c.c
+++ b/stmhal/i2c.c
@@ -29,13 +29,13 @@
#include "py/nlr.h"
#include "py/runtime.h"
+#include "py/mphal.h"
#include "irq.h"
#include "pin.h"
#include "genhdr/pins.h"
#include "bufhelper.h"
#include "dma.h"
#include "i2c.h"
-#include MICROPY_HAL_H
#if !defined(MICROPY_HW_I2C_BAUDRATE_DEFAULT)
#define MICROPY_HW_I2C_BAUDRATE_DEFAULT 400000
diff --git a/stmhal/irq.c b/stmhal/irq.c
index 7a265a5..749e481 100644
--- a/stmhal/irq.c
+++ b/stmhal/irq.c
@@ -26,10 +26,9 @@
#include "py/nlr.h"
#include "py/obj.h"
+#include "py/mphal.h"
#include "irq.h"
-#include MICROPY_HAL_H
-
/// \moduleref pyb
/// \function wfi()
diff --git a/stmhal/led.c b/stmhal/led.c
index e3dbdb5..ca52931 100644
--- a/stmhal/led.c
+++ b/stmhal/led.c
@@ -25,15 +25,14 @@
*/
#include <stdio.h>
-#include STM32_HAL_H
#include "py/nlr.h"
#include "py/runtime.h"
+#include "py/mphal.h"
#include "timer.h"
#include "led.h"
#include "pin.h"
#include "genhdr/pins.h"
-#include "mphal.h"
#if defined(MICROPY_HW_LED1)
diff --git a/stmhal/main.c b/stmhal/main.c
index fe4b4c2..de52cac 100644
--- a/stmhal/main.c
+++ b/stmhal/main.c
@@ -34,6 +34,7 @@
#include "py/runtime.h"
#include "py/stackctrl.h"
#include "py/gc.h"
+#include "py/mphal.h"
#include "lib/fatfs/ff.h"
@@ -60,7 +61,6 @@
#include "dac.h"
#include "can.h"
#include "modnetwork.h"
-#include MICROPY_HAL_H
void SystemClock_Config(void);
diff --git a/stmhal/modmachine.c b/stmhal/modmachine.c
index fa6a1f9..6a0c4a9 100644
--- a/stmhal/modmachine.c
+++ b/stmhal/modmachine.c
@@ -29,6 +29,7 @@
#include "modmachine.h"
#include "py/gc.h"
#include "py/runtime.h"
+#include "py/mphal.h"
#include "lib/fatfs/ff.h"
#include "lib/fatfs/diskio.h"
#include "gccollect.h"
@@ -38,7 +39,6 @@
#include "pin.h"
#include "timer.h"
#include "usb.h"
-#include MICROPY_HAL_H
// machine.info([dump_alloc_table])
// Print out lots of information about the board.
diff --git a/stmhal/modnwwiznet5k.c b/stmhal/modnwwiznet5k.c
index 48d9be1..2feb9b9 100644
--- a/stmhal/modnwwiznet5k.c
+++ b/stmhal/modnwwiznet5k.c
@@ -32,12 +32,12 @@
#include "py/nlr.h"
#include "py/objlist.h"
#include "py/runtime.h"
+#include "py/mphal.h"
#include "netutils.h"
#include "modnetwork.h"
#include "pin.h"
#include "genhdr/pins.h"
#include "spi.h"
-#include MICROPY_HAL_H
#include "ethernet/wizchip_conf.h"
#include "ethernet/socket.h"
diff --git a/stmhal/moduselect.c b/stmhal/moduselect.c
index 0ba5954..232520e 100644
--- a/stmhal/moduselect.c
+++ b/stmhal/moduselect.c
@@ -30,8 +30,8 @@
#include "py/nlr.h"
#include "py/obj.h"
#include "py/objlist.h"
+#include "py/mphal.h"
#include "pybioctl.h"
-#include MICROPY_HAL_H
/// \module select - Provides select function to wait for events on a stream
///
diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h
index 5203213..3848daa 100644
--- a/stmhal/mpconfigport.h
+++ b/stmhal/mpconfigport.h
@@ -199,7 +199,6 @@
typedef const void *machine_const_ptr_t; // must be of pointer size
typedef long mp_off_t;
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
// We have inlined IRQ functions for efficiency (they are generally
@@ -242,7 +241,6 @@
// We need to provide a declaration/definition of alloca()
#include <alloca.h>
-#define MICROPY_HAL_H "mphal.h"
#define MICROPY_PIN_DEFS_PORT_H "pin_defs_stmhal.h"
#endif // __INCLUDED_MPCONFIGPORT_H
diff --git a/stmhal/mphal.c b/stmhal/mphalport.c
similarity index 94%
rename from stmhal/mphal.c
rename to stmhal/mphalport.c
index 145ed8a..147a868 100644
--- a/stmhal/mphal.c
+++ b/stmhal/mphalport.c
@@ -2,9 +2,9 @@
#include <string.h>
#include "py/mpstate.h"
+#include "py/mphal.h"
#include "usb.h"
#include "uart.h"
-#include "mphal.h"
// this table converts from HAL_StatusTypeDef to POSIX errno
const byte mp_hal_status_to_errno_table[4] = {
@@ -48,7 +48,7 @@
mp_hal_stdout_tx_strn(str, strlen(str));
}
-void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
+void mp_hal_stdout_tx_strn(const char *str, size_t len) {
if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
uart_tx_strn(MP_STATE_PORT(pyb_stdio_uart), str, len);
}
@@ -60,7 +60,7 @@
}
}
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
+void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
// send stdout to UART and USB CDC VCP
if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
uart_tx_strn_cooked(MP_STATE_PORT(pyb_stdio_uart), str, len);
diff --git a/stmhal/mphal.h b/stmhal/mphalport.h
similarity index 78%
rename from stmhal/mphal.h
rename to stmhal/mphalport.h
index bafee7b..652f1e7 100644
--- a/stmhal/mphal.h
+++ b/stmhal/mphalport.h
@@ -8,7 +8,7 @@
#elif defined(MCU_SERIES_F7)
#define MP_HAL_UNIQUE_ID_ADDRESS (0x1ff0f420)
#else
-#error mphal.h: Unrecognized MCU_SERIES
+#error mphalport.h: Unrecognized MCU_SERIES
#endif
// Basic GPIO functions
@@ -24,15 +24,10 @@
void mp_hal_gpio_clock_enable(GPIO_TypeDef *gpio);
-extern const byte mp_hal_status_to_errno_table[4];
+extern const unsigned char mp_hal_status_to_errno_table[4];
NORETURN void mp_hal_raise(HAL_StatusTypeDef status);
void mp_hal_set_interrupt_char(int c); // -1 to disable
-int mp_hal_stdin_rx_chr(void);
-void mp_hal_stdout_tx_str(const char *str);
-void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
-
#define mp_hal_delay_ms HAL_Delay
#define mp_hal_ticks_ms HAL_GetTick
diff --git a/stmhal/pin.c b/stmhal/pin.c
index 3aba949..a0f3994 100644
--- a/stmhal/pin.c
+++ b/stmhal/pin.c
@@ -30,7 +30,7 @@
#include "py/nlr.h"
#include "py/runtime.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
#include "pin.h"
/// \moduleref pyb
diff --git a/stmhal/pin_defs_stmhal.c b/stmhal/pin_defs_stmhal.c
index 6dfefb6..0aef5f9 100644
--- a/stmhal/pin_defs_stmhal.c
+++ b/stmhal/pin_defs_stmhal.c
@@ -1,6 +1,5 @@
#include "py/obj.h"
#include "pin.h"
-#include MICROPY_HAL_H
// Returns the pin mode. This value returned by this macro should be one of:
// GPIO_MODE_INPUT, GPIO_MODE_OUTPUT_PP, GPIO_MODE_OUTPUT_OD,
diff --git a/stmhal/pin_named_pins.c b/stmhal/pin_named_pins.c
index d0cf8ad..9e5f959 100644
--- a/stmhal/pin_named_pins.c
+++ b/stmhal/pin_named_pins.c
@@ -28,7 +28,7 @@
#include <string.h>
#include "py/runtime.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
#include "pin.h"
STATIC void pin_named_pins_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
diff --git a/stmhal/printf.c b/stmhal/printf.c
index 87cf4f0..611ad2d 100644
--- a/stmhal/printf.c
+++ b/stmhal/printf.c
@@ -29,9 +29,7 @@
#include <stdarg.h>
#include "py/obj.h"
-#ifdef MICROPY_HAL_H
-#include MICROPY_HAL_H
-#endif
+#include "py/mphal.h"
#if MICROPY_PY_BUILTINS_FLOAT
#include "py/formatfloat.h"
diff --git a/stmhal/pybstdio.c b/stmhal/pybstdio.c
index de0a3a0..72c164b 100644
--- a/stmhal/pybstdio.c
+++ b/stmhal/pybstdio.c
@@ -30,7 +30,7 @@
#include "py/obj.h"
#include "py/stream.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
// TODO make stdin, stdout and stderr writable objects so they can
// be changed by Python code. This requires some changes, as these
diff --git a/stmhal/pyexec.c b/stmhal/pyexec.c
index f5de904..116a41d 100644
--- a/stmhal/pyexec.c
+++ b/stmhal/pyexec.c
@@ -33,9 +33,7 @@
#include "py/runtime.h"
#include "py/repl.h"
#include "py/gc.h"
-#ifdef MICROPY_HAL_H
-#include MICROPY_HAL_H
-#endif
+#include "py/mphal.h"
#if defined(USE_DEVICE_MODE)
#include "irq.h"
#include "usb.h"
diff --git a/stmhal/spi.c b/stmhal/spi.c
index 864463d..7458da6 100644
--- a/stmhal/spi.c
+++ b/stmhal/spi.c
@@ -29,13 +29,13 @@
#include "py/nlr.h"
#include "py/runtime.h"
+#include "py/mphal.h"
#include "irq.h"
#include "pin.h"
#include "genhdr/pins.h"
#include "bufhelper.h"
#include "dma.h"
#include "spi.h"
-#include MICROPY_HAL_H
// The following defines are for compatability with the '405
#if !defined(MICROPY_HW_SPI1_NSS)
diff --git a/stmhal/stm32_it.c b/stmhal/stm32_it.c
index dfc33b7..1c510d3 100644
--- a/stmhal/stm32_it.c
+++ b/stmhal/stm32_it.c
@@ -92,7 +92,7 @@
#if REPORT_HARD_FAULT_REGS
-#include "mphal.h"
+#include "py/mphal.h"
char *fmt_hex(uint32_t val, char *buf) {
const char *hexDig = "0123456789abcdef";
diff --git a/stmhal/timer.c b/stmhal/timer.c
index f88229b..18c027c 100644
--- a/stmhal/timer.c
+++ b/stmhal/timer.c
@@ -35,7 +35,6 @@
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/gc.h"
-#include MICROPY_HAL_H
#include "timer.h"
#include "servo.h"
#include "pin.h"
diff --git a/stmhal/uart.c b/stmhal/uart.c
index 177318a..79c272b 100644
--- a/stmhal/uart.c
+++ b/stmhal/uart.c
@@ -32,9 +32,9 @@
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/stream.h"
+#include "py/mphal.h"
#include "uart.h"
#include "pybioctl.h"
-#include MICROPY_HAL_H
//TODO: Add UART7/8 support for MCU_SERIES_F7
diff --git a/stmhal/usbd_desc.c b/stmhal/usbd_desc.c
index 32e4fd0..1ad960b 100644
--- a/stmhal/usbd_desc.c
+++ b/stmhal/usbd_desc.c
@@ -35,7 +35,7 @@
// need these headers just for MP_HAL_UNIQUE_ID_ADDRESS
#include "py/misc.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
// So we don't clash with existing ST boards, we use the unofficial FOSS VID.
// This needs a proper solution.
diff --git a/stmhal/usrsw.c b/stmhal/usrsw.c
index 225373c..69b0ca9 100644
--- a/stmhal/usrsw.c
+++ b/stmhal/usrsw.c
@@ -27,10 +27,10 @@
#include <stdio.h>
#include "py/runtime.h"
+#include "py/mphal.h"
#include "extint.h"
#include "pin.h"
#include "genhdr/pins.h"
-#include "mphal.h"
#include "usrsw.h"
#if MICROPY_HW_HAS_SWITCH
diff --git a/teensy/led.c b/teensy/led.c
index 500900f..5798f53 100644
--- a/teensy/led.c
+++ b/teensy/led.c
@@ -4,8 +4,8 @@
#include "py/nlr.h"
#include "py/runtime.h"
+#include "py/mphal.h"
#include "led.h"
-#include MICROPY_HAL_H
#include "pin.h"
#include "genhdr/pins.h"
diff --git a/teensy/main.c b/teensy/main.c
index 4fa7aaa..c31be6e 100644
--- a/teensy/main.c
+++ b/teensy/main.c
@@ -9,13 +9,13 @@
#include "py/runtime.h"
#include "py/stackctrl.h"
#include "py/gc.h"
+#include "py/mphal.h"
#include "gccollect.h"
#include "pyexec.h"
#include "readline.h"
#include "lexermemzip.h"
#include "Arduino.h"
-#include MICROPY_HAL_H
#include "servo.h"
#include "led.h"
diff --git a/teensy/modpyb.c b/teensy/modpyb.c
index aded022..8429191 100644
--- a/teensy/modpyb.c
+++ b/teensy/modpyb.c
@@ -31,8 +31,7 @@
#include "py/obj.h"
#include "py/gc.h"
-
-#include MICROPY_HAL_H
+#include "py/mphal.h"
#include "gccollect.h"
#include "irq.h"
diff --git a/teensy/mpconfigport.h b/teensy/mpconfigport.h
index d4bfd1c..4b2181c 100644
--- a/teensy/mpconfigport.h
+++ b/teensy/mpconfigport.h
@@ -66,7 +66,6 @@
typedef const void *machine_const_ptr_t; // must be of pointer size
typedef long mp_off_t;
-void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len);
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
// We have inlined IRQ functions for efficiency (they are generally
@@ -149,5 +148,5 @@
#define MICROPY_MATH_SQRT_ASM (1)
-#define MICROPY_HAL_H "teensy_hal.h"
+#define MICROPY_MPHALPORT_H "teensy_hal.h"
#define MICROPY_PIN_DEFS_PORT_H "pin_defs_teensy.h"
diff --git a/teensy/pin_defs_teensy.c b/teensy/pin_defs_teensy.c
index fd2476f..e7af1e9 100644
--- a/teensy/pin_defs_teensy.c
+++ b/teensy/pin_defs_teensy.c
@@ -1,7 +1,7 @@
#include <stdint.h>
#include <mk20dx128.h>
#include "py/runtime.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
#include "pin.h"
// Returns the pin mode. This value returned by this macro should be one of:
diff --git a/teensy/teensy_hal.c b/teensy/teensy_hal.c
index 099848f..8996c27 100644
--- a/teensy/teensy_hal.c
+++ b/teensy/teensy_hal.c
@@ -2,16 +2,16 @@
#include <string.h>
#include "py/mpstate.h"
+#include "py/mphal.h"
#include "usb.h"
#include "uart.h"
#include "Arduino.h"
-#include MICROPY_HAL_H
-uint32_t mp_hal_ticks_ms(void) {
+mp_uint_t mp_hal_ticks_ms(void) {
return millis();
}
-void mp_hal_delay_ms(uint32_t ms) {
+void mp_hal_delay_ms(mp_uint_t ms) {
delay(ms);
}
@@ -37,7 +37,7 @@
mp_hal_stdout_tx_strn(str, strlen(str));
}
-void mp_hal_stdout_tx_strn(const char *str, uint32_t len) {
+void mp_hal_stdout_tx_strn(const char *str, size_t len) {
if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
uart_tx_strn(MP_STATE_PORT(pyb_stdio_uart), str, len);
}
@@ -46,7 +46,7 @@
}
}
-void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len) {
+void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
// send stdout to UART and USB CDC VCP
if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
uart_tx_strn_cooked(MP_STATE_PORT(pyb_stdio_uart), str, len);
diff --git a/teensy/teensy_hal.h b/teensy/teensy_hal.h
index 24402ee..b00b6e4 100644
--- a/teensy/teensy_hal.h
+++ b/teensy/teensy_hal.h
@@ -112,17 +112,10 @@
__asm volatile ("wfi");
}
-uint32_t mp_hal_ticks_ms(void);
-void mp_hal_delay_ms(uint32_t delay);
void mp_hal_set_interrupt_char(int c);
void mp_hal_gpio_clock_enable(GPIO_TypeDef *gpio);
-int mp_hal_stdin_rx_chr(void);
-void mp_hal_stdout_tx_str(const char *str);
-void mp_hal_stdout_tx_strn(const char *str, uint32_t len);
-void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len);
-
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *init);
#define GPIO_read_pin(gpio, pin) (((gpio)->PDIR >> (pin)) & 1)
diff --git a/teensy/timer.c b/teensy/timer.c
index 5d6237d..88583a0 100644
--- a/teensy/timer.c
+++ b/teensy/timer.c
@@ -32,7 +32,7 @@
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/gc.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
#include "pin.h"
#include "reg.h"
#include "timer.h"
diff --git a/teensy/uart.c b/teensy/uart.c
index 1a04bb0..81035ae 100644
--- a/teensy/uart.c
+++ b/teensy/uart.c
@@ -29,7 +29,6 @@
#include "py/nlr.h"
#include "py/runtime.h"
-#include MICROPY_HAL_H
#include "bufhelper.h"
#include "uart.h"
diff --git a/unix/input.c b/unix/input.c
index 9baa342..a38b63a 100644
--- a/unix/input.c
+++ b/unix/input.c
@@ -29,10 +29,10 @@
#include <string.h>
#include "py/mpstate.h"
+#include "py/mphal.h"
#include "input.h"
#if MICROPY_USE_READLINE == 1
-#include MICROPY_HAL_H
#include "lib/mp-readline/readline.h"
#elif MICROPY_USE_READLINE == 2
#include <readline/readline.h>
diff --git a/unix/main.c b/unix/main.c
index eed7065..1dc5419 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -44,8 +44,8 @@
#include "py/repl.h"
#include "py/gc.h"
#include "py/stackctrl.h"
+#include "py/mphal.h"
#include "genhdr/mpversion.h"
-#include MICROPY_HAL_H
#include "input.h"
// Command line options, with their defaults
diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h
index 13cf1e8..0e1fb6a 100644
--- a/unix/mpconfigport.h
+++ b/unix/mpconfigport.h
@@ -223,7 +223,7 @@
mp_obj_t keyboard_interrupt_obj; \
void *mmap_region_head; \
-#define MICROPY_HAL_H "unix_mphal.h"
+#define MICROPY_MPHALPORT_H "unix_mphal.h"
// We need to provide a declaration/definition of alloca()
#ifdef __FreeBSD__
diff --git a/unix/unix_mphal.c b/unix/unix_mphal.c
index 54a710a..308349c 100644
--- a/unix/unix_mphal.c
+++ b/unix/unix_mphal.c
@@ -30,7 +30,7 @@
#include <sys/time.h>
#include "py/mpstate.h"
-#include MICROPY_HAL_H
+#include "py/mphal.h"
#ifndef _WIN32
#include <signal.h>
@@ -119,7 +119,7 @@
mp_hal_stdout_tx_strn(str, strlen(str));
}
-uint32_t mp_hal_ticks_ms(void) {
+mp_uint_t mp_hal_ticks_ms(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
diff --git a/unix/unix_mphal.h b/unix/unix_mphal.h
index 2e10d48..8961722 100644
--- a/unix/unix_mphal.h
+++ b/unix/unix_mphal.h
@@ -33,10 +33,4 @@
void mp_hal_stdio_mode_raw(void);
void mp_hal_stdio_mode_orig(void);
-int mp_hal_stdin_rx_chr(void);
-void mp_hal_stdout_tx_str(const char *str);
-void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len);
-
-#define mp_hal_delay_ms(ms) usleep((ms) * 1000)
-uint32_t mp_hal_ticks_ms(void);
+static inline void mp_hal_delay_ms(mp_uint_t ms) { usleep((ms) * 1000); }
diff --git a/windows/mpconfigport.h b/windows/mpconfigport.h
index ce5783c..01e0665 100644
--- a/windows/mpconfigport.h
+++ b/windows/mpconfigport.h
@@ -156,7 +156,7 @@
#define MP_STATE_PORT MP_STATE_VM
-#define MICROPY_HAL_H "windows_mphal.h"
+#define MICROPY_MPHALPORT_H "windows_mphal.h"
// We need to provide a declaration/definition of alloca()
#include <malloc.h>
diff --git a/windows/windows_mphal.c b/windows/windows_mphal.c
index 2a803f1..702efa4 100644
--- a/windows/windows_mphal.c
+++ b/windows/windows_mphal.c
@@ -26,8 +26,8 @@
#include "py/mpstate.h"
+#include "py/mphal.h"
-#include MICROPY_HAL_H
#include <windows.h>
#include <unistd.h>
@@ -170,11 +170,11 @@
}
}
-void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
+void mp_hal_stdout_tx_strn(const char *str, size_t len) {
write(1, str, len);
}
-void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
+void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
mp_hal_stdout_tx_strn(str, len);
}
diff --git a/windows/windows_mphal.h b/windows/windows_mphal.h
index 8173d93..c36889d 100644
--- a/windows/windows_mphal.h
+++ b/windows/windows_mphal.h
@@ -24,6 +24,7 @@
* THE SOFTWARE.
*/
+#include "sleep.h"
#include "unix/unix_mphal.h"
#define MICROPY_HAL_HAS_VT100 (0)