stm32: i2c: provide "transfer" level helper routines

For both v1 and v2, provide routines to help do arbitrary length
write/read transfers.

Tested with multiple byte writes and reads, for both 100khz and 400khz,
with repeated starts and stop/starts.  However, only tested (presently)
with a single i2c target device, a Sensiron SHT21 sensor.  Extended
testing against eeproms and alternative devices would be useful
This commit is contained in:
Karl Palsson
2017-03-24 00:10:44 +00:00
parent fb3b5e08f3
commit b40c72828d
4 changed files with 146 additions and 0 deletions

View File

@@ -34,6 +34,9 @@ specific memorymap.h header before including this header file.*/
#ifndef LIBOPENCM3_I2C_COMMON_V1_H
#define LIBOPENCM3_I2C_COMMON_V1_H
#include <stddef.h>
#include <stdint.h>
/* --- Convenience macros -------------------------------------------------- */
/* I2C register base addresses (for convenience) */
@@ -391,6 +394,7 @@ void i2c_enable_dma(uint32_t i2c);
void i2c_disable_dma(uint32_t i2c);
void i2c_set_dma_last_transfer(uint32_t i2c);
void i2c_clear_dma_last_transfer(uint32_t i2c);
void i2c_transfer7(uint32_t i2c, uint8_t addr, uint8_t *w, size_t wn, uint8_t *r, size_t rn);
END_DECLS

View File

@@ -31,6 +31,9 @@ specific memorymap.h header before including this header file.*/
#ifndef LIBOPENCM3_I2C_COMMON_V2_H
#define LIBOPENCM3_I2C_COMMON_V2_H
#include <stddef.h>
#include <stdint.h>
/* --- Convenience macros -------------------------------------------------- */
/* I2C register base addresses (for convenience) */
@@ -427,6 +430,7 @@ void i2c_enable_rxdma(uint32_t i2c);
void i2c_disable_rxdma(uint32_t i2c);
void i2c_enable_txdma(uint32_t i2c);
void i2c_disable_txdma(uint32_t i2c);
void i2c_transfer7(uint32_t i2c, uint8_t addr, uint8_t *w, size_t wn, uint8_t *r, size_t rn);
END_DECLS