image/svg+xml
Brteve's API for EveApps
Version 0.0.1
The reference document for common folder of EveApps project.
 
Loading...
Searching...
No Matches
Hal_I2C.cpp
Go to the documentation of this file.
1
32/* Standard includes */
33#include "Platform.h"
34#include <Wire.h>
35#include "Hal_I2C.h"
36
37/* mainly assosiated to rtc - need to make it generic */
38
40{
41 Wire.begin();
42 delay(100);
43 return 0;
44}
45
46/* api to read n bytes from addr */
48{
49 uint16_t i;
50 short count = 0;
51 uint8_t writeResult = 0;
52 while (length > 28)
53 {
55 buffer += 28;
56 addr += 28;
57 length -= 28;
58 }
59
60 Wire.beginTransmission(0x6f); // transmit to device (0x23)
61
62 /* address bytes for rtc are from 00 to 0xff */
63 Wire.write(addr); // sends value byte
64
65 /* end the transmission but do not release the bus - usage is random data read use case from rtc */
66 writeResult = Wire.endTransmission(false);//hold the bus to read the next data
67
68 if (0 != writeResult)
69 {
70 return -1;//error case
71 }
72
73 Wire.requestFrom(0x6f, length);// request length bytes from slave device and end the transmission after this
74 for(i=0;i<length;i++)
75 {
76 /* need to consider timout here */
77 while(0 == Wire.available());//blocking call - at least one byte must be available
78 buffer[i] = Wire.read();
79 }
80
81 return 0;
82}
83
84/* API to write data into particular location */
86{
87 uint16_t i;
88 byte writeResult = 0;
89 if(0 == length)
90 {
91 return -1;
92 }
93
94 /* for read the lower bit must be set to 1 and for write set to 0 */
95 Wire.beginTransmission(0x6f);
96
97 /* address bytes for rtc are from 00 to 0xff */
98 Wire.write(addr); // sends value byte
99
100 /* check for each byte */
101 for(i=0;i<length;i++)
102 {
103 Wire.write(*buffer++);//send the data to slave
104 }
105
106 /* end the transmission by stop bit */
107
108 writeResult = Wire.endTransmission();//end the transmission by setting the stop bit
109
110 if(0 != writeResult)
111 {
112 return writeResult;
113 }
114 return 0;
115}
116
117/* Nothing beyond this */
118
unsigned short uint16_t
short int16_t
unsigned char uint8_t
static ft_uint32_t ft_uint8_t * buffer
Definition FT_Gpu_Hal.h:139
static ft_uint32_t ft_uint8_t ft_uint32_t length
Definition FT_Gpu_Hal.h:140
static ft_uint32_t addr
Definition FT_Gpu_Hal.h:139
#define delay(x)
Definition Gpu_Hal.h:468
int16_t hal_rtc_i2c_write(uint8_t addr, uint8_t *buffer, uint16_t length)
Definition Hal_I2C.cpp:85
int16_t hal_rtc_i2c_read(uint8_t addr, uint8_t *buffer, uint16_t length)
Definition Hal_I2C.cpp:47
int16_t hal_rtc_i2c_init()
Definition Hal_I2C.cpp:39
This file contains apis related to i2c.
Platform APIs.