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