AP_OSD_MAX7456.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * This file is free software: you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License as published by the
  4. * Free Software Foundation, either version 3 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This file is distributed in the hope that it will be useful, but
  8. * WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. * See the GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License along
  13. * with this program. If not, see <http://www.gnu.org/licenses/>.
  14. *
  15. */
  16. #pragma once
  17. #include <AP_OSD/AP_OSD_Backend.h>
  18. #include <AP_Common/Bitmask.h>
  19. class AP_OSD_MAX7456 : public AP_OSD_Backend {
  20. public:
  21. static AP_OSD_Backend *probe(AP_OSD &osd, AP_HAL::OwnPtr<AP_HAL::Device> dev);
  22. //draw given text to framebuffer
  23. void write(uint8_t x, uint8_t y, const char* text) override;
  24. //initilize display port and underlying hardware
  25. bool init() override;
  26. //flush framebuffer to screen
  27. void flush() override;
  28. //clear framebuffer
  29. void clear() override;
  30. private:
  31. //constructor
  32. AP_OSD_MAX7456(AP_OSD &osd, AP_HAL::OwnPtr<AP_HAL::Device> dev);
  33. void buffer_add_cmd(uint8_t reg, uint8_t arg);
  34. bool update_font();
  35. bool check_font_char(uint8_t chr, const uint8_t* font_data);
  36. bool update_font_char(uint8_t chr, const uint8_t* font_data);
  37. void check_reinit();
  38. void reinit();
  39. void transfer_frame();
  40. bool is_dirty(uint8_t x, uint8_t y);
  41. AP_HAL::OwnPtr<AP_HAL::Device> _dev;
  42. uint8_t video_signal_reg;
  43. bool initialized;
  44. uint8_t last_font;
  45. int8_t last_v_offset;
  46. int8_t last_h_offset;
  47. static const uint8_t video_lines_ntsc = 13;
  48. static const uint8_t video_lines_pal = 16;
  49. static const uint8_t video_columns = 30;
  50. static const uint16_t spi_buffer_size = 512;
  51. uint8_t frame[video_lines_pal][video_columns];
  52. //frame already transfered to max
  53. //used to optimize number of characters updated
  54. uint8_t shadow_frame[video_lines_pal][video_columns];
  55. uint8_t buffer[spi_buffer_size];
  56. int buffer_offset;
  57. uint32_t last_signal_check;
  58. uint32_t video_detect_time;
  59. uint16_t video_lines;
  60. };