From ca04996524a3f4cbf52bed862bdbca2780674e92 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Fri, 11 Sep 2015 11:43:18 -0600 Subject: [PATCH] st7735: throw exception(s) on fatal errors Signed-off-by: Jon Trulson Signed-off-by: Mihai Tudor Panu --- src/st7735/st7735.cxx | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/st7735/st7735.cxx b/src/st7735/st7735.cxx index 73ca4a29..b6bd2416 100644 --- a/src/st7735/st7735.cxx +++ b/src/st7735/st7735.cxx @@ -23,6 +23,8 @@ */ #include +#include +#include #include #include #include @@ -54,6 +56,43 @@ ST7735::initModule () { m_height = 160; m_width = 128; + m_csLCDPinCtx = mraa_gpio_init (m_csLCD); + if (m_csLCDPinCtx == NULL) { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_init(csLCD) failed, invalid pin?"); + return; + } + + m_cSDPinCtx = mraa_gpio_init (m_cSD); + if (m_cSDPinCtx == NULL) { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_init(cSD) failed, invalid pin?"); + return; + } + + m_rSTPinCtx = mraa_gpio_init (m_rST); + if (m_rSTPinCtx == NULL) { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_init(rST) failed, invalid pin?"); + return; + } + + m_rSPinCtx = mraa_gpio_init (m_rS); + if (m_rSPinCtx == NULL) { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_init(rS) failed, invalid pin?"); + return; + } + + if ( !(m_spi = mraa_spi_init (0)) ) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_spi_init() failed"); + return; + } + + mraa_spi_frequency(m_spi, 15 * 1000000); + error = m_csLCDPinCtx.dir(mraa::DIR_OUT); if (error != mraa::SUCCESS) { mraa::printError (error);