Commit 731f3592 authored by Damien George's avatar Damien George Committed by Paul Sokolovsky
Browse files

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.
parent 0bd3f329
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include "py/nlr.h" #include "py/nlr.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "py/gc.h" #include "py/gc.h"
#include MICROPY_HAL_H #include "py/mphal.h"
#include "pin.h" #include "pin.h"
#include "extint.h" #include "extint.h"
......
...@@ -29,13 +29,13 @@ ...@@ -29,13 +29,13 @@
#include "py/nlr.h" #include "py/nlr.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "py/mphal.h"
#include "irq.h" #include "irq.h"
#include "pin.h" #include "pin.h"
#include "genhdr/pins.h" #include "genhdr/pins.h"
#include "bufhelper.h" #include "bufhelper.h"
#include "dma.h" #include "dma.h"
#include "i2c.h" #include "i2c.h"
#include MICROPY_HAL_H
#if !defined(MICROPY_HW_I2C_BAUDRATE_DEFAULT) #if !defined(MICROPY_HW_I2C_BAUDRATE_DEFAULT)
#define MICROPY_HW_I2C_BAUDRATE_DEFAULT 400000 #define MICROPY_HW_I2C_BAUDRATE_DEFAULT 400000
......
...@@ -26,10 +26,9 @@ ...@@ -26,10 +26,9 @@
#include "py/nlr.h" #include "py/nlr.h"
#include "py/obj.h" #include "py/obj.h"
#include "py/mphal.h"
#include "irq.h" #include "irq.h"
#include MICROPY_HAL_H
/// \moduleref pyb /// \moduleref pyb
/// \function wfi() /// \function wfi()
......
...@@ -25,15 +25,14 @@ ...@@ -25,15 +25,14 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include STM32_HAL_H
#include "py/nlr.h" #include "py/nlr.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "py/mphal.h"
#include "timer.h" #include "timer.h"
#include "led.h" #include "led.h"
#include "pin.h" #include "pin.h"
#include "genhdr/pins.h" #include "genhdr/pins.h"
#include "mphal.h"
#if defined(MICROPY_HW_LED1) #if defined(MICROPY_HW_LED1)
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "py/stackctrl.h" #include "py/stackctrl.h"
#include "py/gc.h" #include "py/gc.h"
#include "py/mphal.h"
#include "lib/fatfs/ff.h" #include "lib/fatfs/ff.h"
...@@ -60,7 +61,6 @@ ...@@ -60,7 +61,6 @@
#include "dac.h" #include "dac.h"
#include "can.h" #include "can.h"
#include "modnetwork.h" #include "modnetwork.h"
#include MICROPY_HAL_H
void SystemClock_Config(void); void SystemClock_Config(void);
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "modmachine.h" #include "modmachine.h"
#include "py/gc.h" #include "py/gc.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "py/mphal.h"
#include "lib/fatfs/ff.h" #include "lib/fatfs/ff.h"
#include "lib/fatfs/diskio.h" #include "lib/fatfs/diskio.h"
#include "gccollect.h" #include "gccollect.h"
...@@ -38,7 +39,6 @@ ...@@ -38,7 +39,6 @@
#include "pin.h" #include "pin.h"
#include "timer.h" #include "timer.h"
#include "usb.h" #include "usb.h"
#include MICROPY_HAL_H
// machine.info([dump_alloc_table]) // machine.info([dump_alloc_table])
// Print out lots of information about the board. // Print out lots of information about the board.
......
...@@ -32,12 +32,12 @@ ...@@ -32,12 +32,12 @@
#include "py/nlr.h" #include "py/nlr.h"
#include "py/objlist.h" #include "py/objlist.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "py/mphal.h"
#include "netutils.h" #include "netutils.h"
#include "modnetwork.h" #include "modnetwork.h"
#include "pin.h" #include "pin.h"
#include "genhdr/pins.h" #include "genhdr/pins.h"
#include "spi.h" #include "spi.h"
#include MICROPY_HAL_H
#include "ethernet/wizchip_conf.h" #include "ethernet/wizchip_conf.h"
#include "ethernet/socket.h" #include "ethernet/socket.h"
......
...@@ -30,8 +30,8 @@ ...@@ -30,8 +30,8 @@
#include "py/nlr.h" #include "py/nlr.h"
#include "py/obj.h" #include "py/obj.h"
#include "py/objlist.h" #include "py/objlist.h"
#include "py/mphal.h"
#include "pybioctl.h" #include "pybioctl.h"
#include MICROPY_HAL_H
/// \module select - Provides select function to wait for events on a stream /// \module select - Provides select function to wait for events on a stream
/// ///
......
...@@ -199,7 +199,6 @@ typedef void *machine_ptr_t; // must be of pointer size ...@@ -199,7 +199,6 @@ typedef void *machine_ptr_t; // must be of pointer size
typedef const void *machine_const_ptr_t; // must be of pointer size typedef const void *machine_const_ptr_t; // must be of pointer size
typedef long mp_off_t; 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) #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 // We have inlined IRQ functions for efficiency (they are generally
...@@ -242,7 +241,6 @@ static inline mp_uint_t disable_irq(void) { ...@@ -242,7 +241,6 @@ static inline mp_uint_t disable_irq(void) {
// We need to provide a declaration/definition of alloca() // We need to provide a declaration/definition of alloca()
#include <alloca.h> #include <alloca.h>
#define MICROPY_HAL_H "mphal.h"
#define MICROPY_PIN_DEFS_PORT_H "pin_defs_stmhal.h" #define MICROPY_PIN_DEFS_PORT_H "pin_defs_stmhal.h"
#endif // __INCLUDED_MPCONFIGPORT_H #endif // __INCLUDED_MPCONFIGPORT_H
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
#include <string.h> #include <string.h>
#include "py/mpstate.h" #include "py/mpstate.h"
#include "py/mphal.h"
#include "usb.h" #include "usb.h"
#include "uart.h" #include "uart.h"
#include "mphal.h"
// this table converts from HAL_StatusTypeDef to POSIX errno // this table converts from HAL_StatusTypeDef to POSIX errno
const byte mp_hal_status_to_errno_table[4] = { const byte mp_hal_status_to_errno_table[4] = {
...@@ -48,7 +48,7 @@ void mp_hal_stdout_tx_str(const char *str) { ...@@ -48,7 +48,7 @@ void mp_hal_stdout_tx_str(const char *str) {
mp_hal_stdout_tx_strn(str, strlen(str)); 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) { if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
uart_tx_strn(MP_STATE_PORT(pyb_stdio_uart), str, len); uart_tx_strn(MP_STATE_PORT(pyb_stdio_uart), str, len);
} }
...@@ -60,7 +60,7 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { ...@@ -60,7 +60,7 @@ 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) { void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
// send stdout to UART and USB CDC VCP // send stdout to UART and USB CDC VCP
if (MP_STATE_PORT(pyb_stdio_uart) != NULL) { if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
uart_tx_strn_cooked(MP_STATE_PORT(pyb_stdio_uart), str, len); uart_tx_strn_cooked(MP_STATE_PORT(pyb_stdio_uart), str, len);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#elif defined(MCU_SERIES_F7) #elif defined(MCU_SERIES_F7)
#define MP_HAL_UNIQUE_ID_ADDRESS (0x1ff0f420) #define MP_HAL_UNIQUE_ID_ADDRESS (0x1ff0f420)
#else #else
#error mphal.h: Unrecognized MCU_SERIES #error mphalport.h: Unrecognized MCU_SERIES
#endif #endif
// Basic GPIO functions // Basic GPIO functions
...@@ -24,15 +24,10 @@ ...@@ -24,15 +24,10 @@
void mp_hal_gpio_clock_enable(GPIO_TypeDef *gpio); 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); NORETURN void mp_hal_raise(HAL_StatusTypeDef status);
void mp_hal_set_interrupt_char(int c); // -1 to disable 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_delay_ms HAL_Delay
#define mp_hal_ticks_ms HAL_GetTick #define mp_hal_ticks_ms HAL_GetTick
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include "py/nlr.h" #include "py/nlr.h"
#include "py/runtime.h" #include "py/runtime.h"
#include MICROPY_HAL_H #include "py/mphal.h"
#include "pin.h" #include "pin.h"
/// \moduleref pyb /// \moduleref pyb
......
#include "py/obj.h" #include "py/obj.h"
#include "pin.h" #include "pin.h"
#include MICROPY_HAL_H
// Returns the pin mode. This value returned by this macro should be one of: // 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, // GPIO_MODE_INPUT, GPIO_MODE_OUTPUT_PP, GPIO_MODE_OUTPUT_OD,
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include <string.h> #include <string.h>
#include "py/runtime.h" #include "py/runtime.h"
#include MICROPY_HAL_H #include "py/mphal.h"
#include "pin.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) { STATIC void pin_named_pins_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
......
...@@ -29,9 +29,7 @@ ...@@ -29,9 +29,7 @@
#include <stdarg.h> #include <stdarg.h>
#include "py/obj.h" #include "py/obj.h"
#ifdef MICROPY_HAL_H #include "py/mphal.h"
#include MICROPY_HAL_H
#endif
#if MICROPY_PY_BUILTINS_FLOAT #if MICROPY_PY_BUILTINS_FLOAT
#include "py/formatfloat.h" #include "py/formatfloat.h"
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include "py/obj.h" #include "py/obj.h"
#include "py/stream.h" #include "py/stream.h"
#include MICROPY_HAL_H #include "py/mphal.h"
// TODO make stdin, stdout and stderr writable objects so they can // TODO make stdin, stdout and stderr writable objects so they can
// be changed by Python code. This requires some changes, as these // be changed by Python code. This requires some changes, as these
......
...@@ -33,9 +33,7 @@ ...@@ -33,9 +33,7 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "py/repl.h" #include "py/repl.h"
#include "py/gc.h" #include "py/gc.h"
#ifdef MICROPY_HAL_H #include "py/mphal.h"
#include MICROPY_HAL_H
#endif
#if defined(USE_DEVICE_MODE) #if defined(USE_DEVICE_MODE)
#include "irq.h" #include "irq.h"
#include "usb.h" #include "usb.h"
......
...@@ -29,13 +29,13 @@ ...@@ -29,13 +29,13 @@
#include "py/nlr.h" #include "py/nlr.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "py/mphal.h"
#include "irq.h" #include "irq.h"
#include "pin.h" #include "pin.h"
#include "genhdr/pins.h" #include "genhdr/pins.h"
#include "bufhelper.h" #include "bufhelper.h"
#include "dma.h" #include "dma.h"
#include "spi.h" #include "spi.h"
#include MICROPY_HAL_H
// The following defines are for compatability with the '405 // The following defines are for compatability with the '405
#if !defined(MICROPY_HW_SPI1_NSS) #if !defined(MICROPY_HW_SPI1_NSS)
......
...@@ -92,7 +92,7 @@ extern PCD_HandleTypeDef pcd_handle; ...@@ -92,7 +92,7 @@ extern PCD_HandleTypeDef pcd_handle;
#if REPORT_HARD_FAULT_REGS #if REPORT_HARD_FAULT_REGS
#include "mphal.h" #include "py/mphal.h"
char *fmt_hex(uint32_t val, char *buf) { char *fmt_hex(uint32_t val, char *buf) {
const char *hexDig = "0123456789abcdef"; const char *hexDig = "0123456789abcdef";
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include "py/nlr.h" #include "py/nlr.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "py/gc.h" #include "py/gc.h"
#include MICROPY_HAL_H
#include "timer.h" #include "timer.h"
#include "servo.h" #include "servo.h"
#include "pin.h" #include "pin.h"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment