Interface Driver for Maxim DS2482 1Wire-to-I2C bridge IC. Includes access functions for DS1820 temperature sensors. Can easily be ported to other hardware by using hardware abstraction layer.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers i2c_api.cpp Source File

i2c_api.cpp

00001 /* ============== Platform-specific API ===================*/
00002 /* ( HAL - Hardware Abstraction Layer Implementation )     */
00003 /* These functions have to be implemented in actual system */
00004 
00005 #include "i2c_api.h"
00006 
00007 I2C *mbed_i2c;
00008 
00009 // returns 0 on ACK
00010 int8_t _i8I2CWrite(uint8_t u8Cmd, uint8_t *u8Data, uint8_t u8Size)
00011 {
00012     return mbed_i2c->write(u8Cmd, (const char*) u8Data, u8Size);
00013 }
00014 
00015 // returns 0 on ACK
00016 int8_t _i8I2CWriteByte(uint8_t u8Data)
00017 {
00018     return !mbed_i2c->write(u8Data);        // this sucker returns 1 on ACK so invert it
00019 }
00020 
00021 // return 0 on ACK
00022 // NAK ("stop") last byte if u8Repeated == 0
00023 int8_t _i8I2CRead           (uint8_t u8Cmd, uint8_t *u8Data, uint8_t u8Size, uint8_t u8Repeated)
00024 {
00025     return mbed_i2c->read(u8Cmd, (char*)u8Data, u8Size, u8Repeated);
00026 }
00027 
00028 // returns read data
00029 // sends acknowledge if u8Ack == 1
00030 int8_t _i8I2CReadByte       (uint8_t u8Ack)
00031 {
00032     return mbed_i2c->read(u8Ack);
00033 }
00034 
00035 void   _vI2CStart           (void)
00036 {
00037     mbed_i2c->start();
00038 }
00039 
00040 void   _vI2CStop            (void)
00041 {
00042     mbed_i2c->stop();
00043 }
00044