Commit 866f7543 authored by Toni Ruoss's avatar Toni Ruoss
Browse files

Uebung_6_erstellt

parent b572fad0
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:uno]
platform = atmelavr
board = uno
framework = arduino
This diff is collapsed.
/**
* @copyright (C) 2017 Melexis N.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef _MLX640_API_H_
#define _MLX640_API_H_
#include "Arduino.h"
#define SCALEALPHA 0.000001
//#define MLX90640_DEBUG
typedef struct {
int16_t kVdd;
int16_t vdd25;
float KvPTAT;
float KtPTAT;
uint16_t vPTAT25;
float alphaPTAT;
int16_t gainEE;
float tgc;
float cpKv;
float cpKta;
uint8_t resolutionEE;
uint8_t calibrationModeEE;
float KsTa;
float ksTo[5];
int16_t ct[5];
uint16_t alpha[768];
uint8_t alphaScale;
int16_t offset[768];
int8_t kta[768];
uint8_t ktaScale;
int8_t kv[768];
uint8_t kvScale;
float cpAlpha[2];
int16_t cpOffset[2];
float ilChessC[3];
uint16_t brokenPixels[5];
uint16_t outlierPixels[5];
} paramsMLX90640;
#endif
/**
* @copyright (C) 2017 Melexis N.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#if 0 // we dont be using the mbed layer!
#include "MLX90640_I2C_Driver.h"
#include "mbed.h"
I2C i2c(p9, p10);
void MLX90640_I2CInit()
{
i2c.stop();
}
int MLX90640_I2CRead(uint8_t slaveAddr, uint16_t startAddress, uint16_t nMemAddressRead, uint16_t *data)
{
uint8_t sa;
int ack = 0;
int cnt = 0;
int i = 0;
char cmd[2] = {0,0};
char i2cData[1664] = {0};
uint16_t *p;
p = data;
sa = (slaveAddr << 1);
cmd[0] = startAddress >> 8;
cmd[1] = startAddress & 0x00FF;
i2c.stop();
wait_us(5);
ack = i2c.write(sa, cmd, 2, 1);
if (ack != 0x00)
{
return -1;
}
sa = sa | 0x01;
ack = i2c.read(sa, i2cData, 2*nMemAddressRead, 0);
if (ack != 0x00)
{
return -1;
}
i2c.stop();
for(cnt=0; cnt < nMemAddressRead; cnt++)
{
i = cnt << 1;
*p++ = (uint16_t)i2cData[i]*256 + (uint16_t)i2cData[i+1];
}
return 0;
}
void MLX90640_I2CFreqSet(int freq)
{
i2c.frequency(1000*freq);
}
int MLX90640_I2CWrite(uint8_t slaveAddr, uint16_t writeAddress, uint16_t data)
{
uint8_t sa;
int ack = 0;
char cmd[4] = {0,0,0,0};
static uint16_t dataCheck;
sa = (slaveAddr << 1);
cmd[0] = writeAddress >> 8;
cmd[1] = writeAddress & 0x00FF;
cmd[2] = data >> 8;
cmd[3] = data & 0x00FF;
i2c.stop();
wait_us(5);
ack = i2c.write(sa, cmd, 4, 0);
if (ack != 0x00)
{
return -1;
}
i2c.stop();
MLX90640_I2CRead(slaveAddr,writeAddress,1, &dataCheck);
if ( dataCheck != data)
{
return -2;
}
return 0;
}
#endif
/**
* @copyright (C) 2017 Melexis N.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef _MLX90640_I2C_Driver_H_
#define _MLX90640_I2C_Driver_H_
#include <stdint.h>
void MLX90640_I2CInit(void);
int MLX90640_I2CRead(uint8_t slaveAddr, uint16_t startAddress,
uint16_t nMemAddressRead, uint16_t *data);
int MLX90640_I2CWrite(uint8_t slaveAddr, uint16_t writeAddress, uint16_t data);
void MLX90640_I2CFreqSet(int freq);
#endif
\ No newline at end of file
/**
* @copyright (C) 2017 Melexis N.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
* As the timings depend heavily on the MCU in use, it is recommended
* to make sure that the proper timings are achieved. For that purpose
* an oscilloscope might be needed to strobe the SCL and SDA signals.
* The Wait(int) function could be modified in order to better
* trim the frequency. For coarse setting of the frequency or
* dynamic frequency change using the default function implementation,
* ‘freqCnt’ argument should be changed – lower value results in
* higher frequency.
*/
#if 0 // we dont be using the mbed layer!
#include "MLX90640_I2C_Driver.h"
#include "mbed.h"
DigitalInOut sda(p9);
DigitalOut scl(p10);
#define LOW 0;
#define HIGH 1;
#define SCL_HIGH scl = HIGH;
#define SCL_LOW scl = LOW;
#define SDA_HIGH sda.input();
#define SDA_LOW \
sda.output(); \
sda = LOW;
int I2CSendByte(int8_t);
void I2CReadBytes(int, char *);
void I2CStart(void);
void I2CStop(void);
void I2CRepeatedStart(void);
void I2CSendACK(void);
void I2CSendNack(void);
int I2CReceiveAck(void);
void Wait(int);
static int freqCnt;
void MLX90640_I2CInit()
{
I2CStop();
}
int MLX90640_I2CRead(uint8_t slaveAddr, uint16_t startAddress,uint16_t nMemAddressRead, uint16_t *data)
{
uint8_t sa;
int ack = 0;
int cnt = 0;
int i = 0;
char cmd[2] = {0,0};
char i2cData[1664] = {0};
uint16_t *p;
p = data;
sa = (slaveAddr << 1);
cmd[0] = startAddress >> 8;
cmd[1] = startAddress & 0x00FF;
I2CStop();
Wait(freqCnt);
I2CStart();
Wait(freqCnt);
ack = I2CSendByte(sa)!=0;
if(ack != 0)
{
return -1;
}
ack = I2CSendByte(cmd[0])!=0;
if(ack != 0)
{
return -1;
}
ack = I2CSendByte(cmd[1])!=0;
if(ack != 0)
{
return -1;
}
I2CRepeatedStart();
sa = sa | 0x01;
ack = I2CSendByte(sa);
if(ack != 0)
{
return -1;
}
I2CReadBytes((nMemAddressRead << 1), i2cData);
I2CStop();
for(cnt=0; cnt < nMemAddressRead; cnt++)
{
i = cnt << 1;
*p++ = (int)i2cData[i]*256 + (int)i2cData[i+1];
}
return 0;
}
void MLX90640_I2CFreqSet(int freq)
{
freqCnt = freq>>1;
}
int MLX90640_I2CWrite(uint8_t slaveAddr, uint16_t writeAddress, uint16_t data)
{
uint8_t sa;
int ack = 0;
char cmd[4] = {0,0,0,0};
static uint16_t dataCheck;
sa = (slaveAddr << 1);
cmd[0] = writeAddress >> 8;
cmd[1] = writeAddress & 0x00FF;
cmd[2] = data >> 8;
cmd[3] = data & 0x00FF;
I2CStop();
Wait(freqCnt);
I2CStart();
ack = I2CSendByte(sa);
if (ack != 0x00)
{
return 1;
}
for(int i = 0; i<4; i++)
{
ack = I2CSendByte(cmd[i]);
if (ack != 0x00)
{
return -1;
}
}
I2CStop();
MLX90640_I2CRead(slaveAddr,writeAddress,1, &dataCheck);
if ( dataCheck != data)
{
return -2;
}
return 0;
}
int I2CSendByte(int8_t data)
{
int ack = 1;
int8_t byte = data;
for(int i=0;i<8;i++)
{
Wait(freqCnt);
if(byte & 0x80)
{
SDA_HIGH;
}
else
{
SDA_LOW;
}
Wait(freqCnt);
SCL_HIGH;
Wait(freqCnt);
Wait(freqCnt);
SCL_LOW;
byte = byte<<1;
}
Wait(freqCnt);
ack = I2CReceiveAck();
return ack;
}
void I2CReadBytes(int nBytes, char *dataP)
{
char data;
for(int j=0;j<nBytes;j++)
{
Wait(freqCnt);
SDA_HIGH;
data = 0;
for(int i=0;i<8;i++){
Wait(freqCnt);
SCL_HIGH;
Wait(freqCnt);
data = data<<1;
if(sda == 1){
data = data+1;
}
Wait(freqCnt);
SCL_LOW;
Wait(freqCnt);
}
if(j == (nBytes-1))
{
I2CSendNack();
}
else
{
I2CSendACK();
}
*(dataP+j) = data;
}
}
void Wait(int freqCnt)
{
int cnt;
for(int i = 0;i<freqCnt;i++)
{
cnt = cnt++;
}
}
void I2CStart(void)
{
SDA_HIGH;
SCL_HIGH;
Wait(freqCnt);
Wait(freqCnt);
SDA_LOW;
Wait(freqCnt);
SCL_LOW;
Wait(freqCnt);
}
void I2CStop(void)
{
SCL_LOW;
SDA_LOW;
Wait(freqCnt);
SCL_HIGH;
Wait(freqCnt);
SDA_HIGH;
Wait(freqCnt);
}
void I2CRepeatedStart(void)
{
SCL_LOW;
Wait(freqCnt);
SDA_HIGH;
Wait(freqCnt);
SCL_HIGH;
Wait(freqCnt);
SDA_LOW;
Wait(freqCnt);
SCL_LOW;
}
void I2CSendACK(void)
{
SDA_LOW;
Wait(freqCnt);
SCL_HIGH;
Wait(freqCnt);
Wait(freqCnt);
SCL_LOW;
Wait(freqCnt);
SDA_HIGH;
}
void I2CSendNack(void)
{
SDA_HIGH;
Wait(freqCnt);