Rev 3582 | Rev 3672 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3582 | Rev 3618 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
3 | * Copyright (c) 2008 Martin Decky |
3 | * Copyright (c) 2008 Martin Decky |
4 | * Copyright (c) 2008 Pavel Rimsky |
4 | * Copyright (c) 2008 Pavel Rimsky |
5 | * All rights reserved. |
5 | * All rights reserved. |
6 | * |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without |
7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions |
8 | * modification, are permitted provided that the following conditions |
9 | * are met: |
9 | * are met: |
10 | * |
10 | * |
11 | * - Redistributions of source code must retain the above copyright |
11 | * - Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. |
12 | * notice, this list of conditions and the following disclaimer. |
13 | * - Redistributions in binary form must reproduce the above copyright |
13 | * - Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the |
14 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. |
15 | * documentation and/or other materials provided with the distribution. |
16 | * - The name of the author may not be used to endorse or promote products |
16 | * - The name of the author may not be used to endorse or promote products |
17 | * derived from this software without specific prior written permission. |
17 | * derived from this software without specific prior written permission. |
18 | * |
18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | */ |
29 | */ |
30 | 30 | ||
31 | /** |
31 | /** |
32 | * @defgroup serial Serial console |
32 | * @defgroup serial Serial console |
33 | * @brief Serial console services (putc, puts, clear screen, cursor goto,...).* |
33 | * @brief Serial console services (putc, puts, clear screen, cursor goto,...) |
34 | * @{ |
34 | * @{ |
35 | */ |
35 | */ |
36 | 36 | ||
37 | /** @file |
37 | /** @file |
38 | */ |
38 | */ |
39 | 39 | ||
40 | #include <stdio.h> |
40 | #include <stdio.h> |
41 | 41 | ||
42 | #include "serial_console.h" |
42 | #include "serial_console.h" |
43 | 43 | ||
44 | #define MAX_CONTROL 20 |
44 | #define MAX_CONTROL 20 |
45 | 45 | ||
46 | static uint32_t width; |
46 | static uint32_t width; |
47 | static uint32_t height; |
47 | static uint32_t height; |
48 | static putc_function_t putc_function; |
48 | static putc_function_t putc_function; |
49 | 49 | ||
50 | void serial_puts(char *str) |
50 | void serial_puts(char *str) |
51 | { |
51 | { |
52 | while (*str) |
52 | while (*str) |
53 | putc_function(*(str++)); |
53 | putc_function(*(str++)); |
54 | } |
54 | } |
55 | 55 | ||
56 | void serial_goto(const unsigned int row, const unsigned int col) |
56 | void serial_goto(const unsigned int row, const unsigned int col) |
57 | { |
57 | { |
58 | if ((row > height) || (col > width)) |
58 | if ((row > height) || (col > width)) |
59 | return; |
59 | return; |
60 | 60 | ||
61 | char control[20]; |
61 | char control[20]; |
62 | snprintf(control, 20, "\033[%u;%uf", row + 1, col + 1); |
62 | snprintf(control, 20, "\033[%u;%uf", row + 1, col + 1); |
63 | serial_puts(control); |
63 | serial_puts(control); |
64 | } |
64 | } |
65 | 65 | ||
66 | void serial_clrscr(void) |
66 | void serial_clrscr(void) |
67 | { |
67 | { |
68 | serial_puts("\033[2J"); |
68 | serial_puts("\033[2J"); |
69 | } |
69 | } |
70 | 70 | ||
71 | void serial_scroll(int i) |
71 | void serial_scroll(int i) |
72 | { |
72 | { |
73 | if (i > 0) { |
73 | if (i > 0) { |
74 | serial_goto(height - 1, 0); |
74 | serial_goto(height - 1, 0); |
75 | while (i--) |
75 | while (i--) |
76 | serial_puts("\033D"); |
76 | serial_puts("\033D"); |
77 | } else if (i < 0) { |
77 | } else if (i < 0) { |
78 | serial_goto(0, 0); |
78 | serial_goto(0, 0); |
79 | while (i++) |
79 | while (i++) |
80 | serial_puts("\033M"); |
80 | serial_puts("\033M"); |
81 | } |
81 | } |
82 | } |
82 | } |
83 | 83 | ||
84 | void serial_set_style(const unsigned int mode) |
84 | void serial_set_style(const unsigned int mode) |
85 | { |
85 | { |
86 | char control[MAX_CONTROL]; |
86 | char control[MAX_CONTROL]; |
87 | snprintf(control, MAX_CONTROL, "\033[%um", mode); |
87 | snprintf(control, MAX_CONTROL, "\033[%um", mode); |
88 | serial_puts(control); |
88 | serial_puts(control); |
89 | } |
89 | } |
90 | 90 | ||
91 | void serial_cursor_disable(void) |
91 | void serial_cursor_disable(void) |
92 | { |
92 | { |
93 | serial_puts("\033[?25l"); |
93 | serial_puts("\033[?25l"); |
94 | } |
94 | } |
95 | 95 | ||
96 | void serial_cursor_enable(void) |
96 | void serial_cursor_enable(void) |
97 | { |
97 | { |
98 | serial_puts("\033[?25h"); |
98 | serial_puts("\033[?25h"); |
99 | } |
99 | } |
100 | 100 | ||
101 | void serial_console_init(putc_function_t putc_fn, uint32_t w, uint32_t h) |
101 | void serial_console_init(putc_function_t putc_fn, uint32_t w, uint32_t h) |
102 | { |
102 | { |
103 | width = w; |
103 | width = w; |
104 | height = h; |
104 | height = h; |
105 | putc_function = putc_fn; |
105 | putc_function = putc_fn; |
106 | } |
106 | } |
107 | 107 | ||
108 | /** |
108 | /** |
109 | * @} |
109 | * @} |
110 | */ |
- | |
111 | 110 | */ |
|
- | 111 |