summaryrefslogtreecommitdiffstats
path: root/bsps/arm/raspberrypi/console/fbcons.c
blob: 3669ba458df9f7e8a105da25cbf9b720373cc5f3 (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
166
167
168
169
170
171
172
173
174
175
176
177
/**
 * @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 <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_init
 *
 *  This function initializes the fb console to a quiecsent state.
 */
static void fbcons_init( int minor )
{
}

/*
 *  fbcons_open
 *
 *  This function opens a port for communication.
 *
 *  Default state is 9600 baud, 8 bits, No parity, and 1 stop bit.
 */
static int fbcons_open(
  int   major,
  int   minor,
  void *arg
)
{
  return RTEMS_SUCCESSFUL;
}

/*
 *  fbcons_close
 *
 *  This function shuts down the requested port.
 */
static int fbcons_close(
  int   major,
  int   minor,
  void *arg
)
{
  return ( RTEMS_SUCCESSFUL );
}

/*
 *  fbcons_write_polled
 *
 *  This routine polls out the requested character.
 */
static void fbcons_write_polled(
  int  minor,
  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 ssize_t fbcons_write_support_polled(
  int         minor,
  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( minor, *buf++ );
    nwrite++;
  }

  /*
   * return the number of bytes written.
   */
  return nwrite;
}

/*
 *  fbcons_inbyte_nonblocking_polled
 *
 *  Console Termios polling input entry point.
 */
static int fbcons_inbyte_nonblocking_polled( int minor )
{
  // 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 int fbcons_set_attributes(
  int                   minor,
  const struct termios *t
)
{
  return 0;
}

bool fbcons_probe( int minor )
{
  // 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 console_fns fbcons_fns =
{
  .deviceProbe = libchip_serial_default_probe,     /* deviceProbe */
  .deviceFirstOpen = fbcons_open,                 /* deviceFirstOpen */
  .deviceLastClose = fbcons_close,                /* deviceLastClose */
  .deviceRead = fbcons_inbyte_nonblocking_polled, /* deviceRead */
  .deviceWrite = fbcons_write_support_polled,     /* deviceWrite */
  .deviceInitialize = fbcons_init,                /* deviceInitialize */
  .deviceWritePolled = fbcons_write_polled,       /* deviceWritePolled */
  .deviceSetAttributes = fbcons_set_attributes,   /* deviceSetAttributes */
  .deviceOutputUsesInterrupts = FALSE,           /* deviceOutputUsesInterrupts*/
};