mbed-dev-f303

Committer:
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4
Date:
Tue Jun 14 09:21:18 2022 +0000
Revision:
0:bdf663c61a82
lib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 1
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 2 /** \addtogroup hal */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 3 /** @{*/
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 4 /* mbed Microcontroller Library
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 5 * Copyright (c) 2006-2015 ARM Limited
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 6 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 7 * Licensed under the Apache License, Version 2.0 (the "License");
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 8 * you may not use this file except in compliance with the License.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 9 * You may obtain a copy of the License at
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 10 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 11 * http://www.apache.org/licenses/LICENSE-2.0
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 12 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 13 * Unless required by applicable law or agreed to in writing, software
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 14 * distributed under the License is distributed on an "AS IS" BASIS,
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 16 * See the License for the specific language governing permissions and
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 17 * limitations under the License.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 18 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 19 #ifndef MBED_I2C_API_H
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 20 #define MBED_I2C_API_H
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 21
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 22 #include "device.h"
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 23 #include "hal/buffer.h"
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 24
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 25 #if DEVICE_I2C_ASYNCH
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 26 #include "hal/dma_api.h"
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 27 #endif
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 28
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 29 #if DEVICE_I2C
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 30
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 31 /**
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 32 * @defgroup hal_I2CEvents I2C Events Macros
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 33 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 34 * @{
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 35 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 36 #define I2C_EVENT_ERROR (1 << 1)
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 37 #define I2C_EVENT_ERROR_NO_SLAVE (1 << 2)
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 38 #define I2C_EVENT_TRANSFER_COMPLETE (1 << 3)
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 39 #define I2C_EVENT_TRANSFER_EARLY_NACK (1 << 4)
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 40 #define I2C_EVENT_ALL (I2C_EVENT_ERROR | I2C_EVENT_TRANSFER_COMPLETE | I2C_EVENT_ERROR_NO_SLAVE | I2C_EVENT_TRANSFER_EARLY_NACK)
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 41
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 42 /**@}*/
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 43
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 44 #if DEVICE_I2C_ASYNCH
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 45 /** Asynch I2C HAL structure
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 46 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 47 typedef struct {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 48 struct i2c_s i2c; /**< Target specific I2C structure */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 49 struct buffer_s tx_buff; /**< Tx buffer */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 50 struct buffer_s rx_buff; /**< Rx buffer */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 51 } i2c_t;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 52
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 53 #else
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 54 /** Non-asynch I2C HAL structure
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 55 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 56 typedef struct i2c_s i2c_t;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 57
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 58 #endif
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 59
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 60 enum {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 61 I2C_ERROR_NO_SLAVE = -1,
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 62 I2C_ERROR_BUS_BUSY = -2
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 63 };
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 64
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 65 #ifdef __cplusplus
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 66 extern "C" {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 67 #endif
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 68
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 69 /**
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 70 * \defgroup hal_GeneralI2C I2C Configuration Functions
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 71 * @{
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 72 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 73
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 74 /** Initialize the I2C peripheral. It sets the default parameters for I2C
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 75 * peripheral, and configures its specifieds pins.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 76 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 77 * @param obj The I2C object
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 78 * @param sda The sda pin
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 79 * @param scl The scl pin
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 80 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 81 void i2c_init(i2c_t *obj, PinName sda, PinName scl);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 82
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 83 /** Configure the I2C frequency
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 84 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 85 * @param obj The I2C object
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 86 * @param hz Frequency in Hz
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 87 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 88 void i2c_frequency(i2c_t *obj, int hz);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 89
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 90 /** Send START command
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 91 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 92 * @param obj The I2C object
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 93 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 94 int i2c_start(i2c_t *obj);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 95
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 96 /** Send STOP command
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 97 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 98 * @param obj The I2C object
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 99 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 100 int i2c_stop(i2c_t *obj);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 101
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 102 /** Blocking reading data
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 103 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 104 * @param obj The I2C object
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 105 * @param address 7-bit address (last bit is 1)
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 106 * @param data The buffer for receiving
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 107 * @param length Number of bytes to read
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 108 * @param stop Stop to be generated after the transfer is done
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 109 * @return Number of read bytes
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 110 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 111 int i2c_read(i2c_t *obj, int address, char *data, int length, int stop);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 112
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 113 /** Blocking sending data
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 114 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 115 * @param obj The I2C object
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 116 * @param address 7-bit address (last bit is 0)
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 117 * @param data The buffer for sending
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 118 * @param length Number of bytes to write
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 119 * @param stop Stop to be generated after the transfer is done
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 120 * @return
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 121 * zero or non-zero - Number of written bytes
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 122 * negative - I2C_ERROR_XXX status
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 123 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 124 int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 125
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 126 /** Reset I2C peripheral. TODO: The action here. Most of the implementation sends stop()
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 127 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 128 * @param obj The I2C object
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 129 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 130 void i2c_reset(i2c_t *obj);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 131
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 132 /** Read one byte
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 133 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 134 * @param obj The I2C object
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 135 * @param last Acknoledge
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 136 * @return The read byte
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 137 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 138 int i2c_byte_read(i2c_t *obj, int last);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 139
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 140 /** Write one byte
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 141 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 142 * @param obj The I2C object
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 143 * @param data Byte to be written
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 144 * @return 0 if NAK was received, 1 if ACK was received, 2 for timeout.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 145 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 146 int i2c_byte_write(i2c_t *obj, int data);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 147
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 148 /**@}*/
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 149
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 150 #if DEVICE_I2CSLAVE
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 151
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 152 /**
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 153 * \defgroup SynchI2C Synchronous I2C Hardware Abstraction Layer for slave
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 154 * @{
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 155 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 156
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 157 /** Configure I2C as slave or master.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 158 * @param obj The I2C object
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 159 * @param enable_slave Enable i2c hardware so you can receive events with ::i2c_slave_receive
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 160 * @return non-zero if a value is available
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 161 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 162 void i2c_slave_mode(i2c_t *obj, int enable_slave);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 163
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 164 /** Check to see if the I2C slave has been addressed.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 165 * @param obj The I2C object
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 166 * @return The status - 1 - read addresses, 2 - write to all slaves,
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 167 * 3 write addressed, 0 - the slave has not been addressed
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 168 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 169 int i2c_slave_receive(i2c_t *obj);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 170
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 171 /** Configure I2C as slave or master.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 172 * @param obj The I2C object
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 173 * @param data The buffer for receiving
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 174 * @param length Number of bytes to read
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 175 * @return non-zero if a value is available
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 176 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 177 int i2c_slave_read(i2c_t *obj, char *data, int length);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 178
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 179 /** Configure I2C as slave or master.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 180 * @param obj The I2C object
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 181 * @param data The buffer for sending
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 182 * @param length Number of bytes to write
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 183 * @return non-zero if a value is available
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 184 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 185 int i2c_slave_write(i2c_t *obj, const char *data, int length);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 186
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 187 /** Configure I2C address.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 188 * @param obj The I2C object
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 189 * @param idx Currently not used
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 190 * @param address The address to be set
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 191 * @param mask Currently not used
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 192 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 193 void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 194
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 195 #endif
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 196
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 197 /**@}*/
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 198
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 199 #if DEVICE_I2C_ASYNCH
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 200
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 201 /**
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 202 * \defgroup hal_AsynchI2C Asynchronous I2C Hardware Abstraction Layer
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 203 * @{
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 204 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 205
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 206 /** Start I2C asynchronous transfer
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 207 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 208 * @param obj The I2C object
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 209 * @param tx The transmit buffer
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 210 * @param tx_length The number of bytes to transmit
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 211 * @param rx The receive buffer
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 212 * @param rx_length The number of bytes to receive
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 213 * @param address The address to be set - 7bit or 9bit
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 214 * @param stop If true, stop will be generated after the transfer is done
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 215 * @param handler The I2C IRQ handler to be set
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 216 * @param event Event mask for the transfer. See \ref hal_I2CEvents
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 217 * @param hint DMA hint usage
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 218 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 219 void i2c_transfer_asynch(i2c_t *obj, const void *tx, size_t tx_length, void *rx, size_t rx_length, uint32_t address, uint32_t stop, uint32_t handler, uint32_t event, DMAUsage hint);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 220
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 221 /** The asynchronous IRQ handler
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 222 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 223 * @param obj The I2C object which holds the transfer information
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 224 * @return Event flags if a transfer termination condition was met, otherwise return 0.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 225 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 226 uint32_t i2c_irq_handler_asynch(i2c_t *obj);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 227
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 228 /** Attempts to determine if the I2C peripheral is already in use
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 229 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 230 * @param obj The I2C object
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 231 * @return Non-zero if the I2C module is active or zero if it is not
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 232 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 233 uint8_t i2c_active(i2c_t *obj);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 234
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 235 /** Abort asynchronous transfer
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 236 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 237 * This function does not perform any check - that should happen in upper layers.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 238 * @param obj The I2C object
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 239 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 240 void i2c_abort_asynch(i2c_t *obj);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 241
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 242 #endif
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 243
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 244 /**@}*/
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 245
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 246 #ifdef __cplusplus
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 247 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 248 #endif
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 249
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 250 #endif
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 251
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 252 #endif
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 253
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 254 /** @}*/
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 255