mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +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:
parent
8d25ecacdd
commit
36be22cb90
@ -8,9 +8,9 @@ endif ()
|
||||
|
||||
find_package (Threads REQUIRED)
|
||||
find_package (PkgConfig REQUIRED)
|
||||
# force the libmaa version to be the required version
|
||||
pkg_check_modules (MAA REQUIRED maa>=0.3.1)
|
||||
message (INFO " found libmaa version: ${MAA_VERSION}")
|
||||
# force the libmraa version to be the required version
|
||||
pkg_check_modules (MRAA REQUIRED mraa>=0.4.0)
|
||||
message (INFO " found libmraa version: ${MRAA_VERSION}")
|
||||
|
||||
# Appends the cmake/modules path to MAKE_MODULE_PATH variable.
|
||||
set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
|
||||
@ -19,7 +19,7 @@ set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_
|
||||
include (GetGitRevisionDescription)
|
||||
git_describe (VERSION "--tags")
|
||||
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND")
|
||||
message (WARNING " - Install git to compile a production libmaa!")
|
||||
message (WARNING " - Install git to compile a production libmraa!")
|
||||
set (VERSION "v0.1.4-dirty")
|
||||
endif ()
|
||||
|
||||
@ -81,7 +81,7 @@ if (IPK)
|
||||
set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
|
||||
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DETECTED_ARCH})
|
||||
set(CPACK_SYSTEM_NAME ${DETECTED_ARCH})
|
||||
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libmaa0 (>= ${MAA_VERSION})")
|
||||
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libmraa0 (>= ${MRAA_VERSION})")
|
||||
set(CPACK_DEBIAN_PACKAGE_PROVIDES "upm-dev, upm-dbg, upm-doc")
|
||||
set(CPACK_DEBIAN_PACKAGE_REPLACES ${CPACK_DEBIAN_PACKAGE_PROVIDES})
|
||||
set(CPACK_DEBIAN_PACKAGE_CONFLICTS ${CPACK_DEBIAN_PACKAGE_PROVIDES})
|
||||
|
@ -44,7 +44,7 @@ PROJECT_NUMBER = @upm_VERSION_STRING@
|
||||
# for a project that appears at the top of each page and should give viewer a
|
||||
# quick idea about the purpose of the project. Keep the description short.
|
||||
|
||||
PROJECT_BRIEF = "Sensor/Actuator repository for libmaa (v@MAA_VERSION@)"
|
||||
PROJECT_BRIEF = "Sensor/Actuator repository for libmraa (v@MRAA_VERSION@)"
|
||||
|
||||
# With the PROJECT_LOGO tag one can specify an logo or icon that is included in
|
||||
# the documentation. The maximum height of the logo should not exceed 55 pixels
|
||||
|
@ -1,8 +1,8 @@
|
||||
UPM - Sensor/Actuator repository for Maa
|
||||
UPM - Sensor/Actuator repository for Mraa
|
||||
==============
|
||||
|
||||
UPM is a high level repository for sensors that use maa. Each sensor links to
|
||||
libmaa and are not meant to be interlinked although some groups of sensors may
|
||||
UPM is a high level repository for sensors that use mraa. Each sensor links to
|
||||
libmraa and are not meant to be interlinked although some groups of sensors may
|
||||
be. Each sensor contains a header which allows to interface with it. Typically
|
||||
a sensor is represented as a class and instanciated.
|
||||
|
||||
|
@ -11,6 +11,6 @@ Here are the rules of contribution:
|
||||
avoid GPL. (LGPL is fine). If your license is not MIT please include a
|
||||
LICENSE file in src/<mymodule>/
|
||||
- Please test your module builds before contributing and make sure it works on
|
||||
the latest version of maa. If you tested on a specific board/platform please
|
||||
the latest version of mraa. If you tested on a specific board/platform please
|
||||
tell us what this was in your PR.
|
||||
|
||||
|
@ -9,7 +9,7 @@ people made arduino code already so we'll use that as a
|
||||
|
||||
### Basics
|
||||
|
||||
This is a spi module so we will use the maa spi functions to build our module.
|
||||
This is a spi module so we will use the mraa spi functions to build our module.
|
||||
First thing to do is to create a tree structure like this in upm/src/max31855:
|
||||
|
||||
* max31855.cxx
|
||||
|
@ -1,7 +1,7 @@
|
||||
Porting a module from Arduino {#porting}
|
||||
=============================
|
||||
|
||||
Porting arduino libraries to libmaa as UPM libraries is usually fairly easy.
|
||||
Porting arduino libraries to libmraa as UPM libraries is usually fairly easy.
|
||||
The issues typically come from misunderstanding of how a non real time OS deals
|
||||
with interupts and timers. It also highly depends on the sensor. A concrete
|
||||
example is explained in detail on @ref max31855
|
||||
@ -31,22 +31,22 @@ upm_module_init()
|
||||
|
||||
The easiest way to do this is to have a look at a similar sensor to yours.
|
||||
Typically create a class for your sensor with a constructor that defines the
|
||||
pins it is on. This constructor will create the maa_*_context structs that are
|
||||
pins it is on. This constructor will create the mraa_*_context structs that are
|
||||
required to talk to the board's IO. An I2c sensor will create a
|
||||
maa_i2c_context, keep it as a private member and require a bus number and slave
|
||||
mraa_i2c_context, keep it as a private member and require a bus number and slave
|
||||
address in it's constructor.
|
||||
|
||||
Typically in sensors a simple object->read() function is prefered, depending on
|
||||
your sensor/actuaotr this may or may not be easy or not even make sense. Most
|
||||
UPM apis have a simple set of functions.
|
||||
|
||||
### Mapping arduino API to libmaa
|
||||
### Mapping arduino API to libmraa
|
||||
|
||||
Your constructor is similar to the setup() function in arduino, you should
|
||||
initialise your IO the way you want it. This means initialising contexts
|
||||
(private members) and setting the correct modes for them.
|
||||
|
||||
See the maa API documentation for exact API.
|
||||
See the mraa API documentation for exact API.
|
||||
|
||||
### Building
|
||||
|
||||
|
@ -20,7 +20,7 @@ macro(upm_SWIG_PYTHON)
|
||||
set (CMAKE_C_FLAGS -DSWIGPYTHON=${SWIG_FOUND})
|
||||
set_source_files_properties (pyupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
||||
swig_add_module (pyupm_${libname} python pyupm_${libname}.i ${module_src})
|
||||
swig_link_libraries (pyupm_${libname} ${PYTHON_LIBRARIES} ${MAA_LIBRARIES})
|
||||
swig_link_libraries (pyupm_${libname} ${PYTHON_LIBRARIES} ${MRAA_LIBRARIES})
|
||||
target_include_directories ( ${SWIG_MODULE_pyupm_${libname}_REAL_NAME}
|
||||
PUBLIC
|
||||
"${PYTHON_INCLUDE_PATH}"
|
||||
@ -39,7 +39,7 @@ macro(upm_SWIG_NODE)
|
||||
set_source_files_properties (jsupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
||||
set_source_files_properties (jsupm_${libname}.i PROPERTIES SWIG_FLAGS "-node")
|
||||
swig_add_module (jsupm_${libname} javascript jsupm_${libname}.i ${module_src})
|
||||
swig_link_libraries (jsupm_${libname} ${MAA_LIBRARIES} ${NODE_LIBRARIES})
|
||||
swig_link_libraries (jsupm_${libname} ${MRAA_LIBRARIES} ${NODE_LIBRARIES})
|
||||
target_include_directories ( ${SWIG_MODULE_jsupm_${libname}_REAL_NAME}
|
||||
PUBLIC
|
||||
"${NODE_INCLUDE_DIRS}"
|
||||
@ -95,8 +95,8 @@ endif()
|
||||
|
||||
macro(upm_module_init)
|
||||
add_library (${libname} SHARED ${module_src})
|
||||
include_directories (${MAA_INCLUDE_DIR} .)
|
||||
target_link_libraries (${libname} ${MAA_LIBRARIES})
|
||||
include_directories (${MRAA_INCLUDE_DIR} .)
|
||||
target_link_libraries (${libname} ${MRAA_LIBRARIES})
|
||||
set_target_properties(
|
||||
${libname}
|
||||
PROPERTIES PREFIX "libupm-"
|
||||
|
@ -30,22 +30,22 @@
|
||||
using namespace upm;
|
||||
|
||||
Buzzer::Buzzer (int pinNumber) {
|
||||
m_pwm_context = maa_pwm_init (pinNumber);
|
||||
m_pwm_context = mraa_pwm_init (pinNumber);
|
||||
m_name = "Buzzer";
|
||||
}
|
||||
|
||||
int Buzzer::playSound (int note, int delay) {
|
||||
maa_pwm_enable (m_pwm_context, 1);
|
||||
maa_pwm_period_us (m_pwm_context, note);
|
||||
maa_pwm_pulsewidth_us (m_pwm_context, note / 2);
|
||||
mraa_pwm_enable (m_pwm_context, 1);
|
||||
mraa_pwm_period_us (m_pwm_context, note);
|
||||
mraa_pwm_pulsewidth_us (m_pwm_context, note / 2);
|
||||
usleep (delay);
|
||||
maa_pwm_enable (m_pwm_context, 0);
|
||||
mraa_pwm_enable (m_pwm_context, 0);
|
||||
|
||||
return note;
|
||||
}
|
||||
|
||||
Buzzer::~Buzzer() {
|
||||
maa_pwm_close(m_pwm_context);
|
||||
std::cout << "executed maa_pwm_close" << std::endl;
|
||||
mraa_pwm_close(m_pwm_context);
|
||||
std::cout << "executed mraa_pwm_close" << std::endl;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/pwm.h>
|
||||
#include <mraa/pwm.h>
|
||||
|
||||
#define DO 3300 // 261 Hz 3830
|
||||
#define RE 2930 // 294 Hz
|
||||
@ -76,6 +76,6 @@ class Buzzer {
|
||||
protected:
|
||||
std::string m_name;
|
||||
private:
|
||||
maa_pwm_context m_pwm_context;
|
||||
mraa_pwm_context m_pwm_context;
|
||||
};
|
||||
}
|
||||
|
@ -33,31 +33,31 @@ using namespace upm;
|
||||
|
||||
GroveLed::GroveLed(int pin)
|
||||
{
|
||||
maa_init();
|
||||
m_gpio = maa_gpio_init(pin);
|
||||
maa_gpio_dir(m_gpio, MAA_GPIO_OUT);
|
||||
mraa_init();
|
||||
m_gpio = mraa_gpio_init(pin);
|
||||
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
|
||||
m_name = "LED Socket";
|
||||
}
|
||||
|
||||
GroveLed::~GroveLed()
|
||||
{
|
||||
maa_gpio_close(m_gpio);
|
||||
mraa_gpio_close(m_gpio);
|
||||
}
|
||||
|
||||
maa_result_t GroveLed::write(int value)
|
||||
mraa_result_t GroveLed::write(int value)
|
||||
{
|
||||
if (value >= 1) {
|
||||
return maa_gpio_write(m_gpio, 1);
|
||||
return mraa_gpio_write(m_gpio, 1);
|
||||
}
|
||||
return maa_gpio_write(m_gpio, 0);
|
||||
return mraa_gpio_write(m_gpio, 0);
|
||||
}
|
||||
|
||||
maa_result_t GroveLed::on()
|
||||
mraa_result_t GroveLed::on()
|
||||
{
|
||||
return write(1);
|
||||
}
|
||||
|
||||
maa_result_t GroveLed::off()
|
||||
mraa_result_t GroveLed::off()
|
||||
{
|
||||
return write(0);
|
||||
}
|
||||
@ -66,19 +66,19 @@ maa_result_t GroveLed::off()
|
||||
|
||||
GroveTemp::GroveTemp(unsigned int pin)
|
||||
{
|
||||
maa_init();
|
||||
m_aio = maa_aio_init(pin);
|
||||
mraa_init();
|
||||
m_aio = mraa_aio_init(pin);
|
||||
m_name = "Temperature Sensor";
|
||||
}
|
||||
|
||||
GroveTemp::~GroveTemp()
|
||||
{
|
||||
maa_aio_close(m_aio);
|
||||
mraa_aio_close(m_aio);
|
||||
}
|
||||
|
||||
int GroveTemp::value ()
|
||||
{
|
||||
int a = maa_aio_read(m_aio);
|
||||
int a = mraa_aio_read(m_aio);
|
||||
float r = (float)(1023-a)*10000/a;
|
||||
float t = 1/(logf(r/10000)/3975 + 1/298.15)-273.15;
|
||||
return (int) t;
|
||||
@ -86,32 +86,32 @@ int GroveTemp::value ()
|
||||
|
||||
float GroveTemp::raw_value()
|
||||
{
|
||||
return (float) maa_aio_read(m_aio);
|
||||
return (float) mraa_aio_read(m_aio);
|
||||
}
|
||||
|
||||
//// GroveLight ////
|
||||
|
||||
GroveLight::GroveLight(unsigned int pin)
|
||||
{
|
||||
maa_init();
|
||||
m_aio = maa_aio_init(pin);
|
||||
mraa_init();
|
||||
m_aio = mraa_aio_init(pin);
|
||||
m_name = "Light Sensor";
|
||||
}
|
||||
|
||||
GroveLight::~GroveLight()
|
||||
{
|
||||
maa_aio_close(m_aio);
|
||||
mraa_aio_close(m_aio);
|
||||
}
|
||||
|
||||
int GroveLight::value ()
|
||||
{
|
||||
// rough conversion to Lux
|
||||
int a = maa_aio_read(m_aio);
|
||||
int a = mraa_aio_read(m_aio);
|
||||
a = 10000/(((1023-a)*10/a)*15)^(4/3);
|
||||
return a;
|
||||
}
|
||||
|
||||
float GroveLight::raw_value()
|
||||
{
|
||||
return (float) maa_aio_read(m_aio);
|
||||
return (float) mraa_aio_read(m_aio);
|
||||
}
|
||||
|
@ -24,8 +24,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/aio.h>
|
||||
#include <maa/gpio.h>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
|
||||
namespace upm {
|
||||
|
||||
@ -44,11 +44,11 @@ class GroveLed: public Grove {
|
||||
public:
|
||||
GroveLed(int pin);
|
||||
~GroveLed();
|
||||
maa_result_t write(int value);
|
||||
maa_result_t off();
|
||||
maa_result_t on();
|
||||
mraa_result_t write(int value);
|
||||
mraa_result_t off();
|
||||
mraa_result_t on();
|
||||
private:
|
||||
maa_gpio_context m_gpio;
|
||||
mraa_gpio_context m_gpio;
|
||||
};
|
||||
|
||||
class GroveTemp: public Grove {
|
||||
@ -58,7 +58,7 @@ class GroveTemp: public Grove {
|
||||
float raw_value();
|
||||
int value();
|
||||
private:
|
||||
maa_aio_context m_aio;
|
||||
mraa_aio_context m_aio;
|
||||
};
|
||||
|
||||
class GroveLight: public Grove {
|
||||
@ -68,7 +68,7 @@ class GroveLight: public Grove {
|
||||
float raw_value();
|
||||
int value();
|
||||
private:
|
||||
maa_aio_context m_aio;
|
||||
mraa_aio_context m_aio;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -36,10 +36,10 @@ GY65::GY65 (int bus, int devAddr, uint8_t mode) {
|
||||
m_controlAddr = devAddr;
|
||||
m_bus = bus;
|
||||
|
||||
m_i2ControlCtx = maa_i2c_init(m_bus);
|
||||
m_i2ControlCtx = mraa_i2c_init(m_bus);
|
||||
|
||||
maa_result_t ret = maa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
if (ret != MAA_SUCCESS) {
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
fprintf(stderr, "Messed up i2c bus\n");
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ GY65::GY65 (int bus, int devAddr, uint8_t mode) {
|
||||
}
|
||||
|
||||
GY65::~GY65() {
|
||||
maa_i2c_stop(m_i2ControlCtx);
|
||||
mraa_i2c_stop(m_i2ControlCtx);
|
||||
}
|
||||
|
||||
int32_t
|
||||
@ -180,13 +180,13 @@ GY65::computeB5(int32_t UT) {
|
||||
return X1 + X2;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
GY65::i2cWriteReg (uint8_t reg, uint8_t value) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
uint8_t data[2] = { reg, value };
|
||||
error = maa_i2c_address (m_i2ControlCtx, m_controlAddr);
|
||||
error = maa_i2c_write (m_i2ControlCtx, data, 2);
|
||||
error = mraa_i2c_address (m_i2ControlCtx, m_controlAddr);
|
||||
error = mraa_i2c_write (m_i2ControlCtx, data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
@ -195,11 +195,11 @@ uint16_t
|
||||
GY65::i2cReadReg_16 (int reg) {
|
||||
uint16_t data;
|
||||
|
||||
maa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
maa_i2c_write_byte(m_i2ControlCtx, reg);
|
||||
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
mraa_i2c_write_byte(m_i2ControlCtx, reg);
|
||||
|
||||
maa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
maa_i2c_read(m_i2ControlCtx, (uint8_t *)&data, 0x2);
|
||||
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
mraa_i2c_read(m_i2ControlCtx, (uint8_t *)&data, 0x2);
|
||||
|
||||
uint8_t high = (data & 0xFF00) >> 8;
|
||||
data = (data << 8) & 0xFF00;
|
||||
@ -212,11 +212,11 @@ uint8_t
|
||||
GY65::i2cReadReg_8 (int reg) {
|
||||
uint8_t data;
|
||||
|
||||
maa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
maa_i2c_write_byte(m_i2ControlCtx, reg);
|
||||
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
mraa_i2c_write_byte(m_i2ControlCtx, reg);
|
||||
|
||||
maa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
maa_i2c_read(m_i2ControlCtx, &data, 0x1);
|
||||
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
mraa_i2c_read(m_i2ControlCtx, &data, 0x1);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/i2c.h>
|
||||
#include <mraa/i2c.h>
|
||||
#include <math.h>
|
||||
|
||||
#define ADDR 0x77 // device address
|
||||
@ -137,7 +137,7 @@ class GY65 {
|
||||
* @param reg address of a register
|
||||
* @param value byte to be written
|
||||
*/
|
||||
maa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
mraa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
|
||||
/**
|
||||
* Read one byte register
|
||||
@ -151,7 +151,7 @@ class GY65 {
|
||||
|
||||
int m_controlAddr;
|
||||
int m_bus;
|
||||
maa_i2c_context m_i2ControlCtx;
|
||||
mraa_i2c_context m_i2ControlCtx;
|
||||
|
||||
uint8_t oversampling;
|
||||
int16_t ac1, ac2, ac3, b1, b2, mb, mc, md;
|
||||
|
@ -32,43 +32,43 @@
|
||||
using namespace upm;
|
||||
|
||||
HCSR04::HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void *)) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
m_name = "HCSR04";
|
||||
|
||||
m_pwmTriggerCtx = maa_pwm_init (triggerPin);
|
||||
m_pwmTriggerCtx = mraa_pwm_init (triggerPin);
|
||||
if (m_pwmTriggerCtx == NULL) {
|
||||
std::cout << "PWM context is NULL" << std::endl;
|
||||
exit (1);
|
||||
}
|
||||
|
||||
maa_init();
|
||||
m_echoPinCtx = maa_gpio_init(echoPin);
|
||||
mraa_init();
|
||||
m_echoPinCtx = mraa_gpio_init(echoPin);
|
||||
if (m_echoPinCtx == NULL) {
|
||||
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", echoPin);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
maa_gpio_dir(m_echoPinCtx, MAA_GPIO_IN);
|
||||
gpio_edge_t edge = MAA_GPIO_EDGE_BOTH;
|
||||
maa_gpio_isr (m_echoPinCtx, edge, fptr, NULL);
|
||||
mraa_gpio_dir(m_echoPinCtx, MRAA_GPIO_IN);
|
||||
gpio_edge_t edge = MRAA_GPIO_EDGE_BOTH;
|
||||
mraa_gpio_isr (m_echoPinCtx, edge, fptr, NULL);
|
||||
}
|
||||
|
||||
HCSR04::~HCSR04 () {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
maa_pwm_close (m_pwmTriggerCtx);
|
||||
error = maa_gpio_close (m_echoPinCtx);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print (error);
|
||||
mraa_pwm_close (m_pwmTriggerCtx);
|
||||
error = mraa_gpio_close (m_echoPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
HCSR04::getDistance () {
|
||||
maa_pwm_enable (m_pwmTriggerCtx, 1);
|
||||
maa_pwm_period_us (m_pwmTriggerCtx, MAX_PERIOD);
|
||||
maa_pwm_pulsewidth_us (m_pwmTriggerCtx, TRIGGER_PULSE);
|
||||
maa_pwm_enable (m_pwmTriggerCtx, 0);
|
||||
mraa_pwm_enable (m_pwmTriggerCtx, 1);
|
||||
mraa_pwm_period_us (m_pwmTriggerCtx, MAX_PERIOD);
|
||||
mraa_pwm_pulsewidth_us (m_pwmTriggerCtx, TRIGGER_PULSE);
|
||||
mraa_pwm_enable (m_pwmTriggerCtx, 0);
|
||||
|
||||
m_doWork = 0;
|
||||
m_InterruptCounter = 0;
|
||||
|
@ -24,9 +24,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/aio.h>
|
||||
#include <maa/gpio.h>
|
||||
#include <maa/pwm.h>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <mraa/pwm.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#define HIGH 1
|
||||
@ -85,8 +85,8 @@ class HCSR04 {
|
||||
}
|
||||
|
||||
private:
|
||||
maa_pwm_context m_pwmTriggerCtx;
|
||||
maa_gpio_context m_echoPinCtx;
|
||||
mraa_pwm_context m_pwmTriggerCtx;
|
||||
mraa_gpio_context m_echoPinCtx;
|
||||
|
||||
uint8_t m_waitEcho;
|
||||
long m_RisingTimeStamp;
|
||||
|
@ -79,17 +79,17 @@ using namespace upm;
|
||||
|
||||
Hmc5883l::Hmc5883l(int bus)
|
||||
{
|
||||
m_i2c = maa_i2c_init(bus);
|
||||
m_i2c = mraa_i2c_init(bus);
|
||||
|
||||
maa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
mraa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
m_rx_tx_buf[0] = HMC5883L_CONF_REG_B;
|
||||
m_rx_tx_buf[1] = GA_1_3_REG;
|
||||
maa_i2c_write(m_i2c, m_rx_tx_buf, 2);
|
||||
mraa_i2c_write(m_i2c, m_rx_tx_buf, 2);
|
||||
|
||||
maa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
mraa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
m_rx_tx_buf[0] = HMC5883L_MODE_REG;
|
||||
m_rx_tx_buf[1] = HMC5883L_CONT_MODE;
|
||||
maa_i2c_write(m_i2c, m_rx_tx_buf, 2);
|
||||
mraa_i2c_write(m_i2c, m_rx_tx_buf, 2);
|
||||
|
||||
Hmc5883l::update();
|
||||
}
|
||||
@ -97,11 +97,11 @@ Hmc5883l::Hmc5883l(int bus)
|
||||
int
|
||||
Hmc5883l::update(void)
|
||||
{
|
||||
maa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
maa_i2c_write_byte(m_i2c, HMC5883L_DATA_REG);
|
||||
mraa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
mraa_i2c_write_byte(m_i2c, HMC5883L_DATA_REG);
|
||||
|
||||
maa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
maa_i2c_read(m_i2c, m_rx_tx_buf, DATA_REG_SIZE);
|
||||
mraa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
mraa_i2c_read(m_i2c, m_rx_tx_buf, DATA_REG_SIZE);
|
||||
|
||||
// x
|
||||
m_coor[0] = (m_rx_tx_buf[HMC5883L_X_MSB_REG] << 8 ) | m_rx_tx_buf[HMC5883L_X_LSB_REG];
|
||||
@ -110,7 +110,7 @@ Hmc5883l::update(void)
|
||||
// y
|
||||
m_coor[1] = (m_rx_tx_buf[HMC5883L_Y_MSB_REG] << 8 ) | m_rx_tx_buf[HMC5883L_Y_LSB_REG];
|
||||
|
||||
return MAA_SUCCESS;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
float
|
||||
|
@ -23,7 +23,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <maa/i2c.h>
|
||||
#include <mraa/i2c.h>
|
||||
|
||||
#define MAX_BUFFER_LENGTH 6
|
||||
|
||||
@ -55,7 +55,7 @@ public:
|
||||
private:
|
||||
int m_coor[3];
|
||||
uint8_t m_rx_tx_buf[MAX_BUFFER_LENGTH];
|
||||
maa_i2c_context m_i2c;
|
||||
mraa_i2c_context m_i2c;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -33,54 +33,54 @@ I2CLcd::I2CLcd (int bus, int lcdAddress) {
|
||||
m_lcd_control_address = lcdAddress;
|
||||
m_bus = bus;
|
||||
|
||||
m_i2c_lcd_control = maa_i2c_init(m_bus);
|
||||
m_i2c_lcd_control = mraa_i2c_init(m_bus);
|
||||
|
||||
maa_result_t ret = maa_i2c_address(m_i2c_lcd_control, m_lcd_control_address);
|
||||
if (ret != MAA_SUCCESS) {
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2c_lcd_control, m_lcd_control_address);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
fprintf(stderr, "Messed up i2c bus\n");
|
||||
}
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
I2CLcd::write (int row, int column, std::string msg) {
|
||||
setCursor (row, column);
|
||||
write (msg);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
I2CLcd::close() {
|
||||
return maa_i2c_stop(m_i2c_lcd_control);
|
||||
return mraa_i2c_stop(m_i2c_lcd_control);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
I2CLcd::i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t
|
||||
I2CLcd::i2cReg (mraa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
uint8_t data[2] = { addr, value };
|
||||
error = maa_i2c_address (ctx, deviceAdress);
|
||||
error = maa_i2c_write (ctx, data, 2);
|
||||
error = mraa_i2c_address (ctx, deviceAdress);
|
||||
error = mraa_i2c_write (ctx, data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
I2CLcd::i2Cmd (maa_i2c_context ctx, uint8_t value) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t
|
||||
I2CLcd::i2Cmd (mraa_i2c_context ctx, uint8_t value) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
uint8_t data[2] = { LCD_CMD, value };
|
||||
error = maa_i2c_address (ctx, m_lcd_control_address);
|
||||
error = maa_i2c_write (ctx, data, 2);
|
||||
error = mraa_i2c_address (ctx, m_lcd_control_address);
|
||||
error = mraa_i2c_write (ctx, data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
I2CLcd::i2cData (maa_i2c_context ctx, uint8_t value) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t
|
||||
I2CLcd::i2cData (mraa_i2c_context ctx, uint8_t value) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
uint8_t data[2] = { LCD_DATA, value };
|
||||
error = maa_i2c_address (ctx, m_lcd_control_address);
|
||||
error = maa_i2c_write (ctx, data, 2);
|
||||
error = mraa_i2c_address (ctx, m_lcd_control_address);
|
||||
error = mraa_i2c_write (ctx, data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/i2c.h>
|
||||
#include <mraa/i2c.h>
|
||||
|
||||
namespace upm {
|
||||
|
||||
@ -70,17 +70,17 @@ namespace upm {
|
||||
class I2CLcd {
|
||||
public:
|
||||
I2CLcd (int bus, int lcdAddress);
|
||||
maa_result_t write (int x, int y, std::string msg);
|
||||
mraa_result_t write (int x, int y, std::string msg);
|
||||
|
||||
virtual maa_result_t write (std::string msg) = 0;
|
||||
virtual maa_result_t setCursor (int row, int column) = 0;
|
||||
virtual maa_result_t clear () = 0;
|
||||
virtual maa_result_t home () = 0;
|
||||
virtual maa_result_t i2Cmd (maa_i2c_context ctx, uint8_t value);
|
||||
virtual maa_result_t i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
|
||||
virtual maa_result_t i2cData (maa_i2c_context ctx, uint8_t value);
|
||||
virtual mraa_result_t write (std::string msg) = 0;
|
||||
virtual mraa_result_t setCursor (int row, int column) = 0;
|
||||
virtual mraa_result_t clear () = 0;
|
||||
virtual mraa_result_t home () = 0;
|
||||
virtual mraa_result_t i2Cmd (mraa_i2c_context ctx, uint8_t value);
|
||||
virtual mraa_result_t i2cReg (mraa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
|
||||
virtual mraa_result_t i2cData (mraa_i2c_context ctx, uint8_t value);
|
||||
|
||||
maa_result_t close();
|
||||
mraa_result_t close();
|
||||
std::string name()
|
||||
{
|
||||
return m_name;
|
||||
@ -89,7 +89,7 @@ class I2CLcd {
|
||||
std::string m_name;
|
||||
int m_lcd_control_address;
|
||||
int m_bus;
|
||||
maa_i2c_context m_i2c_lcd_control;
|
||||
mraa_i2c_context m_i2c_lcd_control;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -30,13 +30,13 @@
|
||||
using namespace upm;
|
||||
|
||||
Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : I2CLcd(bus, lcdAddress) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
m_rgb_address = rgbAddress;
|
||||
m_i2c_lcd_rgb = maa_i2c_init(m_bus);
|
||||
m_i2c_lcd_rgb = mraa_i2c_init(m_bus);
|
||||
|
||||
maa_result_t ret = maa_i2c_address(m_i2c_lcd_rgb, m_rgb_address);
|
||||
if (ret != MAA_SUCCESS) {
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2c_lcd_rgb, m_rgb_address);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
fprintf(stderr, "Messed up i2c bus\n");
|
||||
}
|
||||
|
||||
@ -75,9 +75,9 @@ Jhd1313m1::~Jhd1313m1() {
|
||||
* virtual area
|
||||
* **************
|
||||
*/
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Jhd1313m1::write (std::string msg) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
uint8_t data[2] = {0x40, 0};
|
||||
for (std::string::size_type i = 0; i < msg.size(); ++i) {
|
||||
error = i2cData (m_i2c_lcd_control, msg[i]);
|
||||
@ -86,9 +86,9 @@ Jhd1313m1::write (std::string msg) {
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Jhd1313m1::setCursor (int row, int column) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
|
||||
uint8_t offset = ((column % 16) + row_addr[row]);
|
||||
error = i2Cmd (m_i2c_lcd_control, offset);
|
||||
@ -96,12 +96,12 @@ Jhd1313m1::setCursor (int row, int column) {
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Jhd1313m1::clear () {
|
||||
return i2Cmd (m_i2c_lcd_control, LCD_CLEARDISPLAY);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Jhd1313m1::home () {
|
||||
return i2Cmd (m_i2c_lcd_control, LCD_RETURNHOME);
|
||||
}
|
||||
|
@ -32,14 +32,14 @@ class Jhd1313m1 : public I2CLcd {
|
||||
public:
|
||||
Jhd1313m1 (int bus, int lcdAddress, int rgbAddress);
|
||||
~Jhd1313m1 ();
|
||||
maa_result_t write (std::string msg);
|
||||
maa_result_t setCursor (int row, int column);
|
||||
maa_result_t clear ();
|
||||
maa_result_t home ();
|
||||
mraa_result_t write (std::string msg);
|
||||
mraa_result_t setCursor (int row, int column);
|
||||
mraa_result_t clear ();
|
||||
mraa_result_t home ();
|
||||
|
||||
private:
|
||||
int m_rgb_address;
|
||||
maa_i2c_context m_i2c_lcd_rgb;
|
||||
mraa_i2c_context m_i2c_lcd_rgb;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -33,7 +33,7 @@
|
||||
using namespace upm;
|
||||
|
||||
Lcm1602::Lcm1602(int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
usleep(50000);
|
||||
expandWrite(LCD_BACKLIGHT);
|
||||
@ -69,18 +69,18 @@ Lcm1602::~Lcm1602 () {
|
||||
* virtual area
|
||||
* **************
|
||||
*/
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Lcm1602::write (std::string msg) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
for (std::string::size_type i = 0; i < msg.size(); ++i) {
|
||||
error = send (msg[i], LCD_RS);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Lcm1602::setCursor (int row, int column) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
|
||||
uint8_t offset = ((column % 16) + row_addr[row]);
|
||||
@ -88,12 +88,12 @@ Lcm1602::setCursor (int row, int column) {
|
||||
return send (LCD_CMD | offset, 0);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Lcm1602::clear () {
|
||||
return send(LCD_CLEARDISPLAY, 0);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Lcm1602::home () {
|
||||
return send(LCD_RETURNHOME, 0);
|
||||
}
|
||||
@ -103,9 +103,9 @@ Lcm1602::home () {
|
||||
* private area
|
||||
* **************
|
||||
*/
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Lcm1602::send (uint8_t value, int mode) {
|
||||
maa_result_t ret = MAA_SUCCESS;
|
||||
mraa_result_t ret = MRAA_SUCCESS;
|
||||
uint8_t h = value & 0xf0;
|
||||
uint8_t l = (value << 4) & 0xf0;
|
||||
ret = write4bits(h | mode);
|
||||
@ -113,26 +113,26 @@ Lcm1602::send (uint8_t value, int mode) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Lcm1602::write4bits(uint8_t value)
|
||||
{
|
||||
maa_result_t ret = MAA_SUCCESS;
|
||||
mraa_result_t ret = MRAA_SUCCESS;
|
||||
ret = expandWrite(value);
|
||||
ret = pulseEnable(value);
|
||||
return ret;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Lcm1602::expandWrite(uint8_t value)
|
||||
{
|
||||
uint8_t buffer = value | LCD_BACKLIGHT;
|
||||
return maa_i2c_write_byte(m_i2c_lcd_control, buffer);
|
||||
return mraa_i2c_write_byte(m_i2c_lcd_control, buffer);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Lcm1602::pulseEnable(uint8_t value)
|
||||
{
|
||||
maa_result_t ret = MAA_SUCCESS;
|
||||
mraa_result_t ret = MRAA_SUCCESS;
|
||||
ret = expandWrite(value | LCD_EN);
|
||||
usleep(1);
|
||||
ret = expandWrite(value & ~LCD_EN);
|
||||
|
@ -35,21 +35,21 @@ namespace upm {
|
||||
class Lcm1602 : public I2CLcd {
|
||||
public:
|
||||
/** LCM1602 Constructor.
|
||||
* Calls MAA initialisation functions.
|
||||
* Calls MRAA initialisation functions.
|
||||
* @param bus i2c bus to use
|
||||
* @param address the slave address the lcd is registered on.
|
||||
*/
|
||||
Lcm1602(int bus, int address);
|
||||
~Lcm1602();
|
||||
maa_result_t write (std::string msg);
|
||||
maa_result_t setCursor (int row, int column);
|
||||
maa_result_t clear ();
|
||||
maa_result_t home ();
|
||||
mraa_result_t write (std::string msg);
|
||||
mraa_result_t setCursor (int row, int column);
|
||||
mraa_result_t clear ();
|
||||
mraa_result_t home ();
|
||||
|
||||
private :
|
||||
maa_result_t send (uint8_t value, int mode);
|
||||
maa_result_t write4bits(uint8_t value);
|
||||
maa_result_t expandWrite(uint8_t value);
|
||||
maa_result_t pulseEnable(uint8_t value);
|
||||
mraa_result_t send (uint8_t value, int mode);
|
||||
mraa_result_t write4bits(uint8_t value);
|
||||
mraa_result_t expandWrite(uint8_t value);
|
||||
mraa_result_t pulseEnable(uint8_t value);
|
||||
};
|
||||
}
|
||||
|
@ -45,9 +45,9 @@ SSD1308::~SSD1308 () {
|
||||
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1308::draw (uint8_t *data, int bytes) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
setAddressingMode (HORIZONTAL);
|
||||
for (int idx = 0; idx < bytes; idx++) {
|
||||
@ -62,9 +62,9 @@ SSD1308::draw (uint8_t *data, int bytes) {
|
||||
* virtual area
|
||||
* **************
|
||||
*/
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1308::write (std::string msg) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
uint8_t data[2] = {0x40, 0};
|
||||
|
||||
setAddressingMode (PAGE);
|
||||
@ -75,9 +75,9 @@ SSD1308::write (std::string msg) {
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1308::setCursor (int row, int column) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
error = i2Cmd (m_i2c_lcd_control, BASE_PAGE_START_ADDR + row); // set page address
|
||||
error = i2Cmd (m_i2c_lcd_control, BASE_LOW_COLUMN_ADDR + (8 * column & 0x0F)); // set column lower address
|
||||
@ -86,9 +86,9 @@ SSD1308::setCursor (int row, int column) {
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1308::clear () {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
uint8_t columnIdx, rowIdx;
|
||||
|
||||
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_OFF); // display off
|
||||
@ -103,10 +103,10 @@ SSD1308::clear () {
|
||||
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_ON); // display on
|
||||
home ();
|
||||
|
||||
return MAA_SUCCESS;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1308::home () {
|
||||
return setCursor (0, 0);
|
||||
}
|
||||
@ -116,8 +116,8 @@ SSD1308::home () {
|
||||
* private area
|
||||
* **************
|
||||
*/
|
||||
maa_result_t
|
||||
SSD1308::writeChar (maa_i2c_context ctx, uint8_t value) {
|
||||
mraa_result_t
|
||||
SSD1308::writeChar (mraa_i2c_context ctx, uint8_t value) {
|
||||
if (value < 0x20 || value > 0x7F) {
|
||||
value = 0x20; // space
|
||||
}
|
||||
@ -127,12 +127,12 @@ SSD1308::writeChar (maa_i2c_context ctx, uint8_t value) {
|
||||
}
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1308::setNormalDisplay () {
|
||||
return i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL); // set to normal display '1' is ON
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1308::setAddressingMode (displayAddressingMode mode) {
|
||||
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_MEM_ADDR_MODE); //set addressing mode
|
||||
i2Cmd (m_i2c_lcd_control, mode); //set page addressing mode
|
||||
|
@ -148,23 +148,23 @@ typedef enum {
|
||||
class SSD1308 : public I2CLcd {
|
||||
public:
|
||||
/** SSD1308 Constructor.
|
||||
* Calls MAA initialisation functions.
|
||||
* Calls MRAA initialisation functions.
|
||||
* @param bus i2c bus to use
|
||||
* @param address the slave address the lcd is registered on.
|
||||
*/
|
||||
SSD1308 (int bus, int address);
|
||||
~SSD1308 ();
|
||||
maa_result_t draw(uint8_t *data, int bytes);
|
||||
mraa_result_t draw(uint8_t *data, int bytes);
|
||||
|
||||
// pure virtual methods
|
||||
maa_result_t write (std::string msg);
|
||||
maa_result_t setCursor (int row, int column);
|
||||
maa_result_t clear ();
|
||||
maa_result_t home ();
|
||||
mraa_result_t write (std::string msg);
|
||||
mraa_result_t setCursor (int row, int column);
|
||||
mraa_result_t clear ();
|
||||
mraa_result_t home ();
|
||||
|
||||
private:
|
||||
maa_result_t writeChar (maa_i2c_context ctx, uint8_t value);
|
||||
maa_result_t setNormalDisplay ();
|
||||
maa_result_t setAddressingMode (displayAddressingMode mode);
|
||||
mraa_result_t writeChar (mraa_i2c_context ctx, uint8_t value);
|
||||
mraa_result_t setNormalDisplay ();
|
||||
mraa_result_t setAddressingMode (displayAddressingMode mode);
|
||||
};
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ using namespace upm;
|
||||
#define CMD_SLEEP 10000
|
||||
|
||||
SSD1327::SSD1327 (int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
usleep (INIT_SLEEP);
|
||||
i2Cmd (m_i2c_lcd_control, 0xFD); // Unlock OLED driver IC MCU interface from entering command. i.e: Accept commands
|
||||
usleep (INIT_SLEEP);
|
||||
@ -123,9 +123,9 @@ SSD1327::~SSD1327 () {
|
||||
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1327::draw (uint8_t *data, int bytes) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
setHorizontalMode ();
|
||||
for (int row = 0; row < bytes; row++) {
|
||||
@ -151,9 +151,9 @@ SSD1327::draw (uint8_t *data, int bytes) {
|
||||
* virtual area
|
||||
* **************
|
||||
*/
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1327::write (std::string msg) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
setVerticalMode ();
|
||||
for (std::string::size_type i = 0; i < msg.size(); ++i) {
|
||||
@ -163,9 +163,9 @@ SSD1327::write (std::string msg) {
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1327::setCursor (int row, int column) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
//Column Address
|
||||
i2Cmd (m_i2c_lcd_control, 0x15); /* Set Column Address */
|
||||
@ -185,9 +185,9 @@ SSD1327::setCursor (int row, int column) {
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1327::clear () {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
uint8_t columnIdx, rowIdx;
|
||||
|
||||
for(rowIdx = 0; rowIdx < 12; rowIdx++) {
|
||||
@ -197,15 +197,15 @@ SSD1327::clear () {
|
||||
}
|
||||
}
|
||||
|
||||
return MAA_SUCCESS;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1327::home () {
|
||||
return setCursor (0, 0);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1327::setGrayLevel (uint8_t level) {
|
||||
grayHigh = (level << 4) & 0xF0;
|
||||
grayLow = level & 0x0F;
|
||||
@ -216,8 +216,8 @@ SSD1327::setGrayLevel (uint8_t level) {
|
||||
* private area
|
||||
* **************
|
||||
*/
|
||||
maa_result_t
|
||||
SSD1327::writeChar (maa_i2c_context ctx, uint8_t value) {
|
||||
mraa_result_t
|
||||
SSD1327::writeChar (mraa_i2c_context ctx, uint8_t value) {
|
||||
if (value < 0x20 || value > 0x7F) {
|
||||
value = 0x20; // space
|
||||
}
|
||||
@ -238,12 +238,12 @@ SSD1327::writeChar (maa_i2c_context ctx, uint8_t value) {
|
||||
}
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1327::setNormalDisplay () {
|
||||
return i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL); // set to normal display '1' is ON
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1327::setHorizontalMode () {
|
||||
i2Cmd (m_i2c_lcd_control, 0xA0); // remap to
|
||||
usleep (CMD_SLEEP);
|
||||
@ -267,7 +267,7 @@ SSD1327::setHorizontalMode () {
|
||||
usleep (CMD_SLEEP);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1327::setVerticalMode () {
|
||||
i2Cmd (m_i2c_lcd_control, 0xA0); // remap to
|
||||
usleep (CMD_SLEEP);
|
||||
|
@ -148,26 +148,26 @@ typedef enum {
|
||||
class SSD1327 : public I2CLcd {
|
||||
public:
|
||||
/** SSD1308 Constructor.
|
||||
* Calls MAA initialisation functions.
|
||||
* Calls MRAA initialisation functions.
|
||||
* @param bus i2c bus to use
|
||||
* @param address the slave address the lcd is registered on.
|
||||
*/
|
||||
SSD1327 (int bus, int address);
|
||||
~SSD1327 ();
|
||||
maa_result_t draw(uint8_t *data, int bytes);
|
||||
mraa_result_t draw(uint8_t *data, int bytes);
|
||||
|
||||
// virtual methods
|
||||
maa_result_t write (std::string msg);
|
||||
maa_result_t setCursor (int row, int column);
|
||||
maa_result_t clear ();
|
||||
maa_result_t home ();
|
||||
maa_result_t setGrayLevel (uint8_t level);
|
||||
mraa_result_t write (std::string msg);
|
||||
mraa_result_t setCursor (int row, int column);
|
||||
mraa_result_t clear ();
|
||||
mraa_result_t home ();
|
||||
mraa_result_t setGrayLevel (uint8_t level);
|
||||
|
||||
private:
|
||||
maa_result_t writeChar (maa_i2c_context ctx, uint8_t value);
|
||||
maa_result_t setNormalDisplay ();
|
||||
maa_result_t setHorizontalMode ();
|
||||
maa_result_t setVerticalMode ();
|
||||
mraa_result_t writeChar (mraa_i2c_context ctx, uint8_t value);
|
||||
mraa_result_t setNormalDisplay ();
|
||||
mraa_result_t setHorizontalMode ();
|
||||
mraa_result_t setVerticalMode ();
|
||||
|
||||
uint8_t grayHigh;
|
||||
uint8_t grayLow;
|
||||
|
@ -36,12 +36,12 @@ using namespace upm;
|
||||
MAX31855::MAX31855(int bus, int cs)
|
||||
{
|
||||
// initialise chip select as a normal gpio
|
||||
m_gpio = maa_gpio_init(cs);
|
||||
maa_gpio_dir(m_gpio, MAA_GPIO_OUT);
|
||||
m_gpio = mraa_gpio_init(cs);
|
||||
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
|
||||
|
||||
// initialise the spi bus with a 2Mhz clock
|
||||
m_sensor = maa_spi_init(bus);
|
||||
maa_spi_frequency(m_sensor, 2000000);
|
||||
m_sensor = mraa_spi_init(bus);
|
||||
mraa_spi_frequency(m_sensor, 2000000);
|
||||
}
|
||||
//! [Constructor]
|
||||
|
||||
@ -49,14 +49,14 @@ MAX31855::MAX31855(int bus, int cs)
|
||||
MAX31855::~MAX31855()
|
||||
{
|
||||
// close both m_sensor & m_gpio cleanly
|
||||
maa_result_t error;
|
||||
error = maa_spi_stop(m_sensor);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print(error);
|
||||
mraa_result_t error;
|
||||
error = mraa_spi_stop(m_sensor);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
error = maa_gpio_close(m_gpio);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print(error);
|
||||
error = mraa_gpio_close(m_gpio);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
//! [Destructor]
|
||||
@ -66,7 +66,7 @@ MAX31855::getTemp()
|
||||
{
|
||||
//! [spi]
|
||||
// set chip select low
|
||||
maa_gpio_write(m_gpio, 0);
|
||||
mraa_gpio_write(m_gpio, 0);
|
||||
|
||||
uint8_t buf[4];
|
||||
|
||||
@ -74,14 +74,14 @@ MAX31855::getTemp()
|
||||
memset(buf, 0, sizeof(uint8_t)*4);
|
||||
|
||||
// Write buffer to the spi slave
|
||||
uint8_t* x = maa_spi_write_buf(m_sensor, buf, 4);
|
||||
uint8_t* x = mraa_spi_write_buf(m_sensor, buf, 4);
|
||||
//! [spi]
|
||||
|
||||
//! [conversion]
|
||||
// Endian correct way of making our char array into an 32bit int
|
||||
int32_t temp = (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3];;
|
||||
|
||||
// maa_spi_write_buf does not free the return buffer
|
||||
// mraa_spi_write_buf does not free the return buffer
|
||||
free(x);
|
||||
|
||||
if (temp & 0x7) {
|
||||
@ -97,7 +97,7 @@ MAX31855::getTemp()
|
||||
//! [conversion]
|
||||
|
||||
// set chip select high
|
||||
maa_gpio_write(m_gpio, 1);
|
||||
mraa_gpio_write(m_gpio, 1);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
@ -24,8 +24,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/spi.h>
|
||||
#include <maa/gpio.h>
|
||||
#include <mraa/spi.h>
|
||||
#include <mraa/gpio.h>
|
||||
|
||||
namespace upm {
|
||||
|
||||
@ -61,8 +61,8 @@ class MAX31855 {
|
||||
double getTemp();
|
||||
|
||||
private:
|
||||
maa_spi_context m_sensor;
|
||||
maa_gpio_context m_gpio;
|
||||
mraa_spi_context m_sensor;
|
||||
mraa_gpio_context m_gpio;
|
||||
};
|
||||
//! [Interesting]
|
||||
|
||||
|
@ -36,10 +36,10 @@ MAX44000::MAX44000 (int bus, int devAddr) {
|
||||
m_maxControlAddr = devAddr;
|
||||
m_bus = bus;
|
||||
|
||||
m_i2cMaxControlCtx = maa_i2c_init(m_bus);
|
||||
m_i2cMaxControlCtx = mraa_i2c_init(m_bus);
|
||||
|
||||
maa_result_t ret = maa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
if (ret != MAA_SUCCESS) {
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
fprintf(stderr, "Messed up i2c bus\n");
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ MAX44000::MAX44000 (int bus, int devAddr) {
|
||||
}
|
||||
|
||||
MAX44000::~MAX44000() {
|
||||
maa_i2c_stop(m_i2cMaxControlCtx);
|
||||
mraa_i2c_stop(m_i2cMaxControlCtx);
|
||||
}
|
||||
|
||||
uint16_t
|
||||
@ -80,11 +80,11 @@ uint8_t
|
||||
MAX44000::i2cReadReg_8 (int reg) {
|
||||
uint8_t data;
|
||||
|
||||
maa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
maa_i2c_write_byte(m_i2cMaxControlCtx, reg);
|
||||
mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
mraa_i2c_write_byte(m_i2cMaxControlCtx, reg);
|
||||
|
||||
maa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
maa_i2c_read(m_i2cMaxControlCtx, &data, 0x1);
|
||||
mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
mraa_i2c_read(m_i2cMaxControlCtx, &data, 0x1);
|
||||
|
||||
return data;
|
||||
}
|
||||
@ -93,22 +93,22 @@ uint16_t
|
||||
MAX44000::i2cReadReg_16 (int reg) {
|
||||
uint16_t data;
|
||||
|
||||
maa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
maa_i2c_write_byte(m_i2cMaxControlCtx, reg);
|
||||
mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
mraa_i2c_write_byte(m_i2cMaxControlCtx, reg);
|
||||
|
||||
maa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
maa_i2c_read(m_i2cMaxControlCtx, (uint8_t *)&data, 0x2);
|
||||
mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
mraa_i2c_read(m_i2cMaxControlCtx, (uint8_t *)&data, 0x2);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
MAX44000::i2cWriteReg (uint8_t reg, uint8_t value) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
uint8_t data[2] = { reg, value };
|
||||
error = maa_i2c_address (m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
error = maa_i2c_write (m_i2cMaxControlCtx, data, 2);
|
||||
error = mraa_i2c_address (m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
error = mraa_i2c_write (m_i2cMaxControlCtx, data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/i2c.h>
|
||||
#include <mraa/i2c.h>
|
||||
|
||||
#define ADDR 0x4A // device address
|
||||
|
||||
@ -122,14 +122,14 @@ class MAX44000 {
|
||||
* @param reg address of a register
|
||||
* @param value byte to be written
|
||||
*/
|
||||
maa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
mraa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
|
||||
int m_maxControlAddr;
|
||||
int m_bus;
|
||||
maa_i2c_context m_i2cMaxControlCtx;
|
||||
mraa_i2c_context m_i2cMaxControlCtx;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -33,17 +33,17 @@ using namespace upm;
|
||||
|
||||
Microphone::Microphone(int micPin) {
|
||||
// initialise analog mic input
|
||||
m_micCtx = maa_aio_init(micPin);
|
||||
m_micCtx = mraa_aio_init(micPin);
|
||||
|
||||
|
||||
}
|
||||
|
||||
Microphone::~Microphone() {
|
||||
// close analog input
|
||||
maa_result_t error;
|
||||
error = maa_aio_close(m_micCtx);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print(error);
|
||||
mraa_result_t error;
|
||||
error = mraa_aio_close(m_micCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ Microphone::getSampledWindow (unsigned int freqMS, unsigned int numberOfSamples,
|
||||
}
|
||||
|
||||
while (sampleIdx < numberOfSamples) {
|
||||
buffer[sampleIdx++] = maa_aio_read (m_micCtx);
|
||||
buffer[sampleIdx++] = mraa_aio_read (m_micCtx);
|
||||
usleep(freqMS * 1000);
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/gpio.h>
|
||||
#include <maa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <mraa/aio.h>
|
||||
|
||||
struct thresholdContext {
|
||||
long averageReading;
|
||||
@ -80,7 +80,7 @@ class Microphone {
|
||||
void printGraph (thresholdContext* ctx);
|
||||
|
||||
private:
|
||||
maa_aio_context m_micCtx;
|
||||
mraa_aio_context m_micCtx;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -42,10 +42,10 @@ MMA7455::MMA7455 (int bus, int devAddr) {
|
||||
m_controlAddr = devAddr;
|
||||
m_bus = bus;
|
||||
|
||||
m_i2ControlCtx = maa_i2c_init(m_bus);
|
||||
m_i2ControlCtx = mraa_i2c_init(m_bus);
|
||||
|
||||
maa_result_t error = maa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
if (error != MAA_SUCCESS) {
|
||||
mraa_result_t error = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
fprintf(stderr, "Messed up i2c bus\n");
|
||||
return;
|
||||
}
|
||||
@ -53,24 +53,24 @@ MMA7455::MMA7455 (int bus, int devAddr) {
|
||||
// setting GLVL 0x1 (64LSB/g) and MODE 0x1 (Measurement Mode)
|
||||
data = (BIT (MMA7455_GLVL0) | BIT (MMA7455_MODE0));
|
||||
error = ic2WriteReg (MMA7455_MCTL, &data, 0x1);
|
||||
if (error != MAA_SUCCESS) {
|
||||
if (error != MRAA_SUCCESS) {
|
||||
std::cout << "ERROR :: MMA7455 instance wan not created (Mode)" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (MAA_SUCCESS != calibrate ()) {
|
||||
if (MRAA_SUCCESS != calibrate ()) {
|
||||
std::cout << "ERROR :: MMA7455 instance wan not created (Calibrate)" << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
MMA7455::~MMA7455() {
|
||||
maa_i2c_stop(m_i2ControlCtx);
|
||||
mraa_i2c_stop(m_i2ControlCtx);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
MMA7455::calibrate () {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
int i = 0;
|
||||
|
||||
accelData xyz;
|
||||
@ -78,7 +78,7 @@ MMA7455::calibrate () {
|
||||
|
||||
do {
|
||||
error = readData (&xyz.value.x, &xyz.value.y, &xyz.value.z);
|
||||
if (MAA_SUCCESS != error) {
|
||||
if (MRAA_SUCCESS != error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ MMA7455::calibrate () {
|
||||
xyz.value.z += 2 * -(xyz.value.z - 64);
|
||||
|
||||
error = ic2WriteReg (MMA7455_XOFFL, (unsigned char *) &xyz, 0x6);
|
||||
if (error != MAA_SUCCESS) {
|
||||
if (error != MRAA_SUCCESS) {
|
||||
return error;
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ MMA7455::calibrate () {
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
MMA7455::readData (short * ptrX, short * ptrY, short * ptrZ) {
|
||||
accelData xyz;
|
||||
unsigned char data = 0;
|
||||
@ -104,17 +104,17 @@ MMA7455::readData (short * ptrX, short * ptrY, short * ptrZ) {
|
||||
|
||||
/*do {
|
||||
nBytes = ic2ReadReg (MMA7455_STATUS, &data, 0x1);
|
||||
} while ( !(data & MMA7455_DRDY) && nBytes == MAA_SUCCESS);
|
||||
} while ( !(data & MMA7455_DRDY) && nBytes == MRAA_SUCCESS);
|
||||
|
||||
if (nBytes == MAA_SUCCESS) {
|
||||
if (nBytes == MRAA_SUCCESS) {
|
||||
std::cout << "NO_GDB :: 1" << std::endl;
|
||||
return MAA_SUCCESS;
|
||||
return MRAA_SUCCESS;
|
||||
}*/
|
||||
|
||||
nBytes = ic2ReadReg (MMA7455_XOUTL, (unsigned char *) &xyz, 0x6);
|
||||
if (nBytes == 0) {
|
||||
std::cout << "NO_GDB :: 2" << std::endl;
|
||||
return MAA_ERROR_UNSPECIFIED;
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
if (xyz.reg.x_msb & 0x02) {
|
||||
@ -134,40 +134,40 @@ MMA7455::readData (short * ptrX, short * ptrY, short * ptrZ) {
|
||||
*ptrY = xyz.value.y;
|
||||
*ptrZ = xyz.value.z;
|
||||
|
||||
return MAA_SUCCESS;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
MMA7455::ic2ReadReg (unsigned char reg, unsigned char * buf, unsigned char size) {
|
||||
if (MAA_SUCCESS != maa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
|
||||
if (MRAA_SUCCESS != mraa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (MAA_SUCCESS != maa_i2c_write_byte(m_i2ControlCtx, reg)) {
|
||||
if (MRAA_SUCCESS != mraa_i2c_write_byte(m_i2ControlCtx, reg)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (MAA_SUCCESS != maa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
|
||||
if (MRAA_SUCCESS != mraa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) maa_i2c_read(m_i2ControlCtx, buf, size);
|
||||
return (int) mraa_i2c_read(m_i2ControlCtx, buf, size);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
MMA7455::ic2WriteReg (unsigned char reg, unsigned char * buf, unsigned char size) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
uint8_t data[size + 1];
|
||||
data[0] = reg;
|
||||
memcpy(&data[1], buf, size);
|
||||
|
||||
error = maa_i2c_address (m_i2ControlCtx, m_controlAddr);
|
||||
if (error != MAA_SUCCESS) {
|
||||
error = mraa_i2c_address (m_i2ControlCtx, m_controlAddr);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
return error;
|
||||
}
|
||||
error = maa_i2c_write (m_i2ControlCtx, data, size + 1);
|
||||
if (error != MAA_SUCCESS) {
|
||||
error = mraa_i2c_write (m_i2ControlCtx, data, size + 1);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
return error;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/i2c.h>
|
||||
#include <mraa/i2c.h>
|
||||
|
||||
#define ADDR 0x1D // device address
|
||||
|
||||
@ -183,7 +183,7 @@ class MMA7455 {
|
||||
/**
|
||||
* Calibrate the sensor
|
||||
*/
|
||||
maa_result_t calibrate ();
|
||||
mraa_result_t calibrate ();
|
||||
|
||||
/**
|
||||
* Read X, Y and Z acceleration data
|
||||
@ -192,7 +192,7 @@ class MMA7455 {
|
||||
* @param ptrY Y axis
|
||||
* @param ptrZ Z axis
|
||||
*/
|
||||
maa_result_t readData (short * ptrX, short * ptrY, short * ptrZ);
|
||||
mraa_result_t readData (short * ptrX, short * ptrY, short * ptrZ);
|
||||
|
||||
/**
|
||||
*
|
||||
@ -210,14 +210,14 @@ class MMA7455 {
|
||||
* @param buf register data buffer
|
||||
* @param size buffer size
|
||||
*/
|
||||
maa_result_t ic2WriteReg (unsigned char reg, unsigned char * buf, unsigned char size);
|
||||
mraa_result_t ic2WriteReg (unsigned char reg, unsigned char * buf, unsigned char size);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
|
||||
int m_controlAddr;
|
||||
int m_bus;
|
||||
maa_i2c_context m_i2ControlCtx;
|
||||
mraa_i2c_context m_i2ControlCtx;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -39,10 +39,10 @@ MPU9150::MPU9150 (int bus, int devAddr) {
|
||||
m_i2cAddr = devAddr;
|
||||
m_bus = bus;
|
||||
|
||||
m_i2Ctx = maa_i2c_init(m_bus);
|
||||
m_i2Ctx = mraa_i2c_init(m_bus);
|
||||
|
||||
maa_result_t ret = maa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
if (ret != MAA_SUCCESS) {
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
fprintf(stderr, "Messed up i2c bus\n");
|
||||
}
|
||||
|
||||
@ -50,10 +50,10 @@ MPU9150::MPU9150 (int bus, int devAddr) {
|
||||
}
|
||||
|
||||
MPU9150::~MPU9150() {
|
||||
maa_i2c_stop(m_i2Ctx);
|
||||
mraa_i2c_stop(m_i2Ctx);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
MPU9150::initSensor () {
|
||||
uint8_t regData = 0x0;
|
||||
|
||||
@ -71,7 +71,7 @@ MPU9150::initSensor () {
|
||||
regData &= ~(1 << MPU6050_PWR1_SLEEP_BIT);
|
||||
i2cWriteReg (MPU6050_RA_PWR_MGMT_1, regData);
|
||||
|
||||
return MAA_SUCCESS;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
@ -81,7 +81,7 @@ MPU9150::getDeviceID () {
|
||||
return regData;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
MPU9150::getData () {
|
||||
uint8_t buffer[14];
|
||||
|
||||
@ -130,31 +130,31 @@ MPU9150::getData () {
|
||||
axisMagnetomer.data.axisZ = axisMagnetomer.sumData.axisZ / SMOOTH_TIMES;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
MPU9150::getAcceleromter (Vector3D * data) {
|
||||
data->axisX = axisAcceleromter.data.axisX;
|
||||
data->axisY = axisAcceleromter.data.axisY;
|
||||
data->axisZ = axisAcceleromter.data.axisZ;
|
||||
|
||||
return MAA_SUCCESS;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
MPU9150::getGyro (Vector3D * data) {
|
||||
data->axisX = axisGyroscope.data.axisX;
|
||||
data->axisY = axisGyroscope.data.axisY;
|
||||
data->axisZ = axisGyroscope.data.axisZ;
|
||||
|
||||
return MAA_SUCCESS;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
MPU9150::getMagnometer (Vector3D * data) {
|
||||
data->axisX = axisMagnetomer.data.axisX;
|
||||
data->axisY = axisMagnetomer.data.axisY;
|
||||
data->axisZ = axisMagnetomer.data.axisZ;
|
||||
|
||||
return MAA_SUCCESS;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
float
|
||||
@ -177,21 +177,21 @@ MPU9150::getTemperature () {
|
||||
uint16_t
|
||||
MPU9150::i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer) {
|
||||
int readByte = 0;
|
||||
maa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
maa_i2c_write_byte(m_i2Ctx, reg);
|
||||
mraa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
mraa_i2c_write_byte(m_i2Ctx, reg);
|
||||
|
||||
maa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
readByte = maa_i2c_read(m_i2Ctx, buffer, len);
|
||||
mraa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
readByte = mraa_i2c_read(m_i2Ctx, buffer, len);
|
||||
return readByte;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
MPU9150::i2cWriteReg (uint8_t reg, uint8_t value) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
uint8_t data[2] = { reg, value };
|
||||
error = maa_i2c_address (m_i2Ctx, m_i2cAddr);
|
||||
error = maa_i2c_write (m_i2Ctx, data, 2);
|
||||
error = mraa_i2c_address (m_i2Ctx, m_i2cAddr);
|
||||
error = mraa_i2c_write (m_i2Ctx, data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/i2c.h>
|
||||
#include <mraa/i2c.h>
|
||||
|
||||
#define MPU6050_ADDRESS_AD0_LOW 0x68 // address pin low (GND), default for InvenSense evaluation board
|
||||
#define MPU6050_ADDRESS_AD0_HIGH 0x69 // address pin high (VCC)
|
||||
@ -133,7 +133,7 @@ class MPU9150 {
|
||||
/**
|
||||
* Initiate MPU9150 chips
|
||||
*/
|
||||
maa_result_t initSensor ();
|
||||
mraa_result_t initSensor ();
|
||||
|
||||
/**
|
||||
* Get identity of the device
|
||||
@ -144,22 +144,22 @@ class MPU9150 {
|
||||
* Get the Accelerometer, Gyro and Compass data from the chip and
|
||||
* save it in private section.
|
||||
*/
|
||||
maa_result_t getData ();
|
||||
mraa_result_t getData ();
|
||||
|
||||
/**
|
||||
* @param data structure with 3 axis (x,y,z)
|
||||
*/
|
||||
maa_result_t getAcceleromter (Vector3D * data);
|
||||
mraa_result_t getAcceleromter (Vector3D * data);
|
||||
|
||||
/**
|
||||
* @param data structure with 3 axis (x,y,z)
|
||||
*/
|
||||
maa_result_t getGyro (Vector3D * data);
|
||||
mraa_result_t getGyro (Vector3D * data);
|
||||
|
||||
/**
|
||||
* @param data structure with 3 axis (x,y,z)
|
||||
*/
|
||||
maa_result_t getMagnometer (Vector3D * data);
|
||||
mraa_result_t getMagnometer (Vector3D * data);
|
||||
|
||||
/**
|
||||
* Read on die temperature from the chip
|
||||
@ -179,14 +179,14 @@ class MPU9150 {
|
||||
|
||||
int m_i2cAddr;
|
||||
int m_bus;
|
||||
maa_i2c_context m_i2Ctx;
|
||||
mraa_i2c_context m_i2Ctx;
|
||||
|
||||
AxisData axisMagnetomer;
|
||||
AxisData axisAcceleromter;
|
||||
AxisData axisGyroscope;
|
||||
|
||||
uint16_t i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer);
|
||||
maa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
mraa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
int updateRegBits (uint8_t reg, uint8_t bitStart,
|
||||
uint8_t length, uint16_t data);
|
||||
uint8_t getRegBits (uint8_t reg, uint8_t bitStart,
|
||||
|
@ -31,51 +31,51 @@
|
||||
using namespace upm;
|
||||
|
||||
MY9221::MY9221 (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_OUT);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print(error);
|
||||
error = mraa_gpio_dir(m_clkPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
|
||||
// set direction (out)
|
||||
error = maa_gpio_dir(m_dataPinCtx, MAA_GPIO_OUT);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print(error);
|
||||
error = mraa_gpio_dir(m_dataPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
|
||||
MY9221::~MY9221() {
|
||||
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
|
||||
MY9221::setBarLevel (uint8_t level) {
|
||||
if (level > 10) {
|
||||
return MAA_ERROR_INVALID_PARAMETER;
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
send16bitBlock (CMDMODE);
|
||||
@ -86,25 +86,25 @@ MY9221::setBarLevel (uint8_t level) {
|
||||
lockData ();
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
MY9221::lockData () {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
error = maa_gpio_write (m_dataPinCtx, LOW);
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
error = mraa_gpio_write (m_dataPinCtx, LOW);
|
||||
usleep(100);
|
||||
|
||||
for(int idx = 0; idx < 4; idx++) {
|
||||
error = maa_gpio_write (m_dataPinCtx, HIGH);
|
||||
error = maa_gpio_write (m_dataPinCtx, LOW);
|
||||
error = mraa_gpio_write (m_dataPinCtx, HIGH);
|
||||
error = mraa_gpio_write (m_dataPinCtx, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
MY9221::send16bitBlock (short data) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
for (uint8_t bit_idx = 0; bit_idx < MAX_BIT_PER_BLOCK; bit_idx++) {
|
||||
uint32_t state = (data & 0x8000) ? HIGH : LOW;
|
||||
error = maa_gpio_write (m_dataPinCtx, state);
|
||||
state = maa_gpio_read (m_clkPinCtx);
|
||||
error = mraa_gpio_write (m_dataPinCtx, state);
|
||||
state = mraa_gpio_read (m_clkPinCtx);
|
||||
|
||||
if (state) {
|
||||
state = LOW;
|
||||
@ -112,7 +112,7 @@ MY9221::send16bitBlock (short data) {
|
||||
state = HIGH;
|
||||
}
|
||||
|
||||
error = maa_gpio_write (m_clkPinCtx, state);
|
||||
error = mraa_gpio_write (m_clkPinCtx, state);
|
||||
|
||||
data <<= 1;
|
||||
}
|
||||
|
@ -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 MAX_BIT_PER_BLOCK 16
|
||||
#define CMDMODE 0x0000
|
||||
@ -64,7 +64,7 @@ class MY9221 {
|
||||
*
|
||||
* @param level selected level for the bar (1 - 10)
|
||||
*/
|
||||
maa_result_t setBarLevel (uint8_t level);
|
||||
mraa_result_t setBarLevel (uint8_t level);
|
||||
|
||||
/**
|
||||
* Return name of the component
|
||||
@ -74,12 +74,12 @@ class MY9221 {
|
||||
return m_name;
|
||||
}
|
||||
private:
|
||||
maa_result_t lockData ();
|
||||
maa_result_t send16bitBlock (short data);
|
||||
mraa_result_t lockData ();
|
||||
mraa_result_t send16bitBlock (short data);
|
||||
|
||||
std::string m_name;
|
||||
maa_gpio_context m_clkPinCtx;
|
||||
maa_gpio_context m_dataPinCtx;
|
||||
mraa_gpio_context m_clkPinCtx;
|
||||
mraa_gpio_context m_dataPinCtx;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -31,58 +31,58 @@
|
||||
using namespace upm;
|
||||
|
||||
NRF24l01::NRF24l01 (uint8_t cs) {
|
||||
maa_init();
|
||||
mraa_init();
|
||||
nrfInitModule (cs, 8);
|
||||
}
|
||||
|
||||
NRF24l01::~NRF24l01 () {
|
||||
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_cePinCtx);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print(error);
|
||||
error = mraa_gpio_close (m_cePinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
error = maa_gpio_close (m_csnPinCtx);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print(error);
|
||||
error = mraa_gpio_close (m_csnPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NRF24l01::nrfInitModule (uint8_t chip_select, uint8_t chip_enable) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
m_csn = chip_select;
|
||||
m_ce = chip_enable;
|
||||
m_channel = 1;
|
||||
|
||||
m_csnPinCtx = maa_gpio_init (m_csn);
|
||||
m_csnPinCtx = mraa_gpio_init (m_csn);
|
||||
if (m_csnPinCtx == NULL) {
|
||||
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_csn);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
m_cePinCtx = maa_gpio_init (m_ce);
|
||||
m_cePinCtx = mraa_gpio_init (m_ce);
|
||||
if (m_cePinCtx == NULL) {
|
||||
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_ce);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
error = maa_gpio_dir (m_csnPinCtx, MAA_GPIO_OUT);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print (error);
|
||||
error = mraa_gpio_dir (m_csnPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
}
|
||||
|
||||
error = maa_gpio_dir (m_cePinCtx, MAA_GPIO_OUT);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print (error);
|
||||
error = mraa_gpio_dir (m_cePinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
}
|
||||
|
||||
nrfCELow ();
|
||||
m_spi = maa_spi_init (0);
|
||||
m_spi = mraa_spi_init (0);
|
||||
}
|
||||
|
||||
void
|
||||
@ -105,8 +105,8 @@ NRF24l01::nrfConfigModule() {
|
||||
void
|
||||
NRF24l01::nrfConfigRegister(uint8_t reg, uint8_t value) {
|
||||
nrfCSOn ();
|
||||
maa_spi_write (m_spi, W_REGISTER | (REGISTER_MASK & reg));
|
||||
maa_spi_write (m_spi, value);
|
||||
mraa_spi_write (m_spi, W_REGISTER | (REGISTER_MASK & reg));
|
||||
mraa_spi_write (m_spi, value);
|
||||
nrfCSOff ();
|
||||
}
|
||||
|
||||
@ -122,7 +122,7 @@ NRF24l01::nrfPowerUpRX() {
|
||||
void
|
||||
NRF24l01::nrfFlushRX() {
|
||||
nrfCSOn ();
|
||||
maa_spi_write (m_spi, FLUSH_RX);
|
||||
mraa_spi_write (m_spi, FLUSH_RX);
|
||||
nrfCSOff ();
|
||||
}
|
||||
|
||||
@ -160,7 +160,7 @@ void
|
||||
NRF24l01::nrfWriteRegister(uint8_t reg, uint8_t * value, uint8_t len)
|
||||
{
|
||||
nrfCSOn ();
|
||||
maa_spi_write (m_spi, W_REGISTER | (REGISTER_MASK & reg));
|
||||
mraa_spi_write (m_spi, W_REGISTER | (REGISTER_MASK & reg));
|
||||
nrfTransmitSync(value, len);
|
||||
nrfCSOff ();
|
||||
}
|
||||
@ -169,7 +169,7 @@ void
|
||||
NRF24l01::nrfTransmitSync(uint8_t *dataout, uint8_t len){
|
||||
uint8_t i;
|
||||
for(i = 0; i < len; i++) {
|
||||
maa_spi_write (m_spi, dataout[i]);
|
||||
mraa_spi_write (m_spi, dataout[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ void
|
||||
NRF24l01::nrfReadRegister (uint8_t reg, uint8_t * value, uint8_t len)
|
||||
{
|
||||
nrfCSOn ();
|
||||
maa_spi_write (m_spi, R_REGISTER | (REGISTER_MASK & reg));
|
||||
mraa_spi_write (m_spi, R_REGISTER | (REGISTER_MASK & reg));
|
||||
nrfTransferSync (value, value, len);
|
||||
nrfCSOff ();
|
||||
}
|
||||
@ -205,7 +205,7 @@ void
|
||||
NRF24l01::nrfTransferSync (uint8_t *dataout,uint8_t *datain,uint8_t len) {
|
||||
uint8_t i;
|
||||
for(i = 0;i < len;i++) {
|
||||
datain[i] = maa_spi_write (m_spi, dataout[i]);
|
||||
datain[i] = mraa_spi_write (m_spi, dataout[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,7 +222,7 @@ NRF24l01::nrfGetData (uint8_t * data)
|
||||
{
|
||||
nrfCSOn ();
|
||||
/* Send cmd to read rx payload */
|
||||
maa_spi_write (m_spi, R_RX_PAYLOAD);
|
||||
mraa_spi_write (m_spi, R_RX_PAYLOAD);
|
||||
/* Read payload */
|
||||
nrfTransferSync(data, data, m_payload);
|
||||
nrfCSOff ();
|
||||
@ -248,11 +248,11 @@ NRF24l01::nrfSend(uint8_t * value) {
|
||||
nrfCELow();
|
||||
nrfPowerUpTX(); // Set to transmitter mode , Power up
|
||||
nrfCSOn ();
|
||||
maa_spi_write (m_spi, FLUSH_TX); // Write cmd to flush tx fifo
|
||||
mraa_spi_write (m_spi, FLUSH_TX); // Write cmd to flush tx fifo
|
||||
nrfCSOff ();
|
||||
|
||||
nrfCSOn ();
|
||||
maa_spi_write (m_spi, W_TX_PAYLOAD); // Write cmd to write payload
|
||||
mraa_spi_write (m_spi, W_TX_PAYLOAD); // Write cmd to write payload
|
||||
nrfTransmitSync(value, m_payload); // Write payload
|
||||
nrfCSOff ();
|
||||
nrfCEHigh(); // Start transmission
|
||||
@ -290,24 +290,24 @@ NRF24l01::nrfPowerDown () {
|
||||
nrfConfigRegister (CONFIG, NRF_CONFIG);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
NRF24l01::nrfCEHigh () {
|
||||
return maa_gpio_write (m_cePinCtx, HIGH);
|
||||
return mraa_gpio_write (m_cePinCtx, HIGH);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
NRF24l01::nrfCELow () {
|
||||
return maa_gpio_write (m_cePinCtx, LOW);
|
||||
return mraa_gpio_write (m_cePinCtx, LOW);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
NRF24l01::nrfCSOn () {
|
||||
return maa_gpio_write (m_csnPinCtx, LOW);
|
||||
return mraa_gpio_write (m_csnPinCtx, LOW);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
NRF24l01::nrfCSOff () {
|
||||
return maa_gpio_write (m_csnPinCtx, HIGH);
|
||||
return mraa_gpio_write (m_csnPinCtx, HIGH);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -24,9 +24,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>
|
||||
|
||||
/* Memory Map */
|
||||
#define CONFIG 0x00
|
||||
@ -297,22 +297,22 @@ class NRF24l01 {
|
||||
/**
|
||||
* Set chip enable pin HIGH
|
||||
*/
|
||||
maa_result_t nrfCEHigh ();
|
||||
mraa_result_t nrfCEHigh ();
|
||||
|
||||
/**
|
||||
* Set chip enable LOW
|
||||
*/
|
||||
maa_result_t nrfCELow ();
|
||||
mraa_result_t nrfCELow ();
|
||||
|
||||
/**
|
||||
* Set chip select pin LOW
|
||||
*/
|
||||
maa_result_t nrfCSOn ();
|
||||
mraa_result_t nrfCSOn ();
|
||||
|
||||
/**
|
||||
* Set chip select pin HIGH
|
||||
*/
|
||||
maa_result_t nrfCSOff ();
|
||||
mraa_result_t nrfCSOff ();
|
||||
|
||||
/**
|
||||
* Flush reciver stack
|
||||
@ -330,7 +330,7 @@ class NRF24l01 {
|
||||
|
||||
funcPtrVoidVoid dataRecievedHandler; /**< Data arrived handler */
|
||||
private:
|
||||
maa_spi_context m_spi;
|
||||
mraa_spi_context m_spi;
|
||||
uint8_t m_ce;
|
||||
uint8_t m_csn;
|
||||
uint8_t m_channel;
|
||||
@ -338,8 +338,8 @@ class NRF24l01 {
|
||||
uint8_t m_payload;
|
||||
uint8_t m_localAddress[5];
|
||||
|
||||
maa_gpio_context m_csnPinCtx;
|
||||
maa_gpio_context m_cePinCtx;
|
||||
mraa_gpio_context m_csnPinCtx;
|
||||
mraa_gpio_context m_cePinCtx;
|
||||
|
||||
std::string m_name;
|
||||
};
|
||||
|
@ -29,7 +29,7 @@
|
||||
void init_pulsensor (pulsensor_context * ctx, callback_handler handler) {
|
||||
ctx->callback = handler;
|
||||
|
||||
ctx->pin_ctx = maa_aio_init(0);
|
||||
ctx->pin_ctx = mraa_aio_init(0);
|
||||
|
||||
ctx->sample_counter = 0;
|
||||
ctx->last_beat_time = 0;
|
||||
@ -63,8 +63,8 @@ void * do_sample (void * arg) {
|
||||
clbk_data callback_data;
|
||||
while (ctx_counter) {
|
||||
pulsensor_context * ctx = (pulsensor_context *) arg;
|
||||
maa_aio_context pin = ctx->pin_ctx;
|
||||
data_from_sensor = maa_aio_read (pin);
|
||||
mraa_aio_context pin = ctx->pin_ctx;
|
||||
data_from_sensor = mraa_aio_read (pin);
|
||||
ctx->ret = FALSE;
|
||||
|
||||
ctx->sample_counter += 2;
|
||||
|
@ -28,9 +28,9 @@
|
||||
|
||||
#include <string>
|
||||
#include <math.h>
|
||||
#include <maa/pwm.h>
|
||||
#include <maa/aio.h>
|
||||
#include <maa/gpio.h>
|
||||
#include <mraa/pwm.h>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#define HIGH 1
|
||||
@ -62,7 +62,7 @@ struct pulsensor_context {
|
||||
uint8_t second_beat;
|
||||
uint8_t pin;
|
||||
uint8_t ret;
|
||||
maa_aio_context pin_ctx;
|
||||
mraa_aio_context pin_ctx;
|
||||
|
||||
callback_handler callback;
|
||||
};
|
||||
|
@ -32,7 +32,7 @@
|
||||
using namespace upm;
|
||||
|
||||
Servo::Servo (int pin) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
m_minPulseWidth = MIN_PULSE_WIDTH;
|
||||
m_maxPulseWidth = MAX_PULSE_WIDTH;
|
||||
@ -40,7 +40,7 @@ Servo::Servo (int pin) {
|
||||
|
||||
m_maxAngle = 180.0;
|
||||
m_servoPin = pin;
|
||||
m_pwmServoContext = maa_pwm_init (m_servoPin);
|
||||
m_pwmServoContext = mraa_pwm_init (m_servoPin);
|
||||
|
||||
m_currAngle = 180;
|
||||
|
||||
@ -48,7 +48,7 @@ Servo::Servo (int pin) {
|
||||
}
|
||||
|
||||
Servo::~Servo () {
|
||||
maa_pwm_close (m_pwmServoContext);
|
||||
mraa_pwm_close (m_pwmServoContext);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -62,14 +62,14 @@ Servo::~Servo () {
|
||||
* Max period can be only 7968750(nses) which is ~8(msec)
|
||||
* so the servo wil not work as expected.
|
||||
* */
|
||||
maa_result_t Servo::setAngle (int angle) {
|
||||
mraa_result_t Servo::setAngle (int angle) {
|
||||
if (m_pwmServoContext == NULL) {
|
||||
std::cout << "PWM context is NULL" << std::endl;
|
||||
return MAA_ERROR_UNSPECIFIED;
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
if (angle > m_maxAngle || angle < 0) {
|
||||
return MAA_ERROR_UNSPECIFIED;
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
int period = (m_maxPulseWidth - m_minPulseWidth) / m_maxAngle;
|
||||
@ -78,12 +78,12 @@ maa_result_t Servo::setAngle (int angle) {
|
||||
|
||||
// int cycles = (int)(100.0 * ((float)angle / (float)m_maxAngle));
|
||||
|
||||
maa_pwm_enable (m_pwmServoContext, 1);
|
||||
mraa_pwm_enable (m_pwmServoContext, 1);
|
||||
for (int cycle = 0; cycle < cycles; cycle++) {
|
||||
maa_pwm_period_us (m_pwmServoContext, m_maxPeriod);
|
||||
maa_pwm_pulsewidth_us (m_pwmServoContext, calcPulseTraveling(angle));
|
||||
mraa_pwm_period_us (m_pwmServoContext, m_maxPeriod);
|
||||
mraa_pwm_pulsewidth_us (m_pwmServoContext, calcPulseTraveling(angle));
|
||||
}
|
||||
maa_pwm_enable (m_pwmServoContext, 0);
|
||||
mraa_pwm_enable (m_pwmServoContext, 0);
|
||||
|
||||
std::cout << "angle = " << angle << " ,pulse = " << calcPulseTraveling(angle) << ", cycles " << cycles << std::endl;
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/pwm.h>
|
||||
#include <mraa/pwm.h>
|
||||
|
||||
namespace upm {
|
||||
|
||||
@ -70,7 +70,7 @@ class Servo {
|
||||
*
|
||||
* @param angle number between 0 and 180
|
||||
*/
|
||||
maa_result_t setAngle (int angle);
|
||||
mraa_result_t setAngle (int angle);
|
||||
|
||||
/**
|
||||
* Return name of the component
|
||||
@ -122,7 +122,7 @@ class Servo {
|
||||
std::string m_name;
|
||||
int m_servoPin;
|
||||
float m_maxAngle;
|
||||
maa_pwm_context m_pwmServoContext;
|
||||
mraa_pwm_context m_pwmServoContext;
|
||||
int m_currAngle;
|
||||
|
||||
int m_minPulseWidth;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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];
|
||||
|
||||
|
@ -31,35 +31,35 @@
|
||||
using namespace upm;
|
||||
|
||||
StepMotor::StepMotor (int dirPin, int stePin) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
m_name = "StepMotor";
|
||||
|
||||
maa_init();
|
||||
mraa_init();
|
||||
|
||||
m_stePin = stePin;
|
||||
m_dirPin = dirPin;
|
||||
|
||||
m_pwmStepContext = maa_pwm_init (m_stePin);
|
||||
m_dirPinCtx = maa_gpio_init (m_dirPin);
|
||||
m_pwmStepContext = mraa_pwm_init (m_stePin);
|
||||
m_dirPinCtx = mraa_gpio_init (m_dirPin);
|
||||
if (m_dirPinCtx == NULL) {
|
||||
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_dirPin);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
error = maa_gpio_dir (m_dirPinCtx, MAA_GPIO_OUT);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print (error);
|
||||
error = mraa_gpio_dir (m_dirPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
}
|
||||
}
|
||||
|
||||
StepMotor::~StepMotor() {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
maa_pwm_close (m_pwmStepContext);
|
||||
mraa_pwm_close (m_pwmStepContext);
|
||||
|
||||
error = maa_gpio_close (m_dirPinCtx);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print(error);
|
||||
error = mraa_gpio_close (m_dirPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,51 +76,51 @@ StepMotor::setSpeed (int speed) {
|
||||
m_speed = speed;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
StepMotor::stepForward (int ticks) {
|
||||
dirForward ();
|
||||
move (ticks);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
StepMotor::stepBackwards (int ticks) {
|
||||
dirBackwards ();
|
||||
move (ticks);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
StepMotor::move (int ticks) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
maa_pwm_enable (m_pwmStepContext, 1);
|
||||
mraa_pwm_enable (m_pwmStepContext, 1);
|
||||
for (int tick = 0; tick < ticks; tick++) {
|
||||
maa_pwm_period_us (m_pwmStepContext, m_speed);
|
||||
maa_pwm_pulsewidth_us (m_pwmStepContext, PULSEWIDTH);
|
||||
mraa_pwm_period_us (m_pwmStepContext, m_speed);
|
||||
mraa_pwm_pulsewidth_us (m_pwmStepContext, PULSEWIDTH);
|
||||
}
|
||||
maa_pwm_enable (m_pwmStepContext, 0);
|
||||
mraa_pwm_enable (m_pwmStepContext, 0);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
StepMotor::dirForward () {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
error = maa_gpio_write (m_dirPinCtx, HIGH);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print (error);
|
||||
error = mraa_gpio_write (m_dirPinCtx, HIGH);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
StepMotor::dirBackwards () {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
error = maa_gpio_write (m_dirPinCtx, LOW);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print (error);
|
||||
error = mraa_gpio_write (m_dirPinCtx, LOW);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
}
|
||||
|
||||
return error;
|
||||
|
@ -28,9 +28,9 @@
|
||||
|
||||
#include <string>
|
||||
#include <math.h>
|
||||
#include <maa/pwm.h>
|
||||
#include <maa/aio.h>
|
||||
#include <maa/gpio.h>
|
||||
#include <mraa/pwm.h>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
|
||||
#define MIN_PERIOD 500
|
||||
#define MAX_PERIOD 1000
|
||||
@ -75,14 +75,14 @@ class StepMotor {
|
||||
*
|
||||
* @param ticks number of tickes the motor will move
|
||||
*/
|
||||
maa_result_t stepForward (int ticks);
|
||||
mraa_result_t stepForward (int ticks);
|
||||
|
||||
/**
|
||||
* Rotate motor backward
|
||||
*
|
||||
* @param ticks number of tickes the motor will move
|
||||
*/
|
||||
maa_result_t stepBackwards (int ticks);
|
||||
mraa_result_t stepBackwards (int ticks);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
@ -91,11 +91,11 @@ class StepMotor {
|
||||
int m_stePin;
|
||||
int m_speed;
|
||||
|
||||
maa_gpio_context m_dirPinCtx;
|
||||
maa_pwm_context m_pwmStepContext;
|
||||
mraa_gpio_context m_dirPinCtx;
|
||||
mraa_pwm_context m_pwmStepContext;
|
||||
|
||||
maa_result_t move (int ticks);
|
||||
maa_result_t dirForward ();
|
||||
maa_result_t dirBackwards ();
|
||||
mraa_result_t move (int ticks);
|
||||
mraa_result_t dirForward ();
|
||||
mraa_result_t dirBackwards ();
|
||||
};
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user