output.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* Copyright (C) 2013 by John Cronin <jncronin@tysos.org>
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. * The above copyright notice and this permission notice shall be included in
  10. * all copies or substantial portions of the Software.
  11. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. * THE SOFTWARE.
  18. */
  19. #include "output.h"
  20. #include "uart.h"
  21. #include "console.h"
  22. #include "log.h"
  23. rpi_boot_output_state ostate;
  24. int (*custom_putc)(int c) = NULL;
  25. rpi_boot_output_state output_get_state()
  26. {
  27. return ostate;
  28. }
  29. void output_restore_state(rpi_boot_output_state state)
  30. {
  31. ostate = state;
  32. }
  33. void output_disable_fb()
  34. {
  35. ostate &= ~RPIBOOT_OUTPUT_FB;
  36. }
  37. void output_enable_fb()
  38. {
  39. #ifdef ENABLE_FRAMEBUFFER
  40. ostate |= RPIBOOT_OUTPUT_FB;
  41. #endif
  42. }
  43. void output_disable_uart()
  44. {
  45. ostate &= ~RPIBOOT_OUTPUT_UART;
  46. }
  47. void output_enable_uart()
  48. {
  49. #ifdef ENABLE_SERIAL
  50. ostate |= RPIBOOT_OUTPUT_UART;
  51. #endif
  52. }
  53. void output_disable_custom()
  54. {
  55. ostate &= ~RPIBOOT_OUTPUT_CUSTOM;
  56. }
  57. void output_enable_custom()
  58. {
  59. ostate |= RPIBOOT_OUTPUT_CUSTOM;
  60. }
  61. void output_disable_log()
  62. {
  63. ostate &= RPIBOOT_OUTPUT_LOG;
  64. }
  65. void output_enable_log()
  66. {
  67. #ifdef ENABLE_CONSOLE_LOGFILE
  68. ostate |= RPIBOOT_OUTPUT_LOG;
  69. #endif
  70. }
  71. void output_init()
  72. {
  73. ostate = 0;
  74. }
  75. int split_putc(int c)
  76. {
  77. int ret = 0;
  78. #ifdef ENABLE_SERIAL
  79. if(ostate & RPIBOOT_OUTPUT_UART)
  80. ret = uart_putc(c);
  81. #endif
  82. #ifdef ENABLE_FRAMEBUFFER
  83. if(ostate & RPIBOOT_OUTPUT_FB)
  84. ret = console_putc(c);
  85. #endif
  86. #ifdef ENABLE_CONSOLE_LOGFILE
  87. if(ostate & RPIBOOT_OUTPUT_LOG)
  88. ret = log_putc(c);
  89. #endif
  90. if((ostate & RPIBOOT_OUTPUT_CUSTOM) && custom_putc)
  91. custom_putc(c);
  92. return ret;
  93. }
  94. int register_custom_output_function(int (*putc_function)(int c))
  95. {
  96. custom_putc = putc_function;
  97. return 0;
  98. }