mirror of
https://github.com/eclipse/upm.git
synced 2025-07-02 01:41:12 +03:00
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:
@ -51,56 +51,56 @@ const uint8_t digitToSegment[] = {
|
||||
};
|
||||
|
||||
TM1637::TM1637 (uint8_t di, uint8_t dcki) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
maa_init();
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa_init();
|
||||
|
||||
// init clock context
|
||||
m_clkPinCtx = maa_gpio_init(dcki);
|
||||
m_clkPinCtx = mraa_gpio_init(dcki);
|
||||
if (m_clkPinCtx == NULL) {
|
||||
fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", dcki);
|
||||
exit(1);
|
||||
}
|
||||
// init data context
|
||||
m_dataPinCtx = maa_gpio_init(di);
|
||||
m_dataPinCtx = mraa_gpio_init(di);
|
||||
if (m_dataPinCtx == NULL) {
|
||||
fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", di);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// set direction (out)
|
||||
error = maa_gpio_dir(m_clkPinCtx, MAA_GPIO_IN);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print(error);
|
||||
error = mraa_gpio_dir(m_clkPinCtx, MRAA_GPIO_IN);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
|
||||
// set direction (out)
|
||||
error = maa_gpio_dir(m_dataPinCtx, MAA_GPIO_IN);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print(error);
|
||||
error = mraa_gpio_dir(m_dataPinCtx, MRAA_GPIO_IN);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
|
||||
error = maa_gpio_write (m_dataPinCtx, LOW);
|
||||
error = maa_gpio_write (m_clkPinCtx, LOW);
|
||||
error = mraa_gpio_write (m_dataPinCtx, LOW);
|
||||
error = mraa_gpio_write (m_clkPinCtx, LOW);
|
||||
}
|
||||
|
||||
TM1637::~TM1637() {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
error = maa_gpio_close (m_dataPinCtx);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print(error);
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
error = mraa_gpio_close (m_dataPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
error = maa_gpio_close (m_clkPinCtx);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print(error);
|
||||
error = mraa_gpio_close (m_clkPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
TM1637::setBrightness (uint8_t level) {
|
||||
m_brightness = level;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
TM1637::setSegments (const uint8_t segments[], uint8_t length, uint8_t pos) {
|
||||
start();
|
||||
writeByte(TM1637_I2C_COMM1);
|
||||
@ -118,7 +118,7 @@ TM1637::setSegments (const uint8_t segments[], uint8_t length, uint8_t pos) {
|
||||
stop();
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
TM1637::write (std::string msg) {
|
||||
char leter = '\0';
|
||||
uint8_t data[] = { 0x0, 0x0, 0x0, 0x0 };
|
||||
@ -132,60 +132,60 @@ TM1637::write (std::string msg) {
|
||||
setSegments(data);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
TM1637::pinMode (maa_gpio_context ctx, gpio_dir_t mode) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
error = maa_gpio_dir(ctx, mode);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print(error);
|
||||
mraa_result_t
|
||||
TM1637::pinMode (mraa_gpio_context ctx, gpio_dir_t mode) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
error = mraa_gpio_dir(ctx, mode);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
TM1637::start() {
|
||||
pinMode (m_dataPinCtx, MAA_GPIO_OUT);
|
||||
pinMode (m_dataPinCtx, MRAA_GPIO_OUT);
|
||||
usleep(PULSE_LENGTH);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
TM1637::stop() {
|
||||
pinMode (m_dataPinCtx, MAA_GPIO_OUT);
|
||||
pinMode (m_dataPinCtx, MRAA_GPIO_OUT);
|
||||
usleep(PULSE_LENGTH);
|
||||
pinMode (m_clkPinCtx, MAA_GPIO_IN);
|
||||
pinMode (m_clkPinCtx, MRAA_GPIO_IN);
|
||||
usleep(PULSE_LENGTH);
|
||||
pinMode (m_dataPinCtx, MAA_GPIO_IN);
|
||||
pinMode (m_dataPinCtx, MRAA_GPIO_IN);
|
||||
usleep(PULSE_LENGTH);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
TM1637::writeByte(uint8_t value) {
|
||||
for (uint8_t idx = 0; idx < 8; idx++) {
|
||||
pinMode(m_clkPinCtx, MAA_GPIO_OUT);
|
||||
pinMode(m_clkPinCtx, MRAA_GPIO_OUT);
|
||||
usleep(PULSE_LENGTH);
|
||||
if (value & 0x01) {
|
||||
pinMode(m_dataPinCtx, MAA_GPIO_IN);
|
||||
pinMode(m_dataPinCtx, MRAA_GPIO_IN);
|
||||
} else {
|
||||
pinMode(m_dataPinCtx, MAA_GPIO_OUT);
|
||||
pinMode(m_dataPinCtx, MRAA_GPIO_OUT);
|
||||
}
|
||||
usleep(PULSE_LENGTH);
|
||||
|
||||
pinMode(m_clkPinCtx, MAA_GPIO_IN);
|
||||
pinMode(m_clkPinCtx, MRAA_GPIO_IN);
|
||||
usleep(PULSE_LENGTH);
|
||||
value = value >> 1;
|
||||
}
|
||||
|
||||
pinMode(m_clkPinCtx, MAA_GPIO_OUT);
|
||||
pinMode(m_dataPinCtx, MAA_GPIO_IN);
|
||||
pinMode(m_clkPinCtx, MRAA_GPIO_OUT);
|
||||
pinMode(m_dataPinCtx, MRAA_GPIO_IN);
|
||||
usleep(PULSE_LENGTH);
|
||||
|
||||
pinMode(m_clkPinCtx, MAA_GPIO_IN);
|
||||
pinMode(m_clkPinCtx, MRAA_GPIO_IN);
|
||||
usleep(PULSE_LENGTH);
|
||||
|
||||
uint8_t ack = maa_gpio_read (m_dataPinCtx);
|
||||
uint8_t ack = mraa_gpio_read (m_dataPinCtx);
|
||||
if (ack == 0) {
|
||||
pinMode(m_dataPinCtx, MAA_GPIO_OUT);
|
||||
pinMode(m_dataPinCtx, MRAA_GPIO_OUT);
|
||||
} usleep(PULSE_LENGTH);
|
||||
|
||||
pinMode(m_clkPinCtx, MAA_GPIO_OUT);
|
||||
pinMode(m_clkPinCtx, MRAA_GPIO_OUT);
|
||||
usleep(50);
|
||||
}
|
||||
|
@ -24,8 +24,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/aio.h>
|
||||
#include <maa/gpio.h>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
|
||||
#define SEG_A 0b00000001
|
||||
#define SEG_B 0b00000010
|
||||
@ -82,7 +82,7 @@ class TM1637 {
|
||||
*
|
||||
* @param level The brightness level of leds
|
||||
*/
|
||||
maa_result_t setBrightness (uint8_t level);
|
||||
mraa_result_t setBrightness (uint8_t level);
|
||||
|
||||
/**
|
||||
* Set the the segment screen data and number of segments
|
||||
@ -92,14 +92,14 @@ class TM1637 {
|
||||
* @param length number of elements in segments array
|
||||
* @param pos data writing offset
|
||||
*/
|
||||
maa_result_t setSegments (const uint8_t segments[], uint8_t length = 4, uint8_t pos = 0);
|
||||
mraa_result_t setSegments (const uint8_t segments[], uint8_t length = 4, uint8_t pos = 0);
|
||||
|
||||
/**
|
||||
* Write message on the screen.
|
||||
*
|
||||
* @param msg The message to be written on the sreen
|
||||
*/
|
||||
maa_result_t write (std::string msg);
|
||||
mraa_result_t write (std::string msg);
|
||||
|
||||
/**
|
||||
* Return name of the component
|
||||
@ -110,13 +110,13 @@ class TM1637 {
|
||||
}
|
||||
|
||||
private:
|
||||
maa_result_t start();
|
||||
maa_result_t stop();
|
||||
maa_result_t writeByte (uint8_t value);
|
||||
maa_result_t pinMode (maa_gpio_context ctx, gpio_dir_t mode);
|
||||
mraa_result_t start();
|
||||
mraa_result_t stop();
|
||||
mraa_result_t writeByte (uint8_t value);
|
||||
mraa_result_t pinMode (mraa_gpio_context ctx, gpio_dir_t mode);
|
||||
|
||||
maa_gpio_context m_clkPinCtx;
|
||||
maa_gpio_context m_dataPinCtx;
|
||||
mraa_gpio_context m_clkPinCtx;
|
||||
mraa_gpio_context m_dataPinCtx;
|
||||
|
||||
std::string m_name;
|
||||
uint8_t m_brightness;
|
||||
|
Reference in New Issue
Block a user