Damien George | 43ea73f | 2015-03-28 21:45:40 +0000 | [diff] [blame] | 1 | /* |
Alexander Steffen | 55f3324 | 2017-06-30 09:22:17 +0200 | [diff] [blame^] | 2 | * This file is part of the MicroPython project, http://micropython.org/ |
Damien George | 43ea73f | 2015-03-28 21:45:40 +0000 | [diff] [blame] | 3 | * |
| 4 | * The MIT License (MIT) |
| 5 | * |
| 6 | * Copyright (c) 2015 Damien P. George |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | * of this software and associated documentation files (the "Software"), to deal |
| 10 | * in the Software without restriction, including without limitation the rights |
| 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | * copies of the Software, and to permit persons to whom the Software is |
| 13 | * furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included in |
| 16 | * all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | * THE SOFTWARE. |
| 25 | */ |
| 26 | |
| 27 | #include <string.h> |
Damien George | 731f359 | 2015-10-30 23:03:58 +0000 | [diff] [blame] | 28 | #include "py/mphal.h" |
Damien George | 43ea73f | 2015-03-28 21:45:40 +0000 | [diff] [blame] | 29 | #include "board.h" |
| 30 | |
| 31 | static int interrupt_char; |
| 32 | |
| 33 | void mp_hal_init(void) { |
| 34 | MP_STATE_PORT(keyboard_interrupt_obj) = mp_obj_new_exception(&mp_type_KeyboardInterrupt); |
| 35 | } |
| 36 | |
Damien George | 731f359 | 2015-10-30 23:03:58 +0000 | [diff] [blame] | 37 | mp_uint_t mp_hal_ticks_ms(void) { |
Damien George | 43ea73f | 2015-03-28 21:45:40 +0000 | [diff] [blame] | 38 | // TODO |
| 39 | return 0; |
| 40 | } |
| 41 | |
Damien George | 731f359 | 2015-10-30 23:03:58 +0000 | [diff] [blame] | 42 | void mp_hal_delay_ms(mp_uint_t ms) { |
Damien George | 43ea73f | 2015-03-28 21:45:40 +0000 | [diff] [blame] | 43 | // tuned for fixed CPU frequency |
| 44 | for (int i = ms; i > 0; i--) { |
| 45 | for (volatile int j = 0; j < 5000; j++) { |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void mp_hal_set_interrupt_char(int c) { |
| 51 | interrupt_char = c; |
| 52 | } |
| 53 | |
| 54 | int mp_hal_stdin_rx_chr(void) { |
| 55 | for (;;) { |
| 56 | if (uart_rx_any()) { |
| 57 | return uart_rx_char(); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void mp_hal_stdout_tx_str(const char *str) { |
| 63 | mp_hal_stdout_tx_strn(str, strlen(str)); |
| 64 | } |
| 65 | |
Damien George | 731f359 | 2015-10-30 23:03:58 +0000 | [diff] [blame] | 66 | void mp_hal_stdout_tx_strn(const char *str, size_t len) { |
Damien George | 43ea73f | 2015-03-28 21:45:40 +0000 | [diff] [blame] | 67 | for (; len > 0; --len) { |
| 68 | uart_tx_char(*str++); |
| 69 | } |
| 70 | } |
| 71 | |
Damien George | 731f359 | 2015-10-30 23:03:58 +0000 | [diff] [blame] | 72 | void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) { |
Damien George | 43ea73f | 2015-03-28 21:45:40 +0000 | [diff] [blame] | 73 | for (; len > 0; --len) { |
| 74 | if (*str == '\n') { |
| 75 | uart_tx_char('\r'); |
| 76 | } |
| 77 | uart_tx_char(*str++); |
| 78 | } |
| 79 | } |