From d33f8063e2c4033d767415660ca5ddafd3dd03fc Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Tue, 9 Aug 2016 23:17:48 +0200 Subject: ucoo/hal/frame_buffer: enable tearing effect protection --- ucoo/hal/frame_buffer/dsi.stm32f4.cc | 31 ++++++++++++++++++++++++++++++- ucoo/hal/frame_buffer/dsi.stm32f4.hh | 5 +++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/ucoo/hal/frame_buffer/dsi.stm32f4.cc b/ucoo/hal/frame_buffer/dsi.stm32f4.cc index 31a71f4..8e13982 100644 --- a/ucoo/hal/frame_buffer/dsi.stm32f4.cc +++ b/ucoo/hal/frame_buffer/dsi.stm32f4.cc @@ -57,6 +57,13 @@ enum DsiDataType PACKED_PIXEL_RGB888 = 0x3e, }; +enum DcsCommand +{ + DCS_SET_TEAR_ON = 0x35, +}; + +bool Dsi::refreshing_; + Dsi::Dsi (int width, int heigth, int lanes) : Ltdc (width, heigth, 2, 1, 1, 2, 1, 1), lanes_ (lanes) { @@ -139,6 +146,8 @@ Dsi::enable (const Function &config) 5, 2); // pllr, pllr_div => 416 MHz / 5 / 2 ~= 41.6 MHz Ltdc::enable (); //// Enable DSI Host and DSI wrapper. + reg::DSI->WIER = DSI_WIER_ERIE | DSI_WIER_TEIE; + interrupt_enable (Irq::DSI); reg::DSI->CR = DSI_CR_EN; reg::DSI->WCR = DSI_WCR_DSIEN; //// Configure display. @@ -155,6 +164,7 @@ void Dsi::disable () { // TODO + interrupt_disable (Irq::DSI); reg::DSI->CR = 0; reg::DSI->WCR = 0; Ltdc::disable (); @@ -172,7 +182,10 @@ Dsi::layer_setup (int layer, const Surface &surface, int x, int y) void Dsi::refresh () { - ucoo::reg::DSI->WCR |= DSI_WCR_LTDCEN; + refreshing_ = true; + ucoo::Dsi::write_command ({ DCS_SET_TEAR_ON, 0x00 }); + while (refreshing_) + ucoo::barrier (); } void @@ -215,4 +228,20 @@ Dsi::write_command (std::initializer_list data) } } +template<> +void +interrupt () +{ + if (reg::DSI->WISR & DSI_WISR_TEIF) + { + reg::DSI->WIFCR = DSI_WIFCR_CTEIF; + ucoo::reg::DSI->WCR |= DSI_WCR_LTDCEN; + } + else if (reg::DSI->WISR & DSI_WISR_ERIF) + { + reg::DSI->WIFCR = DSI_WIFCR_CERIF; + Dsi::refreshing_ = false; + } +} + } // namespace ucoo diff --git a/ucoo/hal/frame_buffer/dsi.stm32f4.hh b/ucoo/hal/frame_buffer/dsi.stm32f4.hh index bb92d6d..5f785aa 100644 --- a/ucoo/hal/frame_buffer/dsi.stm32f4.hh +++ b/ucoo/hal/frame_buffer/dsi.stm32f4.hh @@ -24,6 +24,7 @@ // // }}} #include "ucoo/hal/frame_buffer/ltdc.stm32f4.hh" +#include "ucoo/arch/interrupt.arm.hh" #include "ucoo/utils/function.hh" #include @@ -49,6 +50,10 @@ class Dsi : public Ltdc private: /// Number of data lanes. int lanes_; + /// Refresh is being done. + static bool refreshing_; + private: + friend void interrupt (); }; } // namespace ucoo -- cgit v1.2.3