Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Revision:
1:9db0e321a9f4
Parent:
0:5b88d5760320
--- a/hal/i2c_api.h	Tue Dec 17 23:23:45 2019 +0000
+++ b/hal/i2c_api.h	Tue Dec 31 06:02:27 2019 +0000
@@ -64,15 +64,94 @@
     I2C_ERROR_BUS_BUSY = -2
 };
 
+typedef struct {
+    int peripheral;
+    PinName sda_pin;
+    int sda_function;
+    PinName scl_pin;
+    int scl_function;
+} i2c_pinmap_t;
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 /**
  * \defgroup hal_GeneralI2C I2C Configuration Functions
+ *
+ * # Defined behavior
+ * * ::i2c_init initializes i2c_t control structure
+ * * ::i2c_init configures the pins used by I2C
+ * * ::i2c_free returns the pins owned by the I2C object to their reset state
+ * * ::i2c_frequency configure the I2C frequency
+ * * ::i2c_start sends START command
+ * * ::i2c_read reads `length` bytes from the I2C slave specified by `address` to the `data` buffer
+ * * ::i2c_read reads generates a stop condition on the bus at the end of the transfer if `stop` parameter is non-zero
+ * * ::i2c_read reads returns the number of symbols received from the bus
+ * * ::i2c_write writes `length` bytes to the I2C slave specified by `address` from the `data` buffer
+ * * ::i2c_write generates a stop condition on the bus at the end of the transfer if `stop` parameter is non-zero
+ * * ::i2c_write returns zero on success, error code otherwise
+ * * ::i2c_reset resets the I2C peripheral
+ * * ::i2c_byte_read reads and return one byte from the specfied I2C slave
+ * * ::i2c_byte_read uses `last` parameter to inform the slave that all bytes have been read
+ * * ::i2c_byte_write writes one byte to the specified I2C slave
+ * * ::i2c_byte_write returns 0 if NAK was received, 1 if ACK was received, 2 for timeout
+ * * ::i2c_slave_mode enables/disables I2S slave mode
+ * * ::i2c_slave_receive returns: 1 - read addresses, 2 - write to all slaves, 3 write addressed, 0 - the slave has not been addressed
+ * * ::i2c_slave_read reads `length` bytes from the I2C master to the `data` buffer
+ * * ::i2c_slave_read returns non-zero if a value is available, 0 otherwise
+ * * ::i2c_slave_write writes `length` bytes to the I2C master from the `data` buffer
+ * * ::i2c_slave_write returns non-zero if a value is available, 0 otherwise
+ * * ::i2c_slave_address configures I2C slave address
+ * * ::i2c_transfer_asynch starts I2C asynchronous transfer
+ * * ::i2c_transfer_asynch writes `tx_length` bytes to the I2C slave specified by `address` from the `tx` buffer
+ * * ::i2c_transfer_asynch reads `rx_length` bytes from the I2C slave specified by `address` to the `rx` buffer
+ * * ::i2c_transfer_asynch generates a stop condition on the bus at the end of the transfer if `stop` parameter is non-zero
+ * * The callback given to ::i2c_transfer_asynch is invoked when the transfer completes
+ * * ::i2c_transfer_asynch specifies the logical OR of events to be registered
+ * * The ::i2c_transfer_asynch function may use the `DMAUsage` hint to select the appropriate async algorithm
+ * * ::i2c_irq_handler_asynch returns event flags if a transfer termination condition was met, otherwise returns 0.
+ * * ::i2c_active returns non-zero if the I2C module is active or 0 if it is not
+ * * ::i2c_abort_asynch aborts an on-going async transfer
+ *
+ * # Undefined behavior
+ * * Calling ::i2c_init multiple times on the same `i2c_t`
+ * * Calling any function other than ::i2c_init on a non-initialized `i2c_t`
+ * * Initialising the `I2C` peripheral with invalid `SDA` and `SCL` pins.
+ * * Passing pins that cannot be on the same peripheral
+ * * Passing an invalid pointer as `obj` to any function
+ * * Use of a `null` pointer as an argument to any function.
+ * * Initialising the peripheral in slave mode if slave mode is not supported
+ * * Operating the peripheral in slave mode without first specifying and address using ::i2c_slave_address
+ * * Setting an address using i2c_slave_address after initialising the peripheral in master mode
+ * * Setting an address to an `I2C` reserved value
+ * * Specifying an invalid address when calling any `read` or `write` functions
+ * * Setting the length of the transfer or receive buffers to larger than the buffers are
+ * * Passing an invalid pointer as `handler`
+ * * Calling ::i2c_abort_async when no transfer is currently in progress
+ *
+ *
  * @{
  */
 
+/**
+ * \defgroup hal_GeneralI2C_tests I2C hal tests
+ * The I2C HAL tests ensure driver conformance to defined behaviour.
+ *
+ * To run the I2C hal tests use the command:
+ *
+ *     mbed test -t <toolchain> -m <target> -n tests-mbed_hal_fpga_ci_test_shield-i2c
+ *
+ */
+
+/** Initialize the I2C peripheral. It sets the default parameters for I2C
+ *  peripheral, and configures its specifieds pins.
+ *
+ *  @param obj  The I2C object
+ *  @param pinmap  Pinmap pointer to structure which holds static pinmap
+ */
+void i2c_init_direct(i2c_t *obj, const i2c_pinmap_t *pinmap);
+
 /** Initialize the I2C peripheral. It sets the default parameters for I2C
  *  peripheral, and configures its specifieds pins.
  *
@@ -82,6 +161,13 @@
  */
 void i2c_init(i2c_t *obj, PinName sda, PinName scl);
 
+/** Release a I2C object
+ *
+ * Return the pins owned by the I2C object to their reset state
+ * @param obj The I2C object to deinitialize
+ */
+void i2c_free(i2c_t *obj);
+
 /** Configure the I2C frequency
  *
  *  @param obj The I2C object