i2c_struct.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _SOC_I2C_STRUCT_H_
  14. #define _SOC_I2C_STRUCT_H_
  15. typedef volatile struct {
  16. union {
  17. struct {
  18. uint32_t scl_low_period:14; /*This register is used to configure the low level width of SCL clock.*/
  19. uint32_t reserved14: 18;
  20. };
  21. uint32_t val;
  22. } scl_low_period;
  23. union {
  24. struct {
  25. uint32_t sda_force_out: 1; /*1:normally output sda data 0: exchange the function of sda_o and sda_oe (sda_o is the original internal output sda signal sda_oe is the enable bit for the internal output sda signal)*/
  26. uint32_t scl_force_out: 1; /*1:normally output scl clock 0: exchange the function of scl_o and scl_oe (scl_o is the original internal output scl signal scl_oe is the enable bit for the internal output scl signal)*/
  27. uint32_t sample_scl_level: 1; /*Set this bit to sample data in SCL low level. clear this bit to sample data in SCL high level.*/
  28. uint32_t reserved3: 1;
  29. uint32_t ms_mode: 1; /*Set this bit to configure the module as i2c master clear this bit to configure the module as i2c slave.*/
  30. uint32_t trans_start: 1; /*Set this bit to start sending data in tx_fifo.*/
  31. uint32_t tx_lsb_first: 1; /*This bit is used to control the sending mode for data need to be send. 1:receive data from most significant bit 0:receive data from least significant bit*/
  32. uint32_t rx_lsb_first: 1; /*This bit is used to control the storage mode for received data. 1:receive data from most significant bit 0:receive data from least significant bit*/
  33. uint32_t clk_en: 1; /*This is the clock gating control bit for reading or writing registers.*/
  34. uint32_t reserved9: 23;
  35. };
  36. uint32_t val;
  37. } ctr;
  38. union {
  39. struct {
  40. uint32_t ack_rec: 1; /*This register stores the value of ACK bit.*/
  41. uint32_t slave_rw: 1; /*when in slave mode 1:master read slave 0: master write slave.*/
  42. uint32_t time_out: 1; /*when I2C takes more than time_out_reg clocks to receive a data then this register changes to high level.*/
  43. uint32_t arb_lost: 1; /*when I2C lost control of SDA line this register changes to high level.*/
  44. uint32_t bus_busy: 1; /*1:I2C bus is busy transferring data. 0:I2C bus is in idle state.*/
  45. uint32_t slave_addressed: 1; /*when configured as i2c slave and the address send by master is equal to slave's address then this bit will be high level.*/
  46. uint32_t byte_trans: 1; /*This register changes to high level when one byte is transferred.*/
  47. uint32_t reserved7: 1;
  48. uint32_t rx_fifo_cnt: 6; /*This register represent the amount of data need to send.*/
  49. uint32_t reserved14: 4;
  50. uint32_t tx_fifo_cnt: 6; /*This register stores the amount of received data in ram.*/
  51. uint32_t scl_main_state_last: 3; /*This register stores the value of state machine for i2c module. 3'h0: SCL_MAIN_IDLE 3'h1: SCL_ADDRESS_SHIFT 3'h2: SCL_ACK_ADDRESS 3'h3: SCL_RX_DATA 3'h4 SCL_TX_DATA 3'h5:SCL_SEND_ACK 3'h6:SCL_WAIT_ACK*/
  52. uint32_t reserved27: 1;
  53. uint32_t scl_state_last: 3; /*This register stores the value of state machine to produce SCL. 3'h0: SCL_IDLE 3'h1:SCL_START 3'h2:SCL_LOW_EDGE 3'h3: SCL_LOW 3'h4:SCL_HIGH_EDGE 3'h5:SCL_HIGH 3'h6:SCL_STOP*/
  54. uint32_t reserved31: 1;
  55. };
  56. uint32_t val;
  57. } status_reg;
  58. union {
  59. struct {
  60. uint32_t tout: 20; /*This register is used to configure the max clock number of receiving a data.*/
  61. uint32_t reserved20:12;
  62. };
  63. uint32_t val;
  64. } timeout;
  65. union {
  66. struct {
  67. uint32_t addr: 15; /*when configured as i2c slave this register is used to configure slave's address.*/
  68. uint32_t reserved15: 16;
  69. uint32_t en_10bit: 1; /*This register is used to enable slave 10bit address mode.*/
  70. };
  71. uint32_t val;
  72. } slave_addr;
  73. union {
  74. struct {
  75. uint32_t rx_fifo_start_addr: 5; /*This is the offset address of the last receiving data as described in nonfifo_rx_thres_register.*/
  76. uint32_t rx_fifo_end_addr: 5; /*This is the offset address of the first receiving data as described in nonfifo_rx_thres_register.*/
  77. uint32_t tx_fifo_start_addr: 5; /*This is the offset address of the first sending data as described in nonfifo_tx_thres register.*/
  78. uint32_t tx_fifo_end_addr: 5; /*This is the offset address of the last sending data as described in nonfifo_tx_thres register.*/
  79. uint32_t reserved20: 12;
  80. };
  81. uint32_t val;
  82. } fifo_st;
  83. union {
  84. struct {
  85. uint32_t rx_fifo_full_thrhd: 5;
  86. uint32_t tx_fifo_empty_thrhd:5; /*Config tx_fifo empty threhd value when using apb fifo access*/
  87. uint32_t nonfifo_en: 1; /*Set this bit to enble apb nonfifo access.*/
  88. uint32_t fifo_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.*/
  89. uint32_t rx_fifo_rst: 1; /*Set this bit to reset rx fifo when using apb fifo access.*/
  90. uint32_t tx_fifo_rst: 1; /*Set this bit to reset tx fifo when using apb fifo access.*/
  91. uint32_t nonfifo_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.*/
  92. uint32_t nonfifo_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.*/
  93. uint32_t reserved26: 6;
  94. };
  95. uint32_t val;
  96. } fifo_conf;
  97. union {
  98. struct {
  99. uint8_t data; /*The register represent the byte data read from rx_fifo when use apb fifo access*/
  100. uint8_t reserved[3];
  101. };
  102. uint32_t val;
  103. } fifo_data;
  104. union {
  105. struct {
  106. uint32_t rx_fifo_full: 1; /*The raw interrupt status bit for rx_fifo full when use apb fifo access.*/
  107. uint32_t tx_fifo_empty: 1; /*The raw interrupt status bit for tx_fifo empty when use apb fifo access.*/
  108. uint32_t rx_fifo_ovf: 1; /*The raw interrupt status bit for receiving data overflow when use apb fifo access.*/
  109. uint32_t end_detect: 1; /*The raw interrupt status bit for end_detect_int interrupt. when I2C deals with the END command it will produce end_detect_int interrupt.*/
  110. uint32_t slave_tran_comp: 1; /*The raw interrupt status bit for slave_tran_comp_int interrupt. when I2C Slave detects the STOP bit it will produce slave_tran_comp_int interrupt.*/
  111. uint32_t arbitration_lost: 1; /*The raw interrupt status bit for arbitration_lost_int interrupt.when I2C lost the usage right of I2C BUS it will produce arbitration_lost_int interrupt.*/
  112. uint32_t master_tran_comp: 1; /*The raw interrupt status bit for master_tra_comp_int interrupt. when I2C Master sends or receives a byte it will produce master_tran_comp_int interrupt.*/
  113. uint32_t trans_complete: 1; /*The raw interrupt status bit for trans_complete_int interrupt. when I2C Master finished STOP command it will produce trans_complete_int interrupt.*/
  114. uint32_t time_out: 1; /*The raw interrupt status bit for time_out_int interrupt. when I2C takes a lot of time to receive a data it will produce time_out_int interrupt.*/
  115. uint32_t trans_start: 1; /*The raw interrupt status bit for trans_start_int interrupt. when I2C sends the START bit it will produce trans_start_int interrupt.*/
  116. uint32_t ack_err: 1; /*The raw interrupt status bit for ack_err_int interrupt. when I2C receives a wrong ACK bit it will produce ack_err_int interrupt..*/
  117. uint32_t rx_rec_full: 1; /*The raw interrupt status bit for rx_rec_full_int interrupt. when I2C receives more data than nonfifo_rx_thres it will produce rx_rec_full_int interrupt.*/
  118. uint32_t tx_send_empty: 1; /*The raw interrupt status bit for tx_send_empty_int interrupt.when I2C sends more data than nonfifo_tx_thres it will produce tx_send_empty_int interrupt..*/
  119. uint32_t reserved13: 19;
  120. };
  121. uint32_t val;
  122. } int_raw;
  123. union {
  124. struct {
  125. uint32_t rx_fifo_full: 1; /*Set this bit to clear the rx_fifo_full_int interrupt.*/
  126. uint32_t tx_fifo_empty: 1; /*Set this bit to clear the tx_fifo_empty_int interrupt.*/
  127. uint32_t rx_fifo_ovf: 1; /*Set this bit to clear the rx_fifo_ovf_int interrupt.*/
  128. uint32_t end_detect: 1; /*Set this bit to clear the end_detect_int interrupt.*/
  129. uint32_t slave_tran_comp: 1; /*Set this bit to clear the slave_tran_comp_int interrupt.*/
  130. uint32_t arbitration_lost: 1; /*Set this bit to clear the arbitration_lost_int interrupt.*/
  131. uint32_t master_tran_comp: 1; /*Set this bit to clear the master_tran_comp interrupt.*/
  132. uint32_t trans_complete: 1; /*Set this bit to clear the trans_complete_int interrupt.*/
  133. uint32_t time_out: 1; /*Set this bit to clear the time_out_int interrupt.*/
  134. uint32_t trans_start: 1; /*Set this bit to clear the trans_start_int interrupt.*/
  135. uint32_t ack_err: 1; /*Set this bit to clear the ack_err_int interrupt.*/
  136. uint32_t rx_rec_full: 1; /*Set this bit to clear the rx_rec_full_int interrupt.*/
  137. uint32_t tx_send_empty: 1; /*Set this bit to clear the tx_send_empty_int interrupt.*/
  138. uint32_t reserved13: 19;
  139. };
  140. uint32_t val;
  141. } int_clr;
  142. union {
  143. struct {
  144. uint32_t rx_fifo_full: 1; /*The enable bit for rx_fifo_full_int interrupt.*/
  145. uint32_t tx_fifo_empty: 1; /*The enable bit for tx_fifo_empty_int interrupt.*/
  146. uint32_t rx_fifo_ovf: 1; /*The enable bit for rx_fifo_ovf_int interrupt.*/
  147. uint32_t end_detect: 1; /*The enable bit for end_detect_int interrupt.*/
  148. uint32_t slave_tran_comp: 1; /*The enable bit for slave_tran_comp_int interrupt.*/
  149. uint32_t arbitration_lost: 1; /*The enable bit for arbitration_lost_int interrupt.*/
  150. uint32_t master_tran_comp: 1; /*The enable bit for master_tran_comp_int interrupt.*/
  151. uint32_t trans_complete: 1; /*The enable bit for trans_complete_int interrupt.*/
  152. uint32_t time_out: 1; /*The enable bit for time_out_int interrupt.*/
  153. uint32_t trans_start: 1; /*The enable bit for trans_start_int interrupt.*/
  154. uint32_t ack_err: 1; /*The enable bit for ack_err_int interrupt.*/
  155. uint32_t rx_rec_full: 1; /*The enable bit for rx_rec_full_int interrupt.*/
  156. uint32_t tx_send_empty: 1; /*The enable bit for tx_send_empty_int interrupt.*/
  157. uint32_t reserved13: 19;
  158. };
  159. uint32_t val;
  160. } int_ena;
  161. union {
  162. struct {
  163. uint32_t rx_fifo_full: 1; /*The masked interrupt status for rx_fifo_full_int interrupt.*/
  164. uint32_t tx_fifo_empty: 1; /*The masked interrupt status for tx_fifo_empty_int interrupt.*/
  165. uint32_t rx_fifo_ovf: 1; /*The masked interrupt status for rx_fifo_ovf_int interrupt.*/
  166. uint32_t end_detect: 1; /*The masked interrupt status for end_detect_int interrupt.*/
  167. uint32_t slave_tran_comp: 1; /*The masked interrupt status for slave_tran_comp_int interrupt.*/
  168. uint32_t arbitration_lost: 1; /*The masked interrupt status for arbitration_lost_int interrupt.*/
  169. uint32_t master_tran_comp: 1; /*The masked interrupt status for master_tran_comp_int interrupt.*/
  170. uint32_t trans_complete: 1; /*The masked interrupt status for trans_complete_int interrupt.*/
  171. uint32_t time_out: 1; /*The masked interrupt status for time_out_int interrupt.*/
  172. uint32_t trans_start: 1; /*The masked interrupt status for trans_start_int interrupt.*/
  173. uint32_t ack_err: 1; /*The masked interrupt status for ack_err_int interrupt.*/
  174. uint32_t rx_rec_full: 1; /*The masked interrupt status for rx_rec_full_int interrupt.*/
  175. uint32_t tx_send_empty: 1; /*The masked interrupt status for tx_send_empty_int interrupt.*/
  176. uint32_t reserved13: 19;
  177. };
  178. uint32_t val;
  179. } int_status;
  180. union {
  181. struct {
  182. uint32_t time: 10; /*This register is used to configure the clock num I2C used to hold the data after the negedge of SCL.*/
  183. uint32_t reserved10: 22;
  184. };
  185. uint32_t val;
  186. } sda_hold;
  187. union {
  188. struct {
  189. uint32_t time: 10; /*This register is used to configure the clock num I2C used to sample data on SDA after the posedge of SCL*/
  190. uint32_t reserved10: 22;
  191. };
  192. uint32_t val;
  193. } sda_sample;
  194. union {
  195. struct {
  196. uint32_t period: 14; /*This register is used to configure the clock num during SCL is low level.*/
  197. uint32_t reserved14: 18;
  198. };
  199. uint32_t val;
  200. } scl_high_period;
  201. uint32_t reserved_3c;
  202. union {
  203. struct {
  204. uint32_t time: 10; /*This register is used to configure the clock num between the negedge of SDA and negedge of SCL for start mark.*/
  205. uint32_t reserved10: 22;
  206. };
  207. uint32_t val;
  208. } scl_start_hold;
  209. union {
  210. struct {
  211. uint32_t time: 10; /*This register is used to configure the clock num between the posedge of SCL and the negedge of SDA for restart mark.*/
  212. uint32_t reserved10: 22;
  213. };
  214. uint32_t val;
  215. } scl_rstart_setup;
  216. union {
  217. struct {
  218. uint32_t time: 14; /*This register is used to configure the clock num after the STOP bit's posedge.*/
  219. uint32_t reserved14: 18;
  220. };
  221. uint32_t val;
  222. } scl_stop_hold;
  223. union {
  224. struct {
  225. uint32_t time: 10; /*This register is used to configure the clock num between the posedge of SCL and the posedge of SDA.*/
  226. uint32_t reserved10: 22;
  227. };
  228. uint32_t val;
  229. } scl_stop_setup;
  230. union {
  231. struct {
  232. uint32_t thres: 3; /*When input SCL's pulse width is smaller than this register value I2C ignores this pulse.*/
  233. uint32_t en: 1; /*This is the filter enable bit for SCL.*/
  234. uint32_t reserved4: 28;
  235. };
  236. uint32_t val;
  237. } scl_filter_cfg;
  238. union {
  239. struct {
  240. uint32_t thres: 3; /*When input SCL's pulse width is smaller than this register value I2C ignores this pulse.*/
  241. uint32_t en: 1; /*This is the filter enable bit for SDA.*/
  242. uint32_t reserved4: 28;
  243. };
  244. uint32_t val;
  245. } sda_filter_cfg;
  246. union {
  247. struct {
  248. uint32_t byte_num: 8; /*Byte_num represent the number of data need to be send or data need to be received.*/
  249. uint32_t ack_en: 1; /*ack_check_en ack_exp and ack value are used to control the ack bit.*/
  250. uint32_t ack_exp: 1; /*ack_check_en ack_exp and ack value are used to control the ack bit.*/
  251. uint32_t ack_val: 1; /*ack_check_en ack_exp and ack value are used to control the ack bit.*/
  252. uint32_t op_code: 3; /*op_code is the command 0:RSTART 1:WRITE 2:READ 3:STOP . 4:END.*/
  253. uint32_t reserved14: 17;
  254. uint32_t done: 1; /*When command0 is done in I2C Master mode this bit changes to high level.*/
  255. };
  256. uint32_t val;
  257. } command[16];
  258. uint32_t reserved_98;
  259. uint32_t reserved_9c;
  260. uint32_t reserved_a0;
  261. uint32_t reserved_a4;
  262. uint32_t reserved_a8;
  263. uint32_t reserved_ac;
  264. uint32_t reserved_b0;
  265. uint32_t reserved_b4;
  266. uint32_t reserved_b8;
  267. uint32_t reserved_bc;
  268. uint32_t reserved_c0;
  269. uint32_t reserved_c4;
  270. uint32_t reserved_c8;
  271. uint32_t reserved_cc;
  272. uint32_t reserved_d0;
  273. uint32_t reserved_d4;
  274. uint32_t reserved_d8;
  275. uint32_t reserved_dc;
  276. uint32_t reserved_e0;
  277. uint32_t reserved_e4;
  278. uint32_t reserved_e8;
  279. uint32_t reserved_ec;
  280. uint32_t reserved_f0;
  281. uint32_t reserved_f4;
  282. uint32_t date; /**/
  283. uint32_t reserved_fc;
  284. uint32_t fifo_start_addr; /*This the start address for ram when use apb nonfifo access.*/
  285. } i2c_dev_t;
  286. extern i2c_dev_t I2C0;
  287. extern i2c_dev_t I2C1;
  288. #endif /* _SOC_I2C_STRUCT_H_ */