blob: 35955f2d3ee5726fe329d1258f327e88d507d243 [file] [log] [blame]
Damien George43ea73f2015-03-28 21:45:40 +00001/*
Alexander Steffen55f33242017-06-30 09:22:17 +02002 * This file is part of the MicroPython project, http://micropython.org/
Damien George43ea73f2015-03-28 21:45:40 +00003 *
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 George731f3592015-10-30 23:03:58 +000028#include "py/mphal.h"
Damien George43ea73f2015-03-28 21:45:40 +000029#include "board.h"
30
31static int interrupt_char;
32
33void mp_hal_init(void) {
34 MP_STATE_PORT(keyboard_interrupt_obj) = mp_obj_new_exception(&mp_type_KeyboardInterrupt);
35}
36
Damien George731f3592015-10-30 23:03:58 +000037mp_uint_t mp_hal_ticks_ms(void) {
Damien George43ea73f2015-03-28 21:45:40 +000038 // TODO
39 return 0;
40}
41
Damien George731f3592015-10-30 23:03:58 +000042void mp_hal_delay_ms(mp_uint_t ms) {
Damien George43ea73f2015-03-28 21:45:40 +000043 // 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
50void mp_hal_set_interrupt_char(int c) {
51 interrupt_char = c;
52}
53
54int mp_hal_stdin_rx_chr(void) {
55 for (;;) {
56 if (uart_rx_any()) {
57 return uart_rx_char();
58 }
59 }
60}
61
62void mp_hal_stdout_tx_str(const char *str) {
63 mp_hal_stdout_tx_strn(str, strlen(str));
64}
65
Damien George731f3592015-10-30 23:03:58 +000066void mp_hal_stdout_tx_strn(const char *str, size_t len) {
Damien George43ea73f2015-03-28 21:45:40 +000067 for (; len > 0; --len) {
68 uart_tx_char(*str++);
69 }
70}
71
Damien George731f3592015-10-30 23:03:58 +000072void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
Damien George43ea73f2015-03-28 21:45:40 +000073 for (; len > 0; --len) {
74 if (*str == '\n') {
75 uart_tx_char('\r');
76 }
77 uart_tx_char(*str++);
78 }
79}