summaryrefslogtreecommitdiffstats
path: root/bsps/arm/raspberrypi/console/fbcons.c
blob: 0c0a5087cec685b16cf834cf519b496b9569f72e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**
 * @file
 *
 * @ingroup raspberrypi_console
 *
 * @brief framebuffer graphic console support.
 */

/*
 * Copyright (c) 2015 Yang Qiao
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *
 *  http://www.rtems.org/license/LICENSE
 *
 */

#include <rtems.h>
#include <rtems/libio.h>
#include <rtems/termiostypes.h>

#include <stdlib.h>

#include <libchip/serial.h>
#include <libchip/sersupp.h>

#include <bsp.h>
#include <bsp/fbcons.h>
#include <bsp/vc.h>
#include <bsp/rpi-fb.h>

/*
 *  fbcons_open
 *
 *  This function opens a port for communication.
 *
 *  Default state is 9600 baud, 8 bits, No parity, and 1 stop bit.
 */
static bool fbcons_open(
  struct rtems_termios_tty *tty,
  rtems_termios_device_context *base,
  struct termios *term,
  rtems_libio_open_close_args_t *args
)
{
  return true;
}

/*
 *  fbcons_close
 *
 *  This function shuts down the requested port.
 */
static void fbcons_close(
  struct rtems_termios_tty *tty,
  rtems_termios_device_context *base,
  rtems_libio_open_close_args_t *args
)
{
}

/*
 *  fbcons_write_polled
 *
 *  This routine polls out the requested character.
 */
void fbcons_write_polled(
  rtems_termios_device_context *base,
  char c
)
{
  rpi_fb_outch( c );

  if ( c == '\n' )
    rpi_fb_outch( '\r' );            /* LF = LF + CR */
}

/*
 *  fbcons_write_support_polled
 *
 *  Console Termios output entry point when using polled output.
 *
 */
static void fbcons_write_support_polled(
  rtems_termios_device_context *base,
  const char *buf,
  size_t      len
)
{
  int nwrite = 0;

  /*
   * poll each byte in the string out of the port.
   */
  while ( nwrite < len ) {
    fbcons_write_polled( base, *buf++ );
    nwrite++;
  }
}

/*
 *  fbcons_inbyte_nonblocking_polled
 *
 *  Console Termios polling input entry point.
 */
static int fbcons_inbyte_nonblocking_polled(
  rtems_termios_device_context *base
)
{
  // if( rtems_kbpoll() ) {
  //   int c = getch();
  //   return c;
  // }

  return -1;
}

/*
 *  fbcons_set_attributes
 *
 *  This function sets the UART channel to reflect the requested termios
 *  port settings.
 */
static bool fbcons_set_attributes(
  rtems_termios_device_context *base,
  const struct termios *t
)
{
  return true;
}

bool fbcons_probe(
  rtems_termios_device_context *context
)
{
  // rtems_status_code status;
  static bool firstTime = true;
  static bool ret = false;

  /*
   *  keyboard interrupt should be registered when the keyboard is available
   */
  if ( firstTime ) {
    if ( !rpi_fb_hdmi_is_present() ) {
      ret = false;
    } else {
      ret = true;
    }
  }

  firstTime = false;

  return ret;
}

const rtems_termios_device_handler fbcons_fns =
{
  .first_open = fbcons_open,
  .last_close = fbcons_close,
  .poll_read = fbcons_inbyte_nonblocking_polled,
  .write = fbcons_write_support_polled,
  .set_attributes = fbcons_set_attributes,
  .mode = TERMIOS_POLLED
};