mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 01:11:10 +03:00
java: changed some C types to C++ types
Signed-off-by: Andrei Vasiliu <andrei.vasiliu@intel.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com> Conflicts: src/mma7455/mma7455.cxx src/mma7455/mma7455.h src/sm130/sm130.cxx src/sm130/sm130.h
This commit is contained in:

committed by
Mihai Tudor Panu

parent
b8835958e2
commit
ab730038fd
@ -31,49 +31,23 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
MAX5487::MAX5487 (int csn) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
MAX5487::MAX5487 (int csn) : m_csnPinCtx(csn), m_spi(0) {
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
m_name = "MAX5487";
|
||||
|
||||
m_csnPinCtx = NULL;
|
||||
if (csn != -1) {
|
||||
m_csnPinCtx = mraa_gpio_init (csn);
|
||||
if (m_csnPinCtx == NULL) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_gpio_init() failed");
|
||||
}
|
||||
|
||||
error = mraa_gpio_dir (m_csnPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_gpio_dir() failed");
|
||||
}
|
||||
if (csn == -1) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__));
|
||||
}
|
||||
|
||||
m_spi = mraa_spi_init (0);
|
||||
if (m_spi == NULL) {
|
||||
error = m_csnPinCtx.dir (mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_spi_init() failed");
|
||||
": mraa_gpio_dir() failed");
|
||||
}
|
||||
|
||||
CSOff ();
|
||||
}
|
||||
|
||||
MAX5487::~MAX5487() {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
error = mraa_spi_stop(m_spi);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
if (m_csnPinCtx != NULL) {
|
||||
error = mraa_gpio_close (m_csnPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MAX5487::setWiperA (uint8_t wiper) {
|
||||
uint8_t data[2] = { 0x00, 0x00};
|
||||
@ -83,7 +57,7 @@ MAX5487::setWiperA (uint8_t wiper) {
|
||||
data[0] = R_WR_WIPER_A;
|
||||
data[1] = wiper;
|
||||
|
||||
uint8_t* retData = mraa_spi_write_buf(m_spi, data, 2);
|
||||
uint8_t* retData = m_spi.write(data, 2);
|
||||
|
||||
CSOff ();
|
||||
}
|
||||
@ -97,7 +71,7 @@ MAX5487::setWiperB (uint8_t wiper) {
|
||||
data[0] = R_WR_WIPER_B;
|
||||
data[1] = wiper;
|
||||
|
||||
uint8_t* retData = mraa_spi_write_buf(m_spi, data, 2);
|
||||
uint8_t* retData = m_spi.write(data, 2);
|
||||
|
||||
CSOff ();
|
||||
}
|
||||
@ -108,16 +82,12 @@ MAX5487::setWiperB (uint8_t wiper) {
|
||||
* **************
|
||||
*/
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
MAX5487::CSOn () {
|
||||
if (m_csnPinCtx != NULL)
|
||||
return mraa_gpio_write (m_csnPinCtx, LOW);
|
||||
return MRAA_SUCCESS;
|
||||
return m_csnPinCtx.write(LOW);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
MAX5487::CSOff () {
|
||||
if (m_csnPinCtx != NULL)
|
||||
return mraa_gpio_write (m_csnPinCtx, HIGH);
|
||||
return MRAA_SUCCESS;
|
||||
return m_csnPinCtx.write(HIGH);
|
||||
}
|
||||
|
@ -24,9 +24,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <mraa/spi.h>
|
||||
#include <mraa/aio.hpp>
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
#undef SWIGJAVA
|
||||
#include <mraa/gpio.hpp>
|
||||
#define SWIGJAVA
|
||||
|
||||
#else
|
||||
#include <mraa/gpio.hpp>
|
||||
#endif
|
||||
|
||||
#include <mraa/spi.hpp>
|
||||
|
||||
#define HIGH 1
|
||||
#define LOW 0
|
||||
@ -71,8 +80,10 @@ class MAX5487 {
|
||||
|
||||
/**
|
||||
* MAX5487 object destructor, closes all IO connections
|
||||
*/
|
||||
~MAX5487 ();
|
||||
* no more needed as the connections will be closed when
|
||||
* m_spi and m_csnPinCtx will go out of scope
|
||||
* ~MAX5487 ();
|
||||
**/
|
||||
|
||||
/**
|
||||
* Sets a wiper for port A.
|
||||
@ -93,18 +104,18 @@ class MAX5487 {
|
||||
}
|
||||
private:
|
||||
std::string m_name;
|
||||
mraa_spi_context m_spi;
|
||||
mraa_gpio_context m_csnPinCtx;
|
||||
mraa::Spi m_spi;
|
||||
mraa::Gpio m_csnPinCtx;
|
||||
|
||||
/**
|
||||
* Sets the chip select pin to LOW
|
||||
*/
|
||||
mraa_result_t CSOn ();
|
||||
mraa::Result CSOn ();
|
||||
|
||||
/**
|
||||
* Sets the chip select pin to HIGH
|
||||
*/
|
||||
mraa_result_t CSOff ();
|
||||
mraa::Result CSOff ();
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user