Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:04

0001 /**
0002  * @file
0003  *
0004  * @ingroup raspberrypi_console
0005  *
0006  * @brief framebuffer graphic console support.
0007  */
0008 
0009 /*
0010  * Copyright (c) 2015 Yang Qiao
0011  *
0012  *  The license and distribution terms for this file may be
0013  *  found in the file LICENSE in this distribution or at
0014  *
0015  *  http://www.rtems.org/license/LICENSE
0016  *
0017  */
0018 
0019 #include <rtems.h>
0020 #include <rtems/libio.h>
0021 #include <rtems/termiostypes.h>
0022 
0023 #include <stdlib.h>
0024 
0025 #include <libchip/serial.h>
0026 #include <libchip/sersupp.h>
0027 
0028 #include <bsp.h>
0029 #include <bsp/fbcons.h>
0030 #include <bsp/vc.h>
0031 #include <bsp/rpi-fb.h>
0032 
0033 /*
0034  *  fbcons_open
0035  *
0036  *  This function opens a port for communication.
0037  *
0038  *  Default state is 9600 baud, 8 bits, No parity, and 1 stop bit.
0039  */
0040 static bool fbcons_open(
0041   struct rtems_termios_tty *tty,
0042   rtems_termios_device_context *base,
0043   struct termios *term,
0044   rtems_libio_open_close_args_t *args
0045 )
0046 {
0047   return true;
0048 }
0049 
0050 /*
0051  *  fbcons_close
0052  *
0053  *  This function shuts down the requested port.
0054  */
0055 static void fbcons_close(
0056   struct rtems_termios_tty *tty,
0057   rtems_termios_device_context *base,
0058   rtems_libio_open_close_args_t *args
0059 )
0060 {
0061 }
0062 
0063 /*
0064  *  fbcons_write_polled
0065  *
0066  *  This routine polls out the requested character.
0067  */
0068 void fbcons_write_polled(
0069   rtems_termios_device_context *base,
0070   char c
0071 )
0072 {
0073   rpi_fb_outch( c );
0074 
0075   if ( c == '\n' )
0076     rpi_fb_outch( '\r' );            /* LF = LF + CR */
0077 }
0078 
0079 /*
0080  *  fbcons_write_support_polled
0081  *
0082  *  Console Termios output entry point when using polled output.
0083  *
0084  */
0085 static void fbcons_write_support_polled(
0086   rtems_termios_device_context *base,
0087   const char *buf,
0088   size_t      len
0089 )
0090 {
0091   int nwrite = 0;
0092 
0093   /*
0094    * poll each byte in the string out of the port.
0095    */
0096   while ( nwrite < len ) {
0097     fbcons_write_polled( base, *buf++ );
0098     nwrite++;
0099   }
0100 }
0101 
0102 /*
0103  *  fbcons_inbyte_nonblocking_polled
0104  *
0105  *  Console Termios polling input entry point.
0106  */
0107 static int fbcons_inbyte_nonblocking_polled(
0108   rtems_termios_device_context *base
0109 )
0110 {
0111   // if( rtems_kbpoll() ) {
0112   //   int c = getch();
0113   //   return c;
0114   // }
0115 
0116   return -1;
0117 }
0118 
0119 /*
0120  *  fbcons_set_attributes
0121  *
0122  *  This function sets the UART channel to reflect the requested termios
0123  *  port settings.
0124  */
0125 static bool fbcons_set_attributes(
0126   rtems_termios_device_context *base,
0127   const struct termios *t
0128 )
0129 {
0130   return true;
0131 }
0132 
0133 bool fbcons_probe(
0134   rtems_termios_device_context *context
0135 )
0136 {
0137   // rtems_status_code status;
0138   static bool firstTime = true;
0139   static bool ret = false;
0140 
0141   /*
0142    *  keyboard interrupt should be registered when the keyboard is available
0143    */
0144   if ( firstTime ) {
0145     if ( !rpi_fb_hdmi_is_present() ) {
0146       ret = false;
0147     } else {
0148       ret = true;
0149     }
0150   }
0151 
0152   firstTime = false;
0153 
0154   return ret;
0155 }
0156 
0157 const rtems_termios_device_handler fbcons_fns =
0158 {
0159   .first_open = fbcons_open,
0160   .last_close = fbcons_close,
0161   .poll_read = fbcons_inbyte_nonblocking_polled,
0162   .write = fbcons_write_support_polled,
0163   .set_attributes = fbcons_set_attributes,
0164   .mode = TERMIOS_POLLED
0165 };