Display.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. *
  3. * Copyright (c) 2020 Project CHIP Authors
  4. * Copyright (c) 2018 Nest Labs, Inc.
  5. * All rights reserved.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. */
  19. /**
  20. * @file Display.h
  21. *
  22. * This describes helper APIs for the M5Stack's Display
  23. *
  24. */
  25. #pragma once
  26. #include "esp_system.h"
  27. #if CONFIG_HAVE_DISPLAY
  28. #if CONFIG_DEVICE_TYPE_M5STACK
  29. #define INVERT_DISPLAY INVERT_ON
  30. #elif CONFIG_DEVICE_TYPE_ESP32_WROVER_KIT
  31. #define INVERT_DISPLAY INVERT_OFF
  32. #endif
  33. extern "C" {
  34. #include "tft.h"
  35. #include "tftspi.h"
  36. } // extern "C"
  37. // To reduce wear (and heat) on the screen, the display will always go off after a few seconds
  38. #define DISPLAY_TIMEOUT_MS 30000
  39. extern uint16_t DisplayHeight;
  40. extern uint16_t DisplayWidth;
  41. /**
  42. * @brief
  43. * Initialize the M5Stack's display driver and set the default bright control and timeout
  44. *
  45. * @return esp_err_t 0 if the display driver was initialized correctly
  46. */
  47. extern esp_err_t InitDisplay();
  48. /**
  49. * @brief
  50. * Clear the display by setting the whole screen to black
  51. */
  52. extern void ClearDisplay();
  53. /**
  54. * @brief
  55. * Clear a portion of the display by drawing a black rectangle based on the given arguments
  56. *
  57. * Calling this with default arguments is the same as calling `ClearDisplay()`.
  58. *
  59. * @param x_percent_start The starting x coordinate specified as a percentage of the screen's width.
  60. * @param y_percent_start The starting y coordinate specified as a percentage of the screen's height.
  61. * @param x_percent_end The end x coordinate specified as a percentage of the screen's width.
  62. * @param y_percent_end The end y coordinate specified as a percentage of the screen's height.
  63. */
  64. extern void ClearRect(uint16_t x_percent_start = 0, uint16_t y_percent_start = 0, uint16_t x_percent_end = 100,
  65. uint16_t y_percent_end = 100);
  66. /**
  67. * @brief
  68. * Display a status message at a given vertical position
  69. *
  70. * The status message will be drawn from the left edge of the screen
  71. *
  72. * @param msg The message to display
  73. * @param vpos The vertical position(0-100 percent) of the message. Where 0 is the top of the screen
  74. */
  75. extern void DisplayStatusMessage(char * msg, uint16_t vpos);
  76. /**
  77. * @brief
  78. * Reset the display timeout and set the brightness back up to default values
  79. *
  80. * @return true If the display was woken
  81. */
  82. extern bool WakeDisplay();
  83. #endif // #if CONFIG_HAVE_DISPLAY