mraa: change all existing code to use libmraa.

* Made CMake depend on 0.4 libmraa

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
This commit is contained in:
Thomas Ingleby
2014-06-25 10:05:27 +01:00
parent 8d25ecacdd
commit 36be22cb90
53 changed files with 640 additions and 640 deletions

View File

@ -40,17 +40,17 @@ GFX::GFX (int width, int height, uint8_t * screenBuffer, const unsigned char * f
GFX::~GFX () {
}
maa_result_t
mraa_result_t
GFX::setPixel (int x, int y, uint16_t color) {
if((x < 0) ||(x >= m_width) || (y < 0) || (y >= m_height)) {
return MAA_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 MAA_SUCCESS;
return MRAA_SUCCESS;
}
void

View File

@ -27,7 +27,7 @@
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <maa.h>
#include <mraa.h>
#define swap(a, b) { int16_t t = a; a = b; b = t; }
@ -106,7 +106,7 @@ class GFX {
* @param y axis on vertical scale
* @param color pixel's color
*/
maa_result_t setPixel (int x, int y, uint16_t color);
mraa_result_t setPixel (int x, int y, uint16_t color);
/**
* Fill screen with selected color

View File

@ -33,7 +33,7 @@
using namespace upm;
ST7735::ST7735 (uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst) : GFX (160, 128, m_map, font) {
maa_init();
mraa_init();
m_csLCD = csLCD;
m_cSD = cSD;
@ -45,84 +45,84 @@ ST7735::ST7735 (uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst) : GFX (160,
}
ST7735::~ST7735 () {
maa_result_t error = MAA_SUCCESS;
error = maa_spi_stop(m_spi);
if (error != MAA_SUCCESS) {
maa_result_print(error);
mraa_result_t error = MRAA_SUCCESS;
error = mraa_spi_stop(m_spi);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
error = maa_gpio_close (m_csLCDPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
error = mraa_gpio_close (m_csLCDPinCtx);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
error = maa_gpio_close (m_cSDPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
error = mraa_gpio_close (m_cSDPinCtx);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
error = maa_gpio_close (m_rSTPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
error = mraa_gpio_close (m_rSTPinCtx);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
error = maa_gpio_close (m_rSPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
error = mraa_gpio_close (m_rSPinCtx);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
}
void
ST7735::initModule () {
maa_result_t error = MAA_SUCCESS;
mraa_result_t error = MRAA_SUCCESS;
m_height = 160;
m_width = 128;
m_csLCDPinCtx = maa_gpio_init (m_csLCD);
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);
}
m_cSDPinCtx = maa_gpio_init (m_cSD);
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);
}
m_rSTPinCtx = maa_gpio_init (m_rST);
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);
}
m_rSPinCtx = maa_gpio_init (m_rS);
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 = maa_gpio_dir (m_csLCDPinCtx, MAA_GPIO_OUT);
if (error != MAA_SUCCESS) {
maa_result_print (error);
error = mraa_gpio_dir (m_csLCDPinCtx, MRAA_GPIO_OUT);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
}
error = maa_gpio_dir (m_cSDPinCtx, MAA_GPIO_OUT);
if (error != MAA_SUCCESS) {
maa_result_print (error);
error = mraa_gpio_dir (m_cSDPinCtx, MRAA_GPIO_OUT);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
}
error = maa_gpio_dir (m_rSTPinCtx, MAA_GPIO_OUT);
if (error != MAA_SUCCESS) {
maa_result_print (error);
error = mraa_gpio_dir (m_rSTPinCtx, MRAA_GPIO_OUT);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
}
error = maa_gpio_dir (m_rSPinCtx, MAA_GPIO_OUT);
if (error != MAA_SUCCESS) {
maa_result_print (error);
error = mraa_gpio_dir (m_rSPinCtx, MRAA_GPIO_OUT);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
}
m_spi = maa_spi_init (0);
error = maa_spi_frequency(m_spi, 15 * 1000000);
if (error != MAA_SUCCESS) {
maa_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);
}
lcdCSOn ();
@ -131,13 +131,13 @@ ST7735::initModule () {
void
ST7735::write (uint8_t value) {
rsLOW ();
maa_spi_write (m_spi, value);
mraa_spi_write (m_spi, value);
}
void
ST7735::data (uint8_t value) {
rsHIGH ();
maa_spi_write (m_spi, value);
mraa_spi_write (m_spi, value);
}
void
@ -177,7 +177,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
maa_spi_write_buf(m_spi, m_spiBuffer, 4);
mraa_spi_write_buf(m_spi, m_spiBuffer, 4);
write (ST7735_RASET); // Row addr set
@ -186,14 +186,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
maa_spi_write_buf(m_spi, m_spiBuffer, 4);
mraa_spi_write_buf(m_spi, m_spiBuffer, 4);
write (ST7735_RAMWR); // write to RAM
}
void
ST7735::drawPixel(int16_t x, int16_t y, uint16_t color) {
if (MAA_SUCCESS != setPixel (x, y, color)) {
if (MRAA_SUCCESS != setPixel (x, y, color)) {
return;
}
@ -206,7 +206,7 @@ ST7735::refresh () {
int fragmentSize = m_height * m_width * 2 / 20;
for (int fragment = 0; fragment < 20; fragment++) {
maa_spi_write_buf(m_spi, &m_map[fragment * fragmentSize], fragmentSize);
mraa_spi_write_buf(m_spi, &m_map[fragment * fragmentSize], fragmentSize);
}
}
@ -216,11 +216,11 @@ ST7735::configModule() {
lcdCSOff ();
lcdCSOn ();
maa_gpio_write (m_rSTPinCtx, HIGH);
mraa_gpio_write (m_rSTPinCtx, HIGH);
usleep (500000);
maa_gpio_write (m_rSTPinCtx, LOW);
mraa_gpio_write (m_rSTPinCtx, LOW);
usleep (500000);
maa_gpio_write (m_rSTPinCtx, HIGH);
mraa_gpio_write (m_rSTPinCtx, HIGH);
usleep (500000);
executeCMDList (Rcmd1);
@ -236,83 +236,83 @@ ST7735::configModule() {
refresh ();
}
maa_result_t
mraa_result_t
ST7735::lcdCSOn () {
maa_result_t error = MAA_SUCCESS;
mraa_result_t error = MRAA_SUCCESS;
error = maa_gpio_write (m_csLCDPinCtx, LOW);
if (error != MAA_SUCCESS) {
maa_result_print (error);
error = mraa_gpio_write (m_csLCDPinCtx, LOW);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
}
error = maa_gpio_write (m_cSDPinCtx, HIGH);
if (error != MAA_SUCCESS) {
maa_result_print (error);
error = mraa_gpio_write (m_cSDPinCtx, HIGH);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
}
return error;
}
maa_result_t
mraa_result_t
ST7735::lcdCSOff () {
maa_result_t error = MAA_SUCCESS;
mraa_result_t error = MRAA_SUCCESS;
error = maa_gpio_write (m_csLCDPinCtx, HIGH);
if (error != MAA_SUCCESS) {
maa_result_print (error);
error = mraa_gpio_write (m_csLCDPinCtx, HIGH);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
}
return error;
}
maa_result_t
mraa_result_t
ST7735::sdCSOn () {
maa_result_t error = MAA_SUCCESS;
mraa_result_t error = MRAA_SUCCESS;
error = maa_gpio_write (m_cSDPinCtx, LOW);
if (error != MAA_SUCCESS) {
maa_result_print (error);
error = mraa_gpio_write (m_cSDPinCtx, LOW);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
}
error = maa_gpio_write (m_csLCDPinCtx, HIGH);
if (error != MAA_SUCCESS) {
maa_result_print (error);
error = mraa_gpio_write (m_csLCDPinCtx, HIGH);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
}
return error;
}
maa_result_t
mraa_result_t
ST7735::sdCSOff () {
maa_result_t error = MAA_SUCCESS;
mraa_result_t error = MRAA_SUCCESS;
error = maa_gpio_write (m_cSDPinCtx, HIGH);
if (error != MAA_SUCCESS) {
maa_result_print (error);
error = mraa_gpio_write (m_cSDPinCtx, HIGH);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
}
return error;
}
maa_result_t
mraa_result_t
ST7735::rsHIGH () {
maa_result_t error = MAA_SUCCESS;
mraa_result_t error = MRAA_SUCCESS;
error = maa_gpio_write (m_rSPinCtx, HIGH);
if (error != MAA_SUCCESS) {
maa_result_print (error);
error = mraa_gpio_write (m_rSPinCtx, HIGH);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
}
return error;
}
maa_result_t
mraa_result_t
ST7735::rsLOW () {
maa_result_t error = MAA_SUCCESS;
mraa_result_t error = MRAA_SUCCESS;
error = maa_gpio_write (m_rSPinCtx, LOW);
if (error != MAA_SUCCESS) {
maa_result_print (error);
error = mraa_gpio_write (m_rSPinCtx, LOW);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
}
return error;

View File

@ -27,9 +27,9 @@
#pragma once
#include <string>
#include <maa/aio.h>
#include <maa/gpio.h>
#include <maa/spi.h>
#include <mraa/aio.h>
#include <mraa/gpio.h>
#include <mraa/spi.h>
#include <gfx.h>
#define INITR_GREENTAB 0x0
@ -584,45 +584,45 @@ class ST7735 : public GFX {
/**
* LCD chip select LOW.
*/
maa_result_t lcdCSOn ();
mraa_result_t lcdCSOn ();
/**
* LCD chip select HIGH.
*/
maa_result_t lcdCSOff ();
mraa_result_t lcdCSOff ();
/**
* CD card chip select LOW.
*/
maa_result_t sdCSOn ();
mraa_result_t sdCSOn ();
/**
* CD card select HIGH.
*/
maa_result_t sdCSOff ();
mraa_result_t sdCSOff ();
/**
* Data select HIGH.
*/
maa_result_t rsHIGH ();
mraa_result_t rsHIGH ();
/**
* Data select LOW.
*/
maa_result_t rsLOW ();
mraa_result_t rsLOW ();
uint8_t m_map[160 * 128 * 2]; /**< Screens buffer */
private:
maa_spi_context m_spi;
mraa_spi_context m_spi;
uint8_t m_csLCD;
uint8_t m_cSD;
uint8_t m_rST;
uint8_t m_rS;
maa_gpio_context m_csLCDPinCtx;
maa_gpio_context m_cSDPinCtx;
maa_gpio_context m_rSTPinCtx;
maa_gpio_context m_rSPinCtx;
mraa_gpio_context m_csLCDPinCtx;
mraa_gpio_context m_cSDPinCtx;
mraa_gpio_context m_rSTPinCtx;
mraa_gpio_context m_rSPinCtx;
uint8_t m_spiBuffer[32];