1 #ifndef INCLUDED_MPHALPORT_H 2 #define INCLUDED_MPHALPORT_H 3 4 #include "py/ringbuf.h" 5 #include "shared/runtime/interrupt_char.h" 6 7 typedef uint32_t cpu_stack_t; 8 9 extern ringbuf_t stdin_ringbuf; 10 11 extern void mp_hal_set_interrupt_char(int c); 12 13 // This macro is used to implement PEP 475 to retry specified syscalls on EINTR 14 #define MP_HAL_RETRY_SYSCALL(ret, syscall, raise) { \ 15 for (;;) { \ 16 MP_THREAD_GIL_EXIT(); \ 17 ret = syscall; \ 18 MP_THREAD_GIL_ENTER(); \ 19 if (ret == -1) { \ 20 int err = errno; \ 21 if (err == EINTR) { \ 22 mp_handle_pending(true); \ 23 continue; \ 24 } \ 25 raise; \ 26 } \ 27 break; \ 28 } \ 29 } 30 31 #define RAISE_ERRNO(err_flag, error_val) \ 32 { if (err_flag == -1) \ 33 { mp_raise_OSError(error_val); } } 34 35 #define mp_hal_delay_us_fast(us) mp_hal_delay_us(us) 36 37 38 #include "py/obj.h" 39 #include "aos_hal_gpio.h" 40 41 #ifdef CONFIG_GPIO_NUM 42 #define PY_GPIO_NUM_MAX CONFIG_GPIO_NUM 43 #else 44 #define PY_GPIO_NUM_MAX 64 45 #endif 46 47 #define MP_HAL_PIN_FMT "%u" 48 #define mp_hal_pin_obj_t uint32_t 49 50 extern gpio_config_t mphal_gpio_config_obj_t[PY_GPIO_NUM_MAX]; 51 52 mp_hal_pin_obj_t machine_pin_get_id(mp_obj_t pin_in); 53 gpio_config_t mp_hal_pin_config_get(mp_hal_pin_obj_t pin_obj); 54 int32_t mp_hal_pin_low(mp_hal_pin_obj_t pin_obj); 55 int32_t mp_hal_pin_high(mp_hal_pin_obj_t pin_obj); 56 int32_t mp_hal_pin_config_set(mp_hal_pin_obj_t pin_obj, gpio_config_t config); 57 58 #define mp_hal_get_pin_obj(o) machine_pin_get_id(o) 59 #define mp_hal_pin_name(p) (p) 60 #define mp_hal_pin_input(p) mp_hal_pin_config_set((p), INPUT_PULL_UP) 61 #define mp_hal_pin_output(p) mp_hal_pin_config_set((p), OUTPUT_PUSH_PULL) 62 #define mp_hal_pin_open_drain(p) mp_hal_pin_config_set((p), OUTPUT_OPEN_DRAIN_NO_PULL) 63 #define mp_hal_pin_od_low(p) mp_hal_pin_low(p) 64 #define mp_hal_pin_od_high(p) mp_hal_pin_high(p) 65 #define mp_hal_pin_write(p, v) ((v) ? mp_hal_pin_high(p) : mp_hal_pin_low(p)) 66 67 #endif // INCLUDED_MPHALPORT_H