mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Tue Nov 08 17:45:16 2016 +0000
Revision:
151:02e0a0aed4ec
Parent:
149:156823d33999
This updates the lib to the mbed lib v129

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1 /**
<> 149:156823d33999 2 ******************************************************************************
<> 149:156823d33999 3 * @file i2c.h
<> 149:156823d33999 4 * @brief (API) Public header of i2c driver
<> 149:156823d33999 5 * @internal
<> 149:156823d33999 6 * @author ON Semiconductor
<> 149:156823d33999 7 * $Rev: $
<> 149:156823d33999 8 * $Date: 2016-04-20 $
<> 149:156823d33999 9 ******************************************************************************
<> 149:156823d33999 10 * Copyright 2016 Semiconductor Components Industries LLC (d/b/a “ON Semiconductor”).
<> 149:156823d33999 11 * All rights reserved. This software and/or documentation is licensed by ON Semiconductor
<> 149:156823d33999 12 * under limited terms and conditions. The terms and conditions pertaining to the software
<> 149:156823d33999 13 * and/or documentation are available at http://www.onsemi.com/site/pdf/ONSEMI_T&C.pdf
<> 149:156823d33999 14 * (“ON Semiconductor Standard Terms and Conditions of Sale, Section 8 Software”) and
<> 149:156823d33999 15 * if applicable the software license agreement. Do not use this software and/or
<> 149:156823d33999 16 * documentation unless you have carefully read and you agree to the limited terms and
<> 149:156823d33999 17 * conditions. By using this software and/or documentation, you agree to the limited
<> 149:156823d33999 18 * terms and conditions.
<> 149:156823d33999 19 *
<> 149:156823d33999 20 * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
<> 149:156823d33999 21 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
<> 149:156823d33999 22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
<> 149:156823d33999 23 * ON SEMICONDUCTOR SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL,
<> 149:156823d33999 24 * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
<> 149:156823d33999 25 * @endinternal
<> 149:156823d33999 26 *
<> 149:156823d33999 27 * @ingroup i2c
<> 149:156823d33999 28 */
<> 149:156823d33999 29
<> 149:156823d33999 30 #include "mbed_assert.h"
<> 149:156823d33999 31 #include "i2c_api.h"
<> 149:156823d33999 32 #include "clock.h"
<> 149:156823d33999 33 #include "i2c_ipc7208_map.h"
<> 149:156823d33999 34 #include "memory_map.h"
<> 149:156823d33999 35 #include "PeripheralPins.h"
<> 149:156823d33999 36
<> 149:156823d33999 37 #ifndef I2C_H_
<> 149:156823d33999 38 #define I2C_H_
<> 149:156823d33999 39
<> 149:156823d33999 40 /* Miscellaneous I/O and control operations codes */
<> 149:156823d33999 41 #define I2C_IPC7208_IOCTL_NOT_ACK 0x03
<> 149:156823d33999 42 #define I2C_IPC7208_IOCTL_NULL_CMD 0x04
<> 149:156823d33999 43 #define I2C_IPC7208_IOCTL_ACK 0x05
<> 149:156823d33999 44
<> 149:156823d33999 45 /* Definitions for the clock speed. */
<> 149:156823d33999 46 #define I2C_SPEED_100K_AT_8MHZ (uint8_t)0x12
<> 149:156823d33999 47 #define I2C_SPEED_100K_AT_16MHZ (uint8_t)0x26
<> 149:156823d33999 48 #define I2C_SPEED_400K_AT_8MHZ (uint8_t)0x03
<> 149:156823d33999 49 #define I2C_SPEED_400K_AT_16MHZ (uint8_t)0x08
<> 149:156823d33999 50
<> 149:156823d33999 51
<> 149:156823d33999 52 /* I2C commands */
<> 149:156823d33999 53 #define I2C_CMD_NULL 0x00
<> 149:156823d33999 54 #define I2C_CMD_WDAT0 0x10
<> 149:156823d33999 55 #define I2C_CMD_WDAT1 0x11
<> 149:156823d33999 56 #define I2C_CMD_WDAT8 0x12
<> 149:156823d33999 57 #define I2C_CMD_RDAT8 0x13
<> 149:156823d33999 58 #define I2C_CMD_STOP 0x14
<> 149:156823d33999 59 #define I2C_CMD_START 0x15
<> 149:156823d33999 60 #define I2C_CMD_VRFY_ACK 0x16
<> 149:156823d33999 61 #define I2C_CMD_VRFY_VACK 0x17
<> 149:156823d33999 62
<> 149:156823d33999 63 /* Status register bits */
<> 149:156823d33999 64 #define I2C_STATUS_CMD_FIFO_MPTY_BIT 0x01
<> 149:156823d33999 65 #define I2C_STATUS_RD_DATA_RDY_BIT 0x02
<> 149:156823d33999 66 #define I2C_STATUS_BUS_ERR_BIT 0x04
<> 149:156823d33999 67 #define I2C_STATUS_RD_DATA_UFL_BIT 0x08
<> 149:156823d33999 68 #define I2C_STATUS_CMD_FIFO_OFL_BIT 0x10
<> 149:156823d33999 69 #define I2C_STATUS_CMD_FIFO_FULL_BIT 0x20
<> 149:156823d33999 70
<> 149:156823d33999 71 /* I2C return status */
<> 149:156823d33999 72 #define I2C_STATUS_INVALID 0xFF
<> 149:156823d33999 73 #define I2C_STATUS_SUCCESS 0x00
<> 149:156823d33999 74 #define I2C_STATUS_FAIL 0x01
<> 149:156823d33999 75 #define I2C_STATUS_BUS_ERROR 0x02
<> 149:156823d33999 76 #define I2C_STATUS_RD_DATA_UFL 0x03
<> 149:156823d33999 77 #define I2C_STATUS_CMD_FIFO_OFL 0x04
<> 149:156823d33999 78 #define I2C_STATUS_INTERRUPT_ERROR 0x05
<> 149:156823d33999 79 #define I2C_STATUS_CMD_FIFO_EMPTY 0x06
<> 149:156823d33999 80
<> 149:156823d33999 81 /* I2C clock divider position */
<> 149:156823d33999 82 #define I2C_CLOCKDIVEDER_VAL_MASK 0x1F
<> 149:156823d33999 83 #define I2C_APB_CLK_DIVIDER_VAL_MASK 0x1FE0
<> 149:156823d33999 84
<> 149:156823d33999 85 /* Error check */
<> 149:156823d33999 86 #define I2C_UFL_CHECK (d->membase->STATUS.WORD & 0x80)
<> 149:156823d33999 87 #define FIFO_OFL_CHECK (d->membase->STATUS.WORD & 0x10)
<> 149:156823d33999 88 #define I2C_BUS_ERR_CHECK (d->membase->STATUS.WORD & 0x04)
<> 149:156823d33999 89 #define RD_DATA_READY (d->membase->STATUS.WORD & 0x02)
<> 149:156823d33999 90
<> 149:156823d33999 91 #define I2C_API_STATUS_SUCCESS 0
<> 149:156823d33999 92 #define PAD_REG_ADRS_BYTE_SIZE 4
<> 149:156823d33999 93
<> 149:156823d33999 94 /** Init I2C device.
<> 149:156823d33999 95 * @details
<> 149:156823d33999 96 * Sets the necessary registers. The baud rate is set default to 100K
<> 149:156823d33999 97 *
<> 149:156823d33999 98 * @param obj A I2C device instance.
<> 149:156823d33999 99 * @param sda GPIO number for SDA line
<> 149:156823d33999 100 * @param scl GPIO number for SCL line
<> 149:156823d33999 101 * @return None
<> 149:156823d33999 102 */
<> 149:156823d33999 103 extern void fI2cInit(i2c_t *obj,PinName sda,PinName scl);
<> 149:156823d33999 104
<> 149:156823d33999 105 /** Set baud rate or frequency
<> 149:156823d33999 106 * @details
<> 149:156823d33999 107 * Sets user baudrate
<> 149:156823d33999 108 *
<> 149:156823d33999 109 * @param obj A I2C device instance.
<> 149:156823d33999 110 * @param hz User desired baud rate/frequency
<> 149:156823d33999 111 * @return None
<> 149:156823d33999 112 */
<> 149:156823d33999 113 extern void fI2cFrequency(i2c_t *obj, uint32_t hz);
<> 149:156823d33999 114
<> 149:156823d33999 115 /** Sends start bit
<> 149:156823d33999 116 * @details
<> 149:156823d33999 117 * Sends start bit on i2c pins
<> 149:156823d33999 118 *
<> 149:156823d33999 119 * @param obj A I2C device instance.
<> 149:156823d33999 120 * @return status
<> 149:156823d33999 121 */
<> 149:156823d33999 122 extern int32_t fI2cStart(i2c_t *obj);
<> 149:156823d33999 123
<> 149:156823d33999 124 /** Sends stop bit
<> 149:156823d33999 125 * @details
<> 149:156823d33999 126 * Sends stop bit on i2c pins
<> 149:156823d33999 127 *
<> 149:156823d33999 128 * @param obj A I2C device instance.
<> 149:156823d33999 129 * @return status
<> 149:156823d33999 130 */
<> 149:156823d33999 131 extern int32_t fI2cStop(i2c_t *obj);
<> 149:156823d33999 132
<> 149:156823d33999 133 /** Reads data from a I2C device in blocking fashion.
<> 149:156823d33999 134 * @details
<> 149:156823d33999 135 * The data is read from the receive queue into the buffer. The receive queue is
<> 149:156823d33999 136 * filled by the interrupt handler. If not enough data is available,
<> 149:156823d33999 137 *
<> 149:156823d33999 138 * @param d The device to read from.
<> 149:156823d33999 139 * @param buf The buffer to read into (only the contents of the buffer may be modified, not the buffer itself).
<> 149:156823d33999 140 * @param len The maximum number of bytes to read, typically the buffer length.
<> 149:156823d33999 141 * @return On Success: The actual number of bytes read. On Failure: Failure code.
<> 149:156823d33999 142 */
<> 149:156823d33999 143 extern int32_t fI2cReadB(i2c_t *d, char *buf, int len);
<> 149:156823d33999 144
<> 149:156823d33999 145 /** Write data to an I2C device.
<> 149:156823d33999 146 * @details
<> 149:156823d33999 147 * The commands(I2C instructions) and data arrive at the I2C Engine via the Command FIFO.
<> 149:156823d33999 148 * The command to write the data & data to be written is sent to command FIFO by writing it into command register.
<> 149:156823d33999 149 *
<> 149:156823d33999 150 * @param d The device to write to.
<> 149:156823d33999 151 * @param buf The buffer to write from (the contents of the buffer may not be modified).
<> 149:156823d33999 152 * @param len The number of bytes to write.
<> 149:156823d33999 153 * @return On success: The actual number of bytes written. On Failure: Failure code
<> 149:156823d33999 154 */
<> 149:156823d33999 155 extern int32_t fI2cWriteB(i2c_t *d, const char *buf, int len);
<> 149:156823d33999 156
<> 149:156823d33999 157 #endif /* I2C_H_ */