java: changed some C types to C++ types

Signed-off-by: Andrei Vasiliu <andrei.vasiliu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>

Conflicts:
	src/mma7455/mma7455.cxx
	src/mma7455/mma7455.h
	src/sm130/sm130.cxx
	src/sm130/sm130.h
This commit is contained in:
Andrei Vasiliu
2015-09-02 14:56:13 +03:00
committed by Mihai Tudor Panu
parent b8835958e2
commit ab730038fd
46 changed files with 731 additions and 996 deletions

View File

@ -40,17 +40,17 @@ GFX::GFX (int width, int height, uint8_t * screenBuffer, const unsigned char * f
GFX::~GFX () {
}
mraa_result_t
mraa::Result
GFX::setPixel (int x, int y, uint16_t color) {
if((x < 0) ||(x >= m_width) || (y < 0) || (y >= m_height)) {
return MRAA_ERROR_UNSPECIFIED;
return mraa::ERROR_UNSPECIFIED;
}
int index = ((y * m_width) + x) * sizeof(uint16_t);
m_map[index] = (uint8_t) (color >> 8);
m_map[++index] = (uint8_t)(color);
return MRAA_SUCCESS;
return mraa::SUCCESS;
}
void

View File

@ -27,7 +27,15 @@
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <mraa.h>
#ifdef SWIGJAVA
#undef SWIGJAVA
#include <mraa.hpp>
#define SWIGJAVA
#else
#include <mraa.hpp>
#endif
#define swap(a, b) { int16_t t = a; a = b; b = t; }
@ -106,7 +114,7 @@ class GFX {
* @param y Axis on the vertical scale
* @param color Pixel color
*/
mraa_result_t setPixel (int x, int y, uint16_t color);
mraa::Result setPixel (int x, int y, uint16_t color);
/**
* Fills the screen with a selected color

View File

@ -32,8 +32,11 @@
using namespace upm;
ST7735::ST7735 (uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst) : GFX (160, 128, m_map, font) {
mraa_init();
ST7735::ST7735 (uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst)
: GFX (160, 128, m_map, font), m_csLCDPinCtx(m_csLCD), m_cSDPinCtx(m_cSD),
m_rSTPinCtx(m_rST), m_rSPinCtx(m_rS), m_spi(0) {
mraa::init();
m_csLCD = csLCD;
m_cSD = cSD;
@ -44,85 +47,36 @@ ST7735::ST7735 (uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst) : GFX (160,
configModule ();
}
ST7735::~ST7735 () {
mraa_result_t error = MRAA_SUCCESS;
error = mraa_spi_stop(m_spi);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
error = mraa_gpio_close (m_csLCDPinCtx);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
error = mraa_gpio_close (m_cSDPinCtx);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
error = mraa_gpio_close (m_rSTPinCtx);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
error = mraa_gpio_close (m_rSPinCtx);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
}
void
ST7735::initModule () {
mraa_result_t error = MRAA_SUCCESS;
mraa::Result error = mraa::SUCCESS;
m_height = 160;
m_width = 128;
m_csLCDPinCtx = mraa_gpio_init (m_csLCD);
if (m_csLCDPinCtx == NULL) {
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_csLCD);
exit (1);
error = m_csLCDPinCtx.dir(mraa::DIR_OUT);
if (error != mraa::SUCCESS) {
mraa::printError (error);
}
m_cSDPinCtx = mraa_gpio_init (m_cSD);
if (m_cSDPinCtx == NULL) {
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_cSD);
exit (1);
error = m_cSDPinCtx.dir(mraa::DIR_OUT);
if (error != mraa::SUCCESS) {
mraa::printError (error);
}
m_rSTPinCtx = mraa_gpio_init (m_rST);
if (m_rSTPinCtx == NULL) {
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_rST);
exit (1);
error = m_rSTPinCtx.dir(mraa::DIR_OUT);
if (error != mraa::SUCCESS) {
mraa::printError (error);
}
m_rSPinCtx = mraa_gpio_init (m_rS);
if (m_rSPinCtx == NULL) {
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_rS);
exit (1);
error = m_rSPinCtx.dir(mraa::DIR_OUT);
if (error != mraa::SUCCESS) {
mraa::printError (error);
}
error = mraa_gpio_dir (m_csLCDPinCtx, MRAA_GPIO_OUT);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
}
error = mraa_gpio_dir (m_cSDPinCtx, MRAA_GPIO_OUT);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
}
error = mraa_gpio_dir (m_rSTPinCtx, MRAA_GPIO_OUT);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
}
error = mraa_gpio_dir (m_rSPinCtx, MRAA_GPIO_OUT);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
}
m_spi = mraa_spi_init (0);
error = mraa_spi_frequency(m_spi, 15 * 1000000);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
error = m_spi.frequency(15 * 1000000);
if (error != mraa::SUCCESS) {
mraa::printError (error);
}
lcdCSOn ();
@ -131,13 +85,13 @@ ST7735::initModule () {
void
ST7735::write (uint8_t value) {
rsLOW ();
mraa_spi_write (m_spi, value);
m_spi.writeByte(value);
}
void
ST7735::data (uint8_t value) {
rsHIGH ();
mraa_spi_write (m_spi, value);
m_spi.writeByte(value);
}
void
@ -177,7 +131,7 @@ ST7735::setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) {
m_spiBuffer[1] = x0 + colstart; // XSTART
m_spiBuffer[2] = 0x00;
m_spiBuffer[3] = x1 + colstart; // XEND
mraa_spi_write_buf(m_spi, m_spiBuffer, 4);
m_spi.write(m_spiBuffer, 4);
write (ST7735_RASET); // Row addr set
@ -186,14 +140,14 @@ ST7735::setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) {
m_spiBuffer[1] = y0 + rowstart; // YSTART
m_spiBuffer[2] = 0x00;
m_spiBuffer[3] = y1 + rowstart; // YEND
mraa_spi_write_buf(m_spi, m_spiBuffer, 4);
m_spi.write(m_spiBuffer, 4);
write (ST7735_RAMWR); // write to RAM
}
void
ST7735::drawPixel(int16_t x, int16_t y, uint16_t color) {
if (MRAA_SUCCESS != setPixel (x, y, color)) {
if (mraa::SUCCESS != setPixel (x, y, color)) {
return;
}
@ -206,7 +160,7 @@ ST7735::refresh () {
int fragmentSize = m_height * m_width * 2 / 20;
for (int fragment = 0; fragment < 20; fragment++) {
mraa_spi_write_buf(m_spi, &m_map[fragment * fragmentSize], fragmentSize);
m_spi.write(&m_map[fragment * fragmentSize], fragmentSize);
}
}
@ -216,11 +170,11 @@ ST7735::configModule() {
lcdCSOff ();
lcdCSOn ();
mraa_gpio_write (m_rSTPinCtx, HIGH);
m_rSTPinCtx.write(HIGH);
usleep (500000);
mraa_gpio_write (m_rSTPinCtx, LOW);
m_rSTPinCtx.write(LOW);
usleep (500000);
mraa_gpio_write (m_rSTPinCtx, HIGH);
m_rSTPinCtx.write(HIGH);
usleep (500000);
executeCMDList (Rcmd1);
@ -236,83 +190,83 @@ ST7735::configModule() {
refresh ();
}
mraa_result_t
mraa::Result
ST7735::lcdCSOn () {
mraa_result_t error = MRAA_SUCCESS;
mraa::Result error = mraa::SUCCESS;
error = mraa_gpio_write (m_csLCDPinCtx, LOW);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
error = m_csLCDPinCtx.write(LOW);
if (error != mraa::SUCCESS) {
mraa::printError (error);
}
error = mraa_gpio_write (m_cSDPinCtx, HIGH);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
error = m_cSDPinCtx.write(HIGH);
if (error != mraa::SUCCESS) {
mraa::printError (error);
}
return error;
}
mraa_result_t
mraa::Result
ST7735::lcdCSOff () {
mraa_result_t error = MRAA_SUCCESS;
mraa::Result error = mraa::SUCCESS;
error = mraa_gpio_write (m_csLCDPinCtx, HIGH);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
error = m_csLCDPinCtx.write(HIGH);
if (error != mraa::SUCCESS) {
mraa::printError (error);
}
return error;
}
mraa_result_t
mraa::Result
ST7735::sdCSOn () {
mraa_result_t error = MRAA_SUCCESS;
mraa::Result error = mraa::SUCCESS;
error = mraa_gpio_write (m_cSDPinCtx, LOW);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
error = m_cSDPinCtx.write(LOW);
if (error != mraa::SUCCESS) {
mraa::printError (error);
}
error = mraa_gpio_write (m_csLCDPinCtx, HIGH);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
error = m_csLCDPinCtx.write(HIGH);
if (error != mraa::SUCCESS) {
mraa::printError (error);
}
return error;
}
mraa_result_t
mraa::Result
ST7735::sdCSOff () {
mraa_result_t error = MRAA_SUCCESS;
mraa::Result error = mraa::SUCCESS;
error = mraa_gpio_write (m_cSDPinCtx, HIGH);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
error = m_cSDPinCtx.write(HIGH);
if (error != mraa::SUCCESS) {
mraa::printError (error);
}
return error;
}
mraa_result_t
mraa::Result
ST7735::rsHIGH () {
mraa_result_t error = MRAA_SUCCESS;
mraa::Result error = mraa::SUCCESS;
error = mraa_gpio_write (m_rSPinCtx, HIGH);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
error = m_rSPinCtx.write(HIGH);
if (error != mraa::SUCCESS) {
mraa::printError (error);
}
return error;
}
mraa_result_t
mraa::Result
ST7735::rsLOW () {
mraa_result_t error = MRAA_SUCCESS;
mraa::Result error = mraa::SUCCESS;
error = mraa_gpio_write (m_rSPinCtx, LOW);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
error = m_rSPinCtx.write(LOW);
if (error != mraa::SUCCESS) {
mraa::printError (error);
}
return error;

View File

@ -27,9 +27,19 @@
#pragma once
#include <string>
#include <mraa/aio.h>
#include <mraa/gpio.h>
#include <mraa/spi.h>
#include <mraa/aio.hpp>
#include <mraa/common.hpp>
#ifdef SWIGJAVA
#undef SWIGJAVA
#include <mraa/gpio.hpp>
#define SWIGJAVA
#else
#include <mraa/gpio.hpp>
#endif
#include <mraa/spi.hpp>
#include <gfx.h>
#define INITR_GREENTAB 0x0
@ -526,11 +536,6 @@ class ST7735 : public GFX {
*/
ST7735 (uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst);
/**
* ST7735 object destructor
*/
~ST7735 ();
/**
* Returns the name of the component
*/
@ -598,45 +603,45 @@ class ST7735 : public GFX {
/**
* LCD chip select is LOW
*/
mraa_result_t lcdCSOn ();
mraa::Result lcdCSOn ();
/**
* LCD chip select is HIGH
*/
mraa_result_t lcdCSOff ();
mraa::Result lcdCSOff ();
/**
* CD card chip select is LOW
*/
mraa_result_t sdCSOn ();
mraa::Result sdCSOn ();
/**
* CD card select is HIGH
*/
mraa_result_t sdCSOff ();
mraa::Result sdCSOff ();
/**
* Data select is HIGH
*/
mraa_result_t rsHIGH ();
mraa::Result rsHIGH ();
/**
* Data select is LOW
*/
mraa_result_t rsLOW ();
mraa::Result rsLOW ();
uint8_t m_map[160 * 128 * 2]; /**< Screens buffer */
private:
mraa_spi_context m_spi;
mraa::Spi m_spi;
uint8_t m_csLCD;
uint8_t m_cSD;
uint8_t m_rST;
uint8_t m_rS;
mraa_gpio_context m_csLCDPinCtx;
mraa_gpio_context m_cSDPinCtx;
mraa_gpio_context m_rSTPinCtx;
mraa_gpio_context m_rSPinCtx;
mraa::Gpio m_csLCDPinCtx;
mraa::Gpio m_cSDPinCtx;
mraa::Gpio m_rSTPinCtx;
mraa::Gpio m_rSPinCtx;
uint8_t m_spiBuffer[32];