mbed official / mbed

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

Committer:
AnnaBridge
Date:
Fri Sep 16 13:57:13 2016 +0100
Revision:
126:abea610beb85
Parent:
125:2e9cc70d1897
Child:
128:9bcdf88f62b0
Release 126 of the mbed library

Changes:

New Targets:
#2504: [Disco_F769NI] adding new target [https://github.com/ARMmbed/mbed-os/pull/2504]
#2654: DELTA_DFBM_NQ620 platform porting [https://github.com/ARMmbed/mbed-os/pull/2654]
#2615: [MTM_MTCONNECT04S] Added support for MTM_MTCONNECT04S [https://github.com/ARMmbed/mbed-os/pull/2615]
#2548: Nucleof303ze [https://github.com/ARMmbed/mbed-os/pull/2548]

Fixes:

#2657: [MAX326xx] Removed echoing of characters and carriage return. [https://github.com/ARMmbed/mbed-os/pull/2657]
#2651: Use lp_timer to count time in the deepsleep tests [https://github.com/ARMmbed/mbed-os/pull/2651]
#2643: Fix thread self termination [https://github.com/ARMmbed/mbed-os/pull/2643]
#2623: DISCO_L476VG - Add Serial Flow Control pins + add SERIAL_FC macro [https://github.com/ARMmbed/mbed-os/pull/2623]
#2617: STM32F2xx - Enable Serial Flow Control [https://github.com/ARMmbed/mbed-os/pull/2617]
#2601: Adding ON Semiconductor copyright notice to source and header files. [https://github.com/ARMmbed/mbed-os/pull/2601]
#2597: [HAL] Fixed "intrinsic is deprecated" warnings [https://github.com/ARMmbed/mbed-os/pull/2597]
#2589: [NUC472] Fix heap configuration error with armcc [https://github.com/ARMmbed/mbed-os/pull/2589]
#2587: add PTEx pins as option for SPI on Hexiwear - for SD Card Interface [https://github.com/ARMmbed/mbed-os/pull/2587]
#2584: Set size of callback irq array to IrqCnt [https://github.com/ARMmbed/mbed-os/pull/2584]
#2582: [GCC_CR] fix runtime hang for baremetal build [https://github.com/ARMmbed/mbed-os/pull/2582]
#2562: Fix GCC lazy init race condition and add test [https://github.com/ARMmbed/mbed-os/pull/2562]
#2538: STM32F4xx - Add support of ADC internal channels (Temp, VRef, VBat) [https://github.com/ARMmbed/mbed-os/pull/2538]
#2514: Updated FlexCan and SAI SDK drivers [https://github.com/ARMmbed/mbed-os/pull/2514]
#2442: Malloc heap info [https://github.com/ARMmbed/mbed-os/pull/2442]
#2419: [STM32F1] Add asynchronous serial [https://github.com/ARMmbed/mbed-os/pull/2419]
#2130: stm32 : reduce number of device.h files [https://github.com/ARMmbed/mbed-os/pull/2130]
#2678: Fixing NCS36510 compile on Linux [https://github.com/ARMmbed/mbed-os/pull/2678]
#2607: Fix uvisor memory tracing [https://github.com/ARMmbed/mbed-os/pull/2607]
#2596: [HAL] Improve memory tracer [https://github.com/ARMmbed/mbed-os/pull/2596]
#2487: Runtime dynamic memory tracing [https://github.com/ARMmbed/mbed-os/pull/2487]

Who changed what in which revision?

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