Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added EAPI/Dmo/x86/EApi_1.dll
Binary file not shown.
Binary file added EAPI/Dmo/x86/EApi_1.lib
Binary file not shown.
Binary file added EAPI/Dmo/x86_64/EApi_1.dll
Binary file not shown.
Binary file added EAPI/Dmo/x86_64/EApi_1.lib
Binary file not shown.
59 changes: 59 additions & 0 deletions EApiOsNTC.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
*<KHeader>
*+=========================================================================
*I Project Name: EApiDK Embedded Application Development Kit
*+=========================================================================
*I $HeadURL: https://eapidk.svn.sourceforge.net/svnroot/eapidk/trunk/lib/WINNT/EApiOsNTC.c $
*+=========================================================================
*I Copyright: Copyright (c) 2002-2009, Kontron Embedded Modules GmbH
*I Author: John Kearney, John.Kearney@kontron.com
*I
*I License: All rights reserved. This program and the accompanying
*I materials are licensed and made available under the
*I terms and conditions of the BSD License which
*I accompanies this distribution. The full text of the
*I license may be found at
*I http://opensource.org/licenses/bsd-license.php
*I
*I THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "
*I AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF
*I ANY KIND, EITHER EXPRESS OR IMPLIED.
*I
*I Description: Auto Created for EApiOsNTC.c
*I
*+-------------------------------------------------------------------------
*I
*I File Name : EApiOsNTC.c
*I File Location : lib\WINNT
*I Last committed : $Revision: 38 $
*I Last changed by : $Author: dethrophes $
*I Last changed date : $Date: 2010-01-26 07:48:22 +0100 (Di, 26. Jan 2010) $
*I ID : $Id: EApiOsNTC.c 38 2010-01-26 06:48:22Z dethrophes $
*I
*+=========================================================================
*</KHeader>
*/
#include <EApiOsNTC.h>
#include <Windows.h>

#ifdef __cplusplus
extern "C"
{
#endif

void usleep(unsigned long us)
{
LARGE_INTEGER cnt1;
LARGE_INTEGER cnt2;
QueryPerformanceCounter (&cnt1);
QueryPerformanceFrequency (&cnt2);
cnt1.QuadPart+=(us*cnt2.QuadPart)/1000000;
do{
QueryPerformanceCounter (&cnt2);
}while(cnt1.QuadPart>cnt2.QuadPart);
return ;
}

#ifdef __cplusplus
}
#endif
2 changes: 1 addition & 1 deletion gpio.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#include "gpio.h"
#include <unistd.h>

#include <EApi.h>

const EApiId_t EApiGpioDevices[]={
Expand Down
6 changes: 6 additions & 0 deletions gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
#include <QPushButton>
#include <QTimer>

#ifdef _MSC_VER
#include <stdint.h>
#else
#include <unistd.h>
#endif

class gpio: public QWidget
{
Q_OBJECT
Expand Down
20 changes: 20 additions & 0 deletions gui-demo.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ SOURCES += main.cpp\
temperatureBar.cpp \
pwm.cpp

win32: SOURCES += EApiOsNTC.c

HEADERS += mainwindow.h \
boardinfo.h \
realtimeinfo.h \
Expand All @@ -42,6 +44,24 @@ equals(LIBPATH, "") {
}
unix:!macx: LIBS += -L$$LIBPATH -lEApi

# Windows, tested w/ MSVC compilers
win32: {
TARGET_ARCH = $$QMAKE_TARGET.arch
DESTDIR = $$PWD/Bin/$$TARGET_ARCH/
TARGET = $$TARGET-$$TARGET_ARCH
EAPI = EAPI/Dmo
LIBS += -L$$PWD/$${EAPI}/$$TARGET_ARCH/ -lEApi_1
DEPLOY_COMMAND = windeployqt
DEPLOY_TARGET = $$shell_quote($$shell_path($${DESTDIR}))
EAPI_DLL = $$PWD/$${EAPI}/$$TARGET_ARCH/EApi_1.dll
CP_EAPI = $$QMAKE_COPY $$shell_quote($$shell_path($${EAPI_DLL})) $$shell_quote($$shell_path($${DESTDIR})) $$escape_expand(\\n\\t)
QMAKE_POST_LINK = $${CP_EAPI}
QMAKE_POST_LINK += $${DEPLOY_COMMAND} $${DEPLOY_TARGET}

INCLUDEPATH += $$PWD/include/WinNt
DEPENDPATH += $$PWD/include/WinNt
}

INCLUDEPATH += $$PWD/include
DEPENDPATH += $$PWD/include

Expand Down
107 changes: 74 additions & 33 deletions i2c.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "i2c.h"
#ifndef _MSC_VER
#include <dirent.h>
#endif
#include <fcntl.h>
#include <qdebug.h>
#include <EApi.h>
#include <unistd.h>

#include <QPainter>


Expand All @@ -24,12 +26,6 @@ i2c::i2c(QWidget *parent)

timer = new QTimer(this);

int tempresult = find_eeprom();
if (tempresult == -1 )
base_addr = 0;
else
base_addr = tempresult;

readWriteByteRadioButton = new QRadioButton("Read/Write Register");
readWriteByteRadioButton->setFont(fontvalue);

Expand All @@ -55,29 +51,23 @@ i2c::i2c(QWidget *parent)
protocolGroup->setFont(fontlabel);
protocolGroup->setLayout(protocolLayout);

if (base_addr == 0) /* no i2c*/
protocolGroup->setEnabled(false);
/*************************************************/

i2cIDLabel = new QLabel("I2C Select:");
i2cIDLabel->setFont(fontvalue);

i2cID = new QComboBox;
i2cID->setFont(fontvalue);

if (base_addr == 0) /* no i2c*/

base_addr = uint32_t(add_i2c_busses(i2cID));
if (base_addr == uint32_t(-1))
protocolGroup->setEnabled(false);
if (base_addr == uint32_t(-1)) /* no i2c*/
{
i2cIDLabel->setStyleSheet("color : red");
i2cID->addItem("-");
}
else
{
i2cID->addItem(QString::number(base_addr));
i2cID->addItem(QString::number(base_addr+1));
i2cID->addItem(QString::number(base_addr+2));
}

i2cBus = base_addr;
connect(i2cID , SIGNAL(currentIndexChanged(int)),this,SLOT(handleI2CselectionChanged(int)));

slaveLabel = new QLabel("Slave Address(Hex, ex. A5):");
Expand Down Expand Up @@ -105,7 +95,7 @@ i2c::i2c(QWidget *parent)
deviceGroup->setFont(fontlabel);
deviceGroup->setLayout(deviceLayout);

if (base_addr == 0) /* no i2c*/
if (base_addr == uint32_t(-1)) /* no i2c*/
deviceGroup->setEnabled(false);

/***********************************************/
Expand Down Expand Up @@ -213,7 +203,7 @@ i2c::i2c(QWidget *parent)
controlGroup->setFont(fontlabel);
controlGroup->setLayout(parameterGrid);

if (base_addr == 0) /* no i2c*/
if (base_addr == uint32_t(-1)) /* no i2c*/
controlGroup->setEnabled(false);

/******************************************************/
Expand All @@ -228,8 +218,9 @@ i2c::i2c(QWidget *parent)


unsigned char TmpStrBuf;
EApiStatus_t StatusCode;
StatusCode=EApiI2CReadTransfer(base_addr, 0x48, EAPI_I2C_ENC_STD_CMD(0),&TmpStrBuf, 1, 1);
EApiStatus_t StatusCode = EAPI_STATUS_ERROR;
if (base_addr != uint32_t(-1))
StatusCode=EApiI2CReadTransfer(base_addr, 0x48, EAPI_I2C_ENC_STD_CMD(0),&TmpStrBuf, 1, 1);

if(EAPI_TEST_SUCCESS(StatusCode))
temperatureButton->setEnabled(true);
Expand All @@ -244,7 +235,7 @@ i2c::i2c(QWidget *parent)
demoGroup->setFont(fontlabel);
demoGroup->setLayout(demoGrid);

if (base_addr == 0) /* no i2c*/
if (base_addr == (uint32_t(-1)) /* no i2c*/
demoGroup->setEnabled(false);

grid = new QGridLayout;
Expand Down Expand Up @@ -292,7 +283,7 @@ void i2c::timingSelected(bool checked)
}
void i2c::handleI2CselectionChanged(int index)
{
i2cBus = i2cID->itemText(index).toInt();
i2cBus = i2cID->itemData(index).toInt();
}
void i2c::slaveChanged(QString text)
{
Expand Down Expand Up @@ -587,8 +578,9 @@ void i2c::temperatureClicked()
void i2c::timeoutTimer()
{
unsigned char TmpStrBuf;
EApiStatus_t StatusCode;
StatusCode=EApiI2CReadTransfer(base_addr, 0x48, EAPI_I2C_ENC_STD_CMD(0),&TmpStrBuf, 1, 1);
EApiStatus_t StatusCode = EAPI_STATUS_ERROR;
if (base_addr != -1)
StatusCode=EApiI2CReadTransfer(base_addr, 0x48, EAPI_I2C_ENC_STD_CMD(0),&TmpStrBuf, 1, 1);

if(EAPI_TEST_SUCCESS(StatusCode))
{
Expand Down Expand Up @@ -619,6 +611,7 @@ void i2c::getInput()
}

/**************************************/
#ifndef _MSC_VER
struct i2c_adap* i2c::more_adapters(struct i2c_adap *adapters, int n)
{
struct i2c_adap *new_adapters;
Expand Down Expand Up @@ -753,27 +746,75 @@ void i2c::free_adapters(struct i2c_adap *adapters)
free(adapters[i].name);
free(adapters);
}
#endif // _MSC_VER

int i2c::find_eeprom(void)
int i2c::add_i2c_busses(QComboBox *i2cBusComboBox)
{
#ifndef _MSC_VER
struct i2c_adap *adapters = NULL;
int count;
int result = -1;
int i;
int mux_channel;
char mux[NAME_MAX] = "\0";

adapters = gather_i2c_busses();
if (adapters == NULL)
{
fprintf(stderr, "Error: Out of memory!\n");
return result;
return (result);
}
for (count = 0; adapters[count].name; count++) {
if (!strncmp(adapters[count].name, I2C_DMEC,8))

for (i = 0; adapters[i].name; i++) {
if (!strncmp(adapters[i].name, I2C_DMEC,8))
{
result = adapters[count].nr +1;
// found DMEC base instance now get all mux busses and add them to the Combobox
sprintf(mux, "i2c-%d-mux", adapters[i].nr);
break;
}
}

if (mux[0] != 0) {
char c[NAME_MAX] = "\0";
int index = 0;
for (i = 0; adapters[i].name; i++) {
if (!strncmp(adapters[i].name, mux,strlen(mux)))
{
// found DMEC mux bus, get channel number
if (sscanf(adapters[i].name, MUX_CHANNEL, c, &mux_channel)) {
i2cBusComboBox->addItem(QString::number(adapters[i].nr) + " (CH" + QString::number(mux_channel) + ")");
i2cBusComboBox->setItemData(index++, adapters[i].nr);
if (mux_channel == 0) {
result = adapters[i].nr;
}
}
}
}

}

free_adapters(adapters);
return result;
return (result);
#else // _MSC_VER
EApiStatus_t StatusCode;
uint32_t MaxBlkLen = 0;
int result = -1;

StatusCode = EApiI2CGetBusCap(EAPI_ID_I2C_EXTERNAL, &MaxBlkLen);
if(EAPI_TEST_SUCCESS(StatusCode)) {
i2cBusComboBox->addItem(QString::number(EAPI_ID_I2C_EXTERNAL));
result = EAPI_ID_I2C_EXTERNAL;
}

StatusCode = EApiI2CGetBusCap(EAPI_ID_I2C_LVDS_1, &MaxBlkLen);
if(EAPI_TEST_SUCCESS(StatusCode))
i2cBusComboBox->addItem(QString::number(EAPI_ID_I2C_LVDS_1));

StatusCode = EApiI2CGetBusCap(EAPI_ID_I2C_LVDS_2, &MaxBlkLen);
if(EAPI_TEST_SUCCESS(StatusCode))
i2cBusComboBox->addItem(QString::number(EAPI_ID_I2C_LVDS_2));
return (result);
#endif // _MSC_VER
}



12 changes: 10 additions & 2 deletions i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
#include <QCheckBox>
#include <QPlainTextEdit>

#ifndef _MSC_VER
#include <unistd.h>
#else
#include <stdint.h>
#include <EApiOsNTC.h>
#endif

#include "temperatureBar.h"

struct i2c_adap {
Expand All @@ -23,7 +30,8 @@ struct i2c_adap {
};

#define BUNCH 8
#define I2C_DMEC "i2c-dmec"
#define I2C_DMEC "i2c-dmec"
#define MUX_CHANNEL "%s (chan_id %d"

class i2c: public QWidget
{
Expand All @@ -34,7 +42,7 @@ class i2c: public QWidget
void free_adapters(struct i2c_adap *adapters);
struct i2c_adap* gather_i2c_busses(void);
struct i2c_adap* more_adapters(struct i2c_adap *adapters, int n);

int add_i2c_busses(QComboBox *i2cBusses);

public slots:
void readClicked();
Expand Down
5 changes: 5 additions & 0 deletions include/EApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
*</KHeader>
*/

#ifdef _MSC_VER
#include <EApiOs.h>
#include <stdint.h>
#endif

#ifndef _EAPI_H_
#define _EAPI_H_

Expand Down
Loading