mirror of
https://github.com/eclipse/upm.git
synced 2025-07-02 01:41:12 +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,31 +31,23 @@ using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
|
||||
MPR121::MPR121(int bus, uint8_t address)
|
||||
MPR121::MPR121(int bus, uint8_t address) : m_i2c(bus)
|
||||
{
|
||||
// setup our i2c link
|
||||
m_i2c = mraa_i2c_init(bus);
|
||||
|
||||
m_addr = address;
|
||||
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2c, m_addr);
|
||||
mraa::Result ret = m_i2c.address(m_addr);
|
||||
|
||||
if (ret != MRAA_SUCCESS)
|
||||
if (ret != mraa::SUCCESS)
|
||||
cerr << "MPR121: Could not initialize i2c bus. " << endl;
|
||||
|
||||
m_buttonStates = 0;
|
||||
m_overCurrentFault = false;
|
||||
}
|
||||
|
||||
MPR121::~MPR121()
|
||||
{
|
||||
mraa_i2c_stop(m_i2c);
|
||||
}
|
||||
|
||||
mraa_result_t MPR121::writeBytes(uint8_t reg, uint8_t *buffer, unsigned int len)
|
||||
mraa::Result MPR121::writeBytes(uint8_t reg, uint8_t *buffer, unsigned int len)
|
||||
{
|
||||
if (!len || !buffer)
|
||||
return MRAA_SUCCESS;
|
||||
return mraa::SUCCESS;
|
||||
|
||||
// create a buffer 1 byte larger than the supplied buffer,
|
||||
// store the register in the first byte
|
||||
@ -67,9 +59,9 @@ mraa_result_t MPR121::writeBytes(uint8_t reg, uint8_t *buffer, unsigned int len)
|
||||
for (int i=1; i<(len + 1); i++)
|
||||
buf2[i] = buffer[i-1];
|
||||
|
||||
mraa_i2c_address(m_i2c, m_addr);
|
||||
m_i2c.address(m_addr);
|
||||
|
||||
return mraa_i2c_write(m_i2c, buf2, len + 1);
|
||||
return m_i2c.write(buf2, len + 1);
|
||||
}
|
||||
|
||||
void MPR121::readBytes(uint8_t reg, uint8_t *buffer, unsigned int len)
|
||||
@ -77,10 +69,10 @@ void MPR121::readBytes(uint8_t reg, uint8_t *buffer, unsigned int len)
|
||||
if (!len || !buffer)
|
||||
return;
|
||||
|
||||
// The usual mraa_i2c_read() does not work here, so we need to
|
||||
// The usual m_i2c.read() does not work here, so we need to
|
||||
// read each byte individually.
|
||||
for (int i=0; i<len; i++)
|
||||
buffer[i] = mraa_i2c_read_byte_data(m_i2c, reg + i);
|
||||
buffer[i] = m_i2c.readReg(reg + i);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -90,13 +82,13 @@ bool MPR121::configAN3944()
|
||||
// Configure the mpr121 chip as recommended in the AN3944 MPR121
|
||||
// Quick Start Guide
|
||||
|
||||
mraa_result_t rv;
|
||||
mraa::Result rv;
|
||||
|
||||
// First, turn off all electrodes by zeroing out the Electrode Configuration
|
||||
// register.
|
||||
// If this one fails, it's unlikely any of the others will succeed.
|
||||
uint8_t eleConf = 0x00;
|
||||
if ((rv = writeBytes(0x5e, &eleConf, 1)) != MRAA_SUCCESS)
|
||||
if ((rv = writeBytes(0x5e, &eleConf, 1)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": " << __LINE__<< ": I2C write failed." << endl;
|
||||
return false;
|
||||
@ -106,7 +98,7 @@ bool MPR121::configAN3944()
|
||||
// Filtering when data is greater than baseline
|
||||
// regs 0x2b-0x2e
|
||||
uint8_t sectA[] = { 0x01, 0x01, 0x00, 0x00 };
|
||||
if ((rv = writeBytes(0x2b, sectA, 4)) != MRAA_SUCCESS)
|
||||
if ((rv = writeBytes(0x2b, sectA, 4)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": " << __LINE__<< ": I2C write failed." << endl;
|
||||
return false;
|
||||
@ -116,7 +108,7 @@ bool MPR121::configAN3944()
|
||||
// Filtering when data is less than baseline
|
||||
// regs 0x2f-0x32
|
||||
uint8_t sectB[] = { 0x01, 0x01, 0xff, 0x02 };
|
||||
if ((rv = writeBytes(0x2f, sectB, 4)) != MRAA_SUCCESS)
|
||||
if ((rv = writeBytes(0x2f, sectB, 4)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": " << __LINE__<< ": I2C write failed." << endl;
|
||||
return false;
|
||||
@ -126,7 +118,7 @@ bool MPR121::configAN3944()
|
||||
// Touch Threshold/Release registers, ELE0-ELE11
|
||||
// regs 0x41-0x58
|
||||
// __T_ __R_
|
||||
uint8_t sectC[] = { 0x0f, 0x0a,
|
||||
uint8_t sectC[] = { 0x0f, 0x0a,
|
||||
0x0f, 0x0a,
|
||||
0x0f, 0x0a,
|
||||
0x0f, 0x0a,
|
||||
@ -138,7 +130,7 @@ bool MPR121::configAN3944()
|
||||
0x0f, 0x0a,
|
||||
0x0f, 0x0a,
|
||||
0x0f, 0x0a };
|
||||
if ((rv = writeBytes(0x41, sectC, 24)) != MRAA_SUCCESS)
|
||||
if ((rv = writeBytes(0x41, sectC, 24)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": " << __LINE__<< ": I2C write failed." << endl;
|
||||
return false;
|
||||
@ -148,7 +140,7 @@ bool MPR121::configAN3944()
|
||||
// Filter configuration
|
||||
// reg 0x5d
|
||||
uint8_t filterConf = 0x04;
|
||||
if ((rv = writeBytes(0x5d, &filterConf, 1)) != MRAA_SUCCESS)
|
||||
if ((rv = writeBytes(0x5d, &filterConf, 1)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": " << __LINE__<< ": I2C write failed." << endl;
|
||||
return false;
|
||||
@ -158,13 +150,13 @@ bool MPR121::configAN3944()
|
||||
// Autoconfiguration registers
|
||||
// regs 0x7b-0x7f
|
||||
uint8_t sectF0 = 0x0b;
|
||||
if ((rv = writeBytes(0x7b, §F0, 1)) != MRAA_SUCCESS)
|
||||
if ((rv = writeBytes(0x7b, §F0, 1)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": " << __LINE__<< ": I2C write failed." << endl;
|
||||
return false;
|
||||
}
|
||||
uint8_t sectF1[] = { 0x9c, 0x65, 0x8c };
|
||||
if ((rv = writeBytes(0x7d, sectF1, 3)) != MRAA_SUCCESS)
|
||||
if ((rv = writeBytes(0x7d, sectF1, 3)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": " << __LINE__<< ": I2C write failed." << endl;
|
||||
return false;
|
||||
@ -175,7 +167,7 @@ bool MPR121::configAN3944()
|
||||
// excessive calibration delay on startup.
|
||||
// reg 0x5e
|
||||
eleConf = 0x8c;
|
||||
if ((rv = writeBytes(0x5e, &eleConf, 1)) != MRAA_SUCCESS)
|
||||
if ((rv = writeBytes(0x5e, &eleConf, 1)) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << __FUNCTION__ << ": " << __LINE__<< ": I2C write failed." << endl;
|
||||
return false;
|
||||
|
@ -24,7 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/i2c.hpp>
|
||||
|
||||
#define MPR121_I2C_BUS 0
|
||||
#define MPR121_DEFAULT_I2C_ADDR 0x5a
|
||||
@ -64,8 +64,9 @@ namespace upm {
|
||||
|
||||
/**
|
||||
* MPR121 destructor
|
||||
*/
|
||||
~MPR121();
|
||||
* ~MPR121();
|
||||
* there is no need for the destructor
|
||||
**/
|
||||
|
||||
/**
|
||||
* Sets up a default configuration, based on Application Note 3944
|
||||
@ -90,9 +91,9 @@ namespace upm {
|
||||
* @param reg Register location to start writing into
|
||||
* @param buffer Buffer for data storage
|
||||
* @param len Number of bytes to write
|
||||
* @return mraa_result_t
|
||||
* @return mraa::Result
|
||||
*/
|
||||
mraa_result_t writeBytes(uint8_t reg, uint8_t *buffer, unsigned int len);
|
||||
mraa::Result writeBytes(uint8_t reg, uint8_t *buffer, unsigned int len);
|
||||
|
||||
/**
|
||||
* Reads value(s) from registers
|
||||
@ -114,7 +115,7 @@ namespace upm {
|
||||
bool m_overCurrentFault;
|
||||
|
||||
private:
|
||||
mraa_i2c_context m_i2c;
|
||||
mraa::I2c m_i2c;
|
||||
uint8_t m_addr;
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user