this hurts

Dependencies:   FFT

Committer:
shyamgatech
Date:
Thu Dec 03 18:15:35 2020 +0000
Revision:
7:0d62545e6d73
Parent:
0:d6c9b09b4042
addded gui mbed code;

Who changed what in which revision?

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