st7735: throw exception(s) on fatal errors

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Jon Trulson 2015-09-11 11:43:18 -06:00 committed by Mihai Tudor Panu
parent 6b19482ceb
commit ca04996524

View File

@ -23,6 +23,8 @@
*/
#include <iostream>
#include <string>
#include <stdexcept>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
@ -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);