You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Get my dirty fingers out of the SDK.
This commit should return the SDK files (i2c_struct.h,i2c_reg.h) back to
factory defaults. The required typedef's were duplicated in
esp32-hal-i2c.h instead.
With this Commit, the only changes are in Wire.h, Wire.cpp,
esp32-hal-i2c.h, esp32-hal-i2c.c
Copy file name to clipboardExpand all lines: cores/esp32/esp32-hal-i2c.h
+52-10
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,7 @@
11
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
+
// modified Nov 2017 by Chuck Todd <StickBreaker> to support Interrupt Driven I/O
14
15
15
16
#ifndef_ESP32_HAL_I2C_H_
16
17
#define_ESP32_HAL_I2C_H_
@@ -25,7 +26,41 @@ extern "C" {
25
26
#include"freertos/FreeRTOS.h"
26
27
#include"freertos/event_groups.h"
27
28
28
-
29
+
// start from tools/sdk/include/soc/soc/i2c_struct.h
30
+
31
+
typedefunion {
32
+
struct {
33
+
uint32_tbyte_num: 8; /*Byte_num represent the number of data need to be send or data need to be received.*/
34
+
uint32_tack_en: 1; /*ack_check_en ack_exp and ack value are used to control the ack bit.*/
35
+
uint32_tack_exp: 1; /*ack_check_en ack_exp and ack value are used to control the ack bit.*/
36
+
uint32_tack_val: 1; /*ack_check_en ack_exp and ack value are used to control the ack bit.*/
37
+
uint32_top_code: 3; /*op_code is the command 0:RSTART 1:WRITE 2:READ 3:STOP . 4:END.*/
38
+
uint32_treserved14: 17;
39
+
uint32_tdone: 1; /*When command0 is done in I2C Master mode this bit changes to high level.*/
40
+
};
41
+
uint32_tval;
42
+
} I2C_COMMAND_t;
43
+
44
+
typedefunion {
45
+
struct {
46
+
uint32_trx_fifo_full_thrhd: 5;
47
+
uint32_ttx_fifo_empty_thrhd:5; //Config tx_fifo empty threhd value when using apb fifo access * /
48
+
uint32_tnonfifo_en: 1; //Set this bit to enble apb nonfifo access. * /
49
+
uint32_tfifo_addr_cfg_en: 1; //When this bit is set to 1 then the byte after address represent the offset address of I2C Slave's ram. * /
50
+
uint32_trx_fifo_rst: 1; //Set this bit to reset rx fifo when using apb fifo access. * /
51
+
// chuck while this bit is 1, the RX fifo is held in REST, Toggle it * /
52
+
uint32_ttx_fifo_rst: 1; //Set this bit to reset tx fifo when using apb fifo access. * /
53
+
// chuck while this bit is 1, the TX fifo is held in REST, Toggle it * /
54
+
uint32_tnonfifo_rx_thres: 6; //when I2C receives more than nonfifo_rx_thres data it will produce rx_send_full_int_raw interrupt and update the current offset address of the receiving data.* /
55
+
uint32_tnonfifo_tx_thres: 6; //when I2C sends more than nonfifo_tx_thres data it will produce tx_send_empty_int_raw interrupt and update the current offset address of the sending data. * /
56
+
uint32_treserved26: 6;
57
+
};
58
+
uint32_tval;
59
+
} I2C_FIFO_CONF_t;
60
+
61
+
// end from tools/sdk/include/soc/soc/i2c_struct.h
62
+
63
+
// External Wire.h equivalent error Codes
29
64
typedefenum {
30
65
I2C_ERROR_OK=0,
31
66
I2C_ERROR_DEV,
@@ -38,6 +73,7 @@ typedef enum {
38
73
I2C_ERROR_NO_BEGIN
39
74
} i2c_err_t;
40
75
76
+
// sync between dispatch(i2cProcQueue) and worker(i2c_isr_handler_default)
41
77
typedefenum {
42
78
//I2C_NONE=0,
43
79
I2C_STARTUP=1,
@@ -52,7 +88,7 @@ typedef enum {
52
88
I2C_MASTERSLAVE
53
89
}I2C_MODE_t;
54
90
55
-
91
+
// internal Error condition
56
92
typedefenum {
57
93
// I2C_NONE=0,
58
94
I2C_OK=1,
@@ -63,22 +99,26 @@ typedef enum {
63
99
I2C_TIMEOUT
64
100
}I2C_ERROR_t;
65
101
66
-
// i2c_event bits
102
+
// i2c_event bits for EVENTGROUP bits
103
+
// needed to minimize change events, FreeRTOS Daemon overload, so ISR will only set values
104
+
// on Exit. Dispatcher will set bits for each dq before/after ISR completion
67
105
#defineEVENT_ERROR_NAK (BIT(0))
68
106
#defineEVENT_ERROR (BIT(1))
69
-
//#define EVENT_RUNNING (BIT(3))
107
+
#defineEVENT_RUNNING (BIT(3))
70
108
#defineEVENT_DONE (BIT(4))
71
109
#defineEVENT_IN_END (BIT(5))
72
110
#defineEVENT_ERROR_PREV (BIT(6))
73
111
#defineEVENT_ERROR_TIMEOUT (BIT(7))
74
112
#defineEVENT_ERROR_ARBITRATION (BIT(8))
75
113
#defineEVENT_ERROR_DATA_NAK (BIT(9))
76
114
#defineEVENT_MASK 0x3F
115
+
116
+
// control record for each dq entry
77
117
typedefunion{
78
118
struct {
79
119
uint32_taddr: 16; // I2C address, if 10bit must have 0x7800 mask applied, else 8bit
80
-
uint32_tmode: 1; // 0 write, 1 read
81
-
uint32_tstop: 1; // 0 no, 1 yes
120
+
uint32_tmode: 1; // transaction direction 0 write, 1 read
121
+
uint32_tstop: 1; // sendStop 0 no, 1 yes
82
122
uint32_tstartCmdSent: 1; // START cmd has been added to command[]
83
123
uint32_taddrCmdSent: 1; // addr WRITE cmd has been added to command[]
84
124
uint32_tdataCmdSent: 1; // all necessary DATA(READ/WRITE) cmds added to command[]
@@ -89,15 +129,17 @@ typedef union{
89
129
};
90
130
uint32_tval;
91
131
}I2C_DATA_CTRL_t;
92
-
132
+
133
+
// individual dq element
93
134
typedefstruct {
94
135
uint8_t*data; // datapointer for read/write buffer
95
136
uint16_tlength; // size of data buffer
96
137
uint16_tposition; // current position for next char in buffer (<length)
97
-
uint16_tcmdBytesNeeded; // number of data bytes needing (READ/WRITE)Command[]
98
-
uint16_tqueueLength;
138
+
uint16_tcmdBytesNeeded; // used to control number of I2C_COMMAND_t blocks added to queu
139
+
uint16_tqueueLength; // number of data bytes needing moved, used to control
140
+
// current queuePos for fifo fills
99
141
I2C_DATA_CTRL_tctrl;
100
-
EventGroupHandle_tqueueEvent;
142
+
EventGroupHandle_tqueueEvent;// optional user supplied for Async feedback EventBits
0 commit comments