Skip to content

Commit

Permalink
1. modify i2c_set_pin function
Browse files Browse the repository at this point in the history
2. update example comments and other minor changes
3. rename API:  i2c_cmd_link_create/i2c_cmd_link_delete (+4 squashed commits)

Squashed commits:
[2e0ac3e] 1. coding style: add one space after condition key words.
2. modify i2c.h, use gpio_num_t instead of int, improve comments of return values
3. add i2c index in index.rst
4. add readme for i2c example
[4991d92] update i2c.doc
[88b672e] driver: i2c

1. add mux and spin lock to run in a thread-safe way.
2. modify example code
[4eb15fe] driver: i2c code

1. add i2c master code
2. add i2c slave code
3. add i2c example code
4. add DRAM_ATTR for I2C array
  • Loading branch information
costaud committed Jan 2, 2017
1 parent 370cf54 commit 9c7cc86
Show file tree
Hide file tree
Showing 10 changed files with 1,983 additions and 3 deletions.
1,037 changes: 1,037 additions & 0 deletions components/driver/i2c.c

Large diffs are not rendered by default.

514 changes: 514 additions & 0 deletions components/driver/include/driver/i2c.h

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions components/esp32/include/soc/i2c_reg.h
Expand Up @@ -261,6 +261,8 @@
#define I2C_RXFIFO_FULL_THRHD_V 0x1F
#define I2C_RXFIFO_FULL_THRHD_S 0

#define I2C_DATA_APB_REG(i) (0x60013000 + (i) * 0x14000 + 0x001c)

#define I2C_DATA_REG(i) (REG_I2C_BASE(i) + 0x001c)
/* I2C_FIFO_RDATA : RO ;bitpos:[7:0] ;default: 8'b0 ; */
/*description: The register represent the byte data read from rxfifo when use apb fifo access*/
Expand Down
6 changes: 3 additions & 3 deletions components/esp32/include/soc/i2c_struct.h
Expand Up @@ -16,7 +16,7 @@
typedef volatile struct {
union {
struct {
uint32_t scl_low_period:14; /*This register is used to configure the low level width of SCL clock.*/
uint32_t period:14; /*This register is used to configure the low level width of SCL clock.*/
uint32_t reserved14: 18;
};
uint32_t val;
Expand Down Expand Up @@ -58,7 +58,7 @@ typedef volatile struct {
} status_reg;
union {
struct {
uint32_t tout: 20; /*This register is used to configure the max clock number of receiving a data.*/
uint32_t tout: 20; /*This register is used to configure the max clock number of receiving a data, unit: APB clock cycle.*/
uint32_t reserved20:12;
};
uint32_t val;
Expand Down Expand Up @@ -282,7 +282,7 @@ typedef volatile struct {
uint32_t reserved_f4;
uint32_t date; /**/
uint32_t reserved_fc;
uint32_t fifo_start_addr; /*This the start address for ram when use apb nonfifo access.*/
uint32_t ram_data[32]; /*This the start address for ram when use apb nonfifo access.*/
} i2c_dev_t;
extern i2c_dev_t I2C0;
extern i2c_dev_t I2C1;
Expand Down
82 changes: 82 additions & 0 deletions docs/api/i2c.rst
@@ -0,0 +1,82 @@
I2C
===========

Overview
--------

ESP32 has two I2C controllers which can be set as master mode or slave mode.

Application Example
-------------------

I2C master and slave example: `examples/18_i2c <https://github.com/espressif/esp-idf/tree/master/examples/18_i2c>`_.

API Reference
-------------

Header Files
^^^^^^^^^^^^

* `driver/include/driver/i2c.h <https://github.com/espressif/esp-idf/blob/master/components/driver/include/driver/i2c.h>`_

Macros
^^^^^^

.. doxygendefine:: I2C_APB_CLK_FREQ
.. doxygendefine:: I2C_FIFO_LEN

Type Definitions
^^^^^^^^^^^^^^^^

.. doxygentypedef:: i2c_cmd_handle_t

Enumerations
^^^^^^^^^^^^

.. doxygenenum:: i2c_mode_t
.. doxygenenum:: i2c_rw_t
.. doxygenenum:: i2c_trans_mode_t
.. doxygenenum:: i2c_opmode_t
.. doxygenenum:: i2c_port_t
.. doxygenenum:: i2c_addr_mode_t

Structures
^^^^^^^^^^

.. doxygenstruct:: i2c_config_t
:members:


Functions
^^^^^^^^^

.. doxygenfunction:: i2c_driver_install
.. doxygenfunction:: i2c_driver_delete
.. doxygenfunction:: i2c_param_config
.. doxygenfunction:: i2c_reset_tx_fifo
.. doxygenfunction:: i2c_reset_rx_fifo
.. doxygenfunction:: i2c_isr_register
.. doxygenfunction:: i2c_isr_free
.. doxygenfunction:: i2c_set_pin
.. doxygenfunction:: i2c_master_start
.. doxygenfunction:: i2c_master_write_byte
.. doxygenfunction:: i2c_master_write
.. doxygenfunction:: i2c_master_read_byte
.. doxygenfunction:: i2c_master_read
.. doxygenfunction:: i2c_master_stop
.. doxygenfunction:: i2c_master_cmd_begin
.. doxygenfunction:: i2c_slave_write_buffer
.. doxygenfunction:: i2c_slave_read
.. doxygenfunction:: i2c_set_period
.. doxygenfunction:: i2s_get_period
.. doxygenfunction:: i2c_set_start_timing
.. doxygenfunction:: i2c_get_start_timing
.. doxygenfunction:: i2c_set_stop_timing
.. doxygenfunction:: i2c_get_stop_timing
.. doxygenfunction:: i2c_set_data_timing
.. doxygenfunction:: i2c_get_data_timing
.. doxygenfunction:: i2c_set_data_mode
.. doxygenfunction:: i2c_get_data_mode
.. doxygenfunction:: i2c_cmd_link_create
.. doxygenfunction:: i2c_cmd_link_delete

1 change: 1 addition & 0 deletions docs/index.rst
Expand Up @@ -107,6 +107,7 @@ Contents:
LED Control <api/ledc>
Remote Control <api/rmt>
Timer <api/timer>
I2C <api/i2c>
Pulse Counter <api/pcnt>
Sigma-delta Modulation <api/sigmadelta>
SPI Flash and Partition APIs <api/spi_flash>
Expand Down
9 changes: 9 additions & 0 deletions examples/18_i2c/Makefile
@@ -0,0 +1,9 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#

PROJECT_NAME := i2c

include $(IDF_PATH)/make/project.mk

29 changes: 29 additions & 0 deletions examples/18_i2c/README.md
@@ -0,0 +1,29 @@
# I2C Example


* This example will show you how to use I2C module by running two tasks on i2c bus:

* read external i2c sensor, here we use a BH1750 light sensor(GY-30 module) for instance.
* Use one I2C port(master mode) to read or write the other I2C port(slave mode) on one ESP32 chip.

* Pin assignment:

* slave :
* GPIO25 is assigned as the data signal of i2c slave port
* GPIO26 is assigned as the clock signal of i2c slave port
* master:
* GPIO18 is assigned as the data signal of i2c master port
* GPIO19 is assigned as the clock signal of i2c master port

* Connection:

* connect GPIO18 with GPIO25
* connect GPIO19 with GPIO26
* connect sda/scl of sensor with GPIO18/GPIO19
* no need to add external pull-up resistors, driver will enable internal pull-up resistors.

* Test items:

* read the sensor data, if connected.
* i2c master(ESP32) will write data to i2c slave(ESP32).
* i2c master(ESP32) will read data from i2c slave(ESP32).
3 changes: 3 additions & 0 deletions examples/18_i2c/main/component.mk
@@ -0,0 +1,3 @@
#
# Main Makefile. This is basically the same as a component makefile.
#

0 comments on commit 9c7cc86

Please sign in to comment.