Tsev > Xov xwm > Ntsiab lus

FT_Hal_I2C.cpp

May 06, 2019

/ * Cov ntaub ntawv no muaj apis ntsig txog i2c * /

/ * Txheem xws li * /

#include "FT_Platform.h"

#include "..WireWire.h"

# 0

#include "FT_DataTypes.h"

#include "FT_Gpu.h"

#ifdef ARDUINO_PLATFORM

#include

#include

#include

#include

#include

#endif

#endif

#include "FT_Hal_I2C.h"


ft_int16_t hal_rtc_i2c_init ()

{

Wire.begin ();

ft_delay (100);

rov qab 0;

}


/ * api nyeem n bytes los ntawm addr * /

ft_int16_t hal_rtc_i2c_read (ft_uint8_t addr, ft_uint8_t * tsis, ft_uint16_t ntev)

{

ft_uint16_t kuv;

kev suav luv luv = 0;

ft_uint8_t sauResult = 0;

thaum lub sijhawm (ntev> 28)

{

hal_rtc_i2c_read (addr, tsis, 28);

tsis kam + = 28;

addr + = 28;

ntev - = 28;

}


Wire.beginTransmission (0x6f); // xa mus rau kev ntaus ntawv (0x23)

/ * chaw nyob bytes rau rtc yog los ntawm 00 kom 0xff * /

Wire.write (addr); // xa nqi nqi byte


/ * xaus qhov kis tau tus mob, tiam sis tsis tso tsheb npav - kev pab yog siv cov ntaub ntawv siv los ntawm rtc * /

writeResult = Wire.endTransmission (cuav); // tuav lub npav mus nyeem cov ntaub ntawv tom ntej

yog tias (0! = writeResult)

{

rov qab -1; // yuam kev case

}

Wire.requestFrom (0x6f, ntev); // thov ntev bytes ntawm tus qhev ncaj qha thiab xaus qhov kis mob tom qab

rau (i = 0; kuv

{

/ * yuav tsum xav txog qhov ncua sij hawm ntawm * /

thaum (0 == Wire.available ()); // blocking hu - tsawg kawg yog ib byte yuav tsum muaj

tsis [i] = Wire.read ();

}

rov qab 0;

}

/ * API sau cov ntaub ntawv hauv qhov chaw * /

ft_int16_t hal_rtc_i2c_write (ft_uint8_t addr, ft_uint8_t * tsis, ft_uint16_t ntev)

{

ft_uint16_t kuv;

byte writeResult = 0;

yog tias (0 == ntev)

{

rov qab -1;

}

/ * rau nyeem ntawv qis dua yuav tsum tau teem rau 1 thiab sau rau 0 * /

Wire.beginTransmission (0x6f);


/ * chaw nyob bytes rau rtc yog los ntawm 00 kom 0xff * /

Wire.write (addr); // xa nqi nqi byte

/ * kos rau txhua tus byte * /

rau (i = 0; kuv

{

Wire.write (* tsis tuaj ++); // xa cov ntaub ntawv rau qhev ncaj qha

}


/ * xaus qhov kis mob los ntawm kev tso dag me ntsis * /

writeResult = Wire.endTransmission (); // xaus qhov kis mob los ntawm qhov chaw nres tsheb

yog tias (0! = writeResult)

{

rov qab sau dua tshiab;

}

rov qab 0;

}

/ * Tsis muaj dab tsi tshaj qhov no * /