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
......@@ -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
......
......@@ -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.
......
......@@ -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
......
......@@ -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"
......
......@@ -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"
......
......@@ -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"
......
......@@ -66,7 +66,6 @@ typedef void *machine_ptr_t; // must be of pointer size
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 @@ __attribute__(( always_inline )) static inline mp_uint_t disable_irq(void) {
#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"
#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:
......
......@@ -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 @@ void mp_hal_stdout_tx_str(const char *str) {
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(const char *str, uint32_t 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) {
// 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);
......
......@@ -112,17 +112,10 @@ __attribute__(( always_inline )) static inline void __WFI(void) {
__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)
......
......@@ -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"
......
......@@ -29,7 +29,6 @@
#include "py/nlr.h"
#include "py/runtime.h"
#include MICROPY_HAL_H
#include "bufhelper.h"
#include "uart.h"
......
......@@ -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>
......
......@@ -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
......
......@@ -223,7 +223,7 @@ extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
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__
......
......@@ -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 @@ void mp_hal_stdout_tx_str(const char *str) {
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;
......
......@@ -33,10 +33,4 @@ void mp_hal_set_interrupt_char(char c);
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); }
......@@ -156,7 +156,7 @@ extern const struct _mp_obj_module_t mp_module_time;
#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>
......
......@@ -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 @@ int mp_hal_stdin_rx_chr(void) {
}
}
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);
}
......
......@@ -24,6 +24,7 @@
* THE SOFTWARE.
*/
#include "sleep.h"
#include "unix/unix_mphal.h"
#define MICROPY_HAL_HAS_VT100 (0)
......
Markdown is supported
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