summaryrefslogtreecommitdiff
path: root/docs/i2c_driver.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/i2c_driver.md')
-rw-r--r--docs/i2c_driver.md24
1 files changed, 12 insertions, 12 deletions
diff --git a/docs/i2c_driver.md b/docs/i2c_driver.md
index c9f53ef0d6..d28a20fa16 100644
--- a/docs/i2c_driver.md
+++ b/docs/i2c_driver.md
@@ -1,8 +1,8 @@
-# I2C Master Driver
+# I2C Master Driver :id=i2c-master-driver
The I2C Master drivers used in QMK have a set of common functions to allow portability between MCUs.
-## An important note on I2C Addresses
+## An important note on I2C Addresses :id=note-on-i2c-addresses
All of the addresses expected by this driver should be pushed to the upper 7 bits of the address byte. Setting
the lower bit (indicating read/write) will be done by the respective functions. Almost all I2C addresses listed
@@ -15,7 +15,7 @@ You can either do this on each call to the functions below, or once in your defi
See https://www.robot-electronics.co.uk/i2c-tutorial for more information about I2C addressing and other technical details.
-## Available functions
+## Available functions :id=available-functions
|Function |Description |
|------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
@@ -27,7 +27,7 @@ See https://www.robot-electronics.co.uk/i2c-tutorial for more information about
|`i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);` |Same as the `i2c_receive` function but `regaddr` sets from where in the slave the data will be read. |
|`i2c_status_t i2c_stop(void);` |Ends an I2C transaction. |
-### Function Return
+### Function Return :id=function-return
All the above functions, except `void i2c_init(void);` return the following truth table:
@@ -38,9 +38,9 @@ All the above functions, except `void i2c_init(void);` return the following trut
|`I2C_STATUS_TIMEOUT`|-2 |Operation timed out. |
-## AVR
+## AVR :id=avr
-### Configuration
+### Configuration :id=avr-configuration
The following defines can be used to configure the I2C master driver.
@@ -50,12 +50,12 @@ The following defines can be used to configure the I2C master driver.
AVRs usually have set GPIO which turn into I2C pins, therefore no further configuration is required.
-## ARM
+## ARM :id=arm
For ARM the Chibios I2C HAL driver is under the hood.
This section assumes an STM32 MCU.
-### Configuration
+### Configuration :id=arm-configuration
The configuration for ARM MCUs can be quite complex as often there are multiple I2C drivers which can be assigned to a variety of ports.
@@ -90,7 +90,7 @@ The ChibiOS I2C driver configuration depends on STM32 MCU:
STM32F1xx, STM32F2xx, STM32F4xx, STM32L0xx and STM32L1xx use I2Cv1;
STM32F0xx, STM32F3xx, STM32F7xx and STM32L4xx use I2Cv2;
-#### I2Cv1
+#### I2Cv1 :id=i2cv1
STM32 MCUs allow for different clock and duty parameters when configuring I2Cv1. These can be modified using the following parameters, using <https://www.playembedded.org/blog/stm32-i2c-chibios/#I2Cv1_configuration_structure> as a reference:
| Variable | Default |
@@ -99,7 +99,7 @@ STM32 MCUs allow for different clock and duty parameters when configuring I2Cv1.
| `I2C1_CLOCK_SPEED` | `100000` |
| `I2C1_DUTY_CYCLE` | `STD_DUTY_CYCLE` |
-#### I2Cv2
+#### I2Cv2 :id=i2cv2
STM32 MCUs allow for different timing parameters when configuring I2Cv2. These can be modified using the following parameters, using <https://www.st.com/en/embedded-software/stsw-stm32126.html> as a reference:
| Variable | Default |
@@ -117,10 +117,10 @@ STM32 MCUs allow for different "alternate function" modes when configuring GPIO
| `I2C1_SCL_PAL_MODE` | `4` |
| `I2C1_SDA_PAL_MODE` | `4` |
-#### Other
+#### Other :id=other
You can also overload the `void i2c_init(void)` function, which has a weak attribute. If you do this the configuration variables above will not be used. Please consult the datasheet of your MCU for the available GPIO configurations. The following is an example initialization function:
-```C
+```c
void i2c_init(void)
{
setPinInput(B6); // Try releasing special pins for a short time