Fork of mbed-dev build 137, last build before FAT file system appears to be broken. Also reduced HSE timeout time in STM4XX HAL
Fork of mbed-dev by
targets/TARGET_Maxim/TARGET_MAX32625/mxc/i2cs.h@150:02e0a0aed4ec, 2016-11-08 (annotated)
- Committer:
- <>
- Date:
- Tue Nov 08 17:45:16 2016 +0000
- Revision:
- 150:02e0a0aed4ec
This updates the lib to the mbed lib v129
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 150:02e0a0aed4ec | 1 | /** |
<> | 150:02e0a0aed4ec | 2 | * @file i2cs.h |
<> | 150:02e0a0aed4ec | 3 | * @brief I2CS (Inter-Integrated Circuit Slave) function prototypes and data types. |
<> | 150:02e0a0aed4ec | 4 | */ |
<> | 150:02e0a0aed4ec | 5 | |
<> | 150:02e0a0aed4ec | 6 | /* **************************************************************************** |
<> | 150:02e0a0aed4ec | 7 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
<> | 150:02e0a0aed4ec | 8 | * |
<> | 150:02e0a0aed4ec | 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
<> | 150:02e0a0aed4ec | 10 | * copy of this software and associated documentation files (the "Software"), |
<> | 150:02e0a0aed4ec | 11 | * to deal in the Software without restriction, including without limitation |
<> | 150:02e0a0aed4ec | 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
<> | 150:02e0a0aed4ec | 13 | * and/or sell copies of the Software, and to permit persons to whom the |
<> | 150:02e0a0aed4ec | 14 | * Software is furnished to do so, subject to the following conditions: |
<> | 150:02e0a0aed4ec | 15 | * |
<> | 150:02e0a0aed4ec | 16 | * The above copyright notice and this permission notice shall be included |
<> | 150:02e0a0aed4ec | 17 | * in all copies or substantial portions of the Software. |
<> | 150:02e0a0aed4ec | 18 | * |
<> | 150:02e0a0aed4ec | 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
<> | 150:02e0a0aed4ec | 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
<> | 150:02e0a0aed4ec | 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
<> | 150:02e0a0aed4ec | 22 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
<> | 150:02e0a0aed4ec | 23 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
<> | 150:02e0a0aed4ec | 24 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
<> | 150:02e0a0aed4ec | 25 | * OTHER DEALINGS IN THE SOFTWARE. |
<> | 150:02e0a0aed4ec | 26 | * |
<> | 150:02e0a0aed4ec | 27 | * Except as contained in this notice, the name of Maxim Integrated |
<> | 150:02e0a0aed4ec | 28 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
<> | 150:02e0a0aed4ec | 29 | * Products, Inc. Branding Policy. |
<> | 150:02e0a0aed4ec | 30 | * |
<> | 150:02e0a0aed4ec | 31 | * The mere transfer of this software does not imply any licenses |
<> | 150:02e0a0aed4ec | 32 | * of trade secrets, proprietary technology, copyrights, patents, |
<> | 150:02e0a0aed4ec | 33 | * trademarks, maskwork rights, or any other form of intellectual |
<> | 150:02e0a0aed4ec | 34 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
<> | 150:02e0a0aed4ec | 35 | * ownership rights. |
<> | 150:02e0a0aed4ec | 36 | * |
<> | 150:02e0a0aed4ec | 37 | * $Date: 2016-08-15 20:05:48 -0500 (Mon, 15 Aug 2016) $ |
<> | 150:02e0a0aed4ec | 38 | * $Revision: 24086 $ |
<> | 150:02e0a0aed4ec | 39 | * |
<> | 150:02e0a0aed4ec | 40 | *************************************************************************** */ |
<> | 150:02e0a0aed4ec | 41 | |
<> | 150:02e0a0aed4ec | 42 | /* Define to prevent redundant inclusion */ |
<> | 150:02e0a0aed4ec | 43 | #ifndef _I2CS_H_ |
<> | 150:02e0a0aed4ec | 44 | #define _I2CS_H_ |
<> | 150:02e0a0aed4ec | 45 | |
<> | 150:02e0a0aed4ec | 46 | /* **** Includes **** */ |
<> | 150:02e0a0aed4ec | 47 | #include "mxc_config.h" |
<> | 150:02e0a0aed4ec | 48 | #include "mxc_sys.h" |
<> | 150:02e0a0aed4ec | 49 | #include "mxc_assert.h" |
<> | 150:02e0a0aed4ec | 50 | #include "i2cs_regs.h" |
<> | 150:02e0a0aed4ec | 51 | |
<> | 150:02e0a0aed4ec | 52 | #ifdef __cplusplus |
<> | 150:02e0a0aed4ec | 53 | extern "C" { |
<> | 150:02e0a0aed4ec | 54 | #endif |
<> | 150:02e0a0aed4ec | 55 | |
<> | 150:02e0a0aed4ec | 56 | /** |
<> | 150:02e0a0aed4ec | 57 | * @defgroup i2cs I2C Slave |
<> | 150:02e0a0aed4ec | 58 | * @ingroup i2c_master_slave |
<> | 150:02e0a0aed4ec | 59 | * @brief I2C Slave (I2CS) API |
<> | 150:02e0a0aed4ec | 60 | * @{ |
<> | 150:02e0a0aed4ec | 61 | */ |
<> | 150:02e0a0aed4ec | 62 | |
<> | 150:02e0a0aed4ec | 63 | /* **** Definitions **** */ |
<> | 150:02e0a0aed4ec | 64 | /** |
<> | 150:02e0a0aed4ec | 65 | * Internal buffer size for storing I2C Slave Messages |
<> | 150:02e0a0aed4ec | 66 | */ |
<> | 150:02e0a0aed4ec | 67 | #define I2CS_BUFFER_SIZE 32 |
<> | 150:02e0a0aed4ec | 68 | |
<> | 150:02e0a0aed4ec | 69 | /** |
<> | 150:02e0a0aed4ec | 70 | * Enumeration type to select supported I2CS frequencies. |
<> | 150:02e0a0aed4ec | 71 | */ |
<> | 150:02e0a0aed4ec | 72 | typedef enum { |
<> | 150:02e0a0aed4ec | 73 | I2CS_SPEED_100KHZ = 0, /**< Use to select a bus communication speed of 100 kHz. */ |
<> | 150:02e0a0aed4ec | 74 | I2CS_SPEED_400KHZ = 1 /**< Use to select a bus communication speed of 400 kHz. */ |
<> | 150:02e0a0aed4ec | 75 | } i2cs_speed_t; |
<> | 150:02e0a0aed4ec | 76 | |
<> | 150:02e0a0aed4ec | 77 | /** |
<> | 150:02e0a0aed4ec | 78 | * Enumeration type to select the I2CS addressing mode. |
<> | 150:02e0a0aed4ec | 79 | */ |
<> | 150:02e0a0aed4ec | 80 | typedef enum { |
<> | 150:02e0a0aed4ec | 81 | I2CS_ADDR_8 = 0, /**< Sets the slave address mode to 8-bits (7-bits address plus read/write bit). */ |
<> | 150:02e0a0aed4ec | 82 | I2CS_ADDR_10 = MXC_F_I2CS_DEV_ID_TEN_BIT_ID_MODE /**< Sets the slave address mode to 10-bits. */ |
<> | 150:02e0a0aed4ec | 83 | } i2cs_addr_t; |
<> | 150:02e0a0aed4ec | 84 | |
<> | 150:02e0a0aed4ec | 85 | /** |
<> | 150:02e0a0aed4ec | 86 | * Type alias for an I2CS callback function that will be called when a given byte is updated by the Master, see I2CS_RegisterCallback(mxc_i2cs_regs_t *i2cs, uint8_t addr, i2cs_callback_fn callback). |
<> | 150:02e0a0aed4ec | 87 | * @details The function prototype for implementing callback_fn is: |
<> | 150:02e0a0aed4ec | 88 | * @code |
<> | 150:02e0a0aed4ec | 89 | * void func(uint8_t addr); |
<> | 150:02e0a0aed4ec | 90 | * @endcode |
<> | 150:02e0a0aed4ec | 91 | */ |
<> | 150:02e0a0aed4ec | 92 | typedef void (*i2cs_callback_fn)(uint8_t error_code); |
<> | 150:02e0a0aed4ec | 93 | /* **** Globals **** */ |
<> | 150:02e0a0aed4ec | 94 | |
<> | 150:02e0a0aed4ec | 95 | /* **** Function Prototypes **** */ |
<> | 150:02e0a0aed4ec | 96 | |
<> | 150:02e0a0aed4ec | 97 | /** |
<> | 150:02e0a0aed4ec | 98 | * @brief Initialize I2CS module. |
<> | 150:02e0a0aed4ec | 99 | * @param i2cs Pointer to I2CS regs. |
<> | 150:02e0a0aed4ec | 100 | * @param sys_cfg Pointer to I2CS system configuration, see |
<> | 150:02e0a0aed4ec | 101 | * #sys_cfg_i2cs_t. |
<> | 150:02e0a0aed4ec | 102 | * @param speed I2CS frequency. |
<> | 150:02e0a0aed4ec | 103 | * @param address I2CS address. |
<> | 150:02e0a0aed4ec | 104 | * @param addr_len I2CS address length. |
<> | 150:02e0a0aed4ec | 105 | * @return #E_NO_ERROR if everything is successful or an |
<> | 150:02e0a0aed4ec | 106 | * @ref MXC_Error_Codes "error code" if unsuccessful. |
<> | 150:02e0a0aed4ec | 107 | * |
<> | 150:02e0a0aed4ec | 108 | */ |
<> | 150:02e0a0aed4ec | 109 | int I2CS_Init(mxc_i2cs_regs_t *i2cs, const sys_cfg_i2cs_t *sys_cfg, i2cs_speed_t speed, uint16_t address, i2cs_addr_t addr_len); |
<> | 150:02e0a0aed4ec | 110 | |
<> | 150:02e0a0aed4ec | 111 | /** |
<> | 150:02e0a0aed4ec | 112 | * @brief Shutdown I2CS module. |
<> | 150:02e0a0aed4ec | 113 | * @param i2cs Pointer to I2CS regs. |
<> | 150:02e0a0aed4ec | 114 | * @return #E_NO_ERROR if everything is successful or an |
<> | 150:02e0a0aed4ec | 115 | * @ref MXC_Error_Codes "error code" if unsuccessful. |
<> | 150:02e0a0aed4ec | 116 | */ |
<> | 150:02e0a0aed4ec | 117 | int I2CS_Shutdown(mxc_i2cs_regs_t *i2cs); |
<> | 150:02e0a0aed4ec | 118 | |
<> | 150:02e0a0aed4ec | 119 | /** |
<> | 150:02e0a0aed4ec | 120 | * @brief I2CS interrupt handler. |
<> | 150:02e0a0aed4ec | 121 | * @details This function should be called by the application from the |
<> | 150:02e0a0aed4ec | 122 | * interrupt handler if I2CS interrupts are enabled. Alternately, |
<> | 150:02e0a0aed4ec | 123 | * this function can be periodically called by the application if |
<> | 150:02e0a0aed4ec | 124 | * I2CS interrupts are disabled. |
<> | 150:02e0a0aed4ec | 125 | * |
<> | 150:02e0a0aed4ec | 126 | * @param i2cs Pointer to I2CS regs. |
<> | 150:02e0a0aed4ec | 127 | */ |
<> | 150:02e0a0aed4ec | 128 | void I2CS_Handler(mxc_i2cs_regs_t *i2cs); |
<> | 150:02e0a0aed4ec | 129 | |
<> | 150:02e0a0aed4ec | 130 | /** |
<> | 150:02e0a0aed4ec | 131 | * @brief Register a callback that is triggered by an update of a specified |
<> | 150:02e0a0aed4ec | 132 | * byte. |
<> | 150:02e0a0aed4ec | 133 | * @details Registering a callback causes the slave to interrupt when the |
<> | 150:02e0a0aed4ec | 134 | * master has updated a specified byte. |
<> | 150:02e0a0aed4ec | 135 | * |
<> | 150:02e0a0aed4ec | 136 | * @param i2cs Pointer to the I2CS register structure, see |
<> | 150:02e0a0aed4ec | 137 | * #mxc_i2cs_regs_t. |
<> | 150:02e0a0aed4ec | 138 | * @param addr Index to trigger a call to the #i2cs_callback_fn. |
<> | 150:02e0a0aed4ec | 139 | * @param callback callback function of type #i2cs_callback_fn to be called |
<> | 150:02e0a0aed4ec | 140 | * when the addr being written by the master matches \c addr. |
<> | 150:02e0a0aed4ec | 141 | */ |
<> | 150:02e0a0aed4ec | 142 | void I2CS_RegisterCallback(mxc_i2cs_regs_t *i2cs, uint8_t addr, i2cs_callback_fn callback); |
<> | 150:02e0a0aed4ec | 143 | |
<> | 150:02e0a0aed4ec | 144 | /** |
<> | 150:02e0a0aed4ec | 145 | * @brief Write I2CS data to a given byte. |
<> | 150:02e0a0aed4ec | 146 | * @details The slave has a buffer of registers that the external master can |
<> | 150:02e0a0aed4ec | 147 | * read. Use this function to write data into a specified |
<> | 150:02e0a0aed4ec | 148 | * address/index. |
<> | 150:02e0a0aed4ec | 149 | * |
<> | 150:02e0a0aed4ec | 150 | * @param i2cs Pointer to I2CS regs. |
<> | 150:02e0a0aed4ec | 151 | * @param addr Address/Index to write. |
<> | 150:02e0a0aed4ec | 152 | * @param data Data to be written. |
<> | 150:02e0a0aed4ec | 153 | */ |
<> | 150:02e0a0aed4ec | 154 | __STATIC_INLINE void I2CS_Write(mxc_i2cs_regs_t *i2cs, uint8_t addr, uint8_t data) |
<> | 150:02e0a0aed4ec | 155 | { |
<> | 150:02e0a0aed4ec | 156 | // Make sure we don't overflow |
<> | 150:02e0a0aed4ec | 157 | MXC_ASSERT(addr < MXC_CFG_I2CS_BUFFER_SIZE); |
<> | 150:02e0a0aed4ec | 158 | i2cs->data_byte[addr] = ((i2cs->data_byte[addr] & ~MXC_F_I2CS_DATA_BYTE_DATA_FIELD) | |
<> | 150:02e0a0aed4ec | 159 | (data << MXC_F_I2CS_DATA_BYTE_DATA_FIELD_POS)); |
<> | 150:02e0a0aed4ec | 160 | } |
<> | 150:02e0a0aed4ec | 161 | |
<> | 150:02e0a0aed4ec | 162 | /** |
<> | 150:02e0a0aed4ec | 163 | * @brief Read I2CS data from a given address . |
<> | 150:02e0a0aed4ec | 164 | * @details The slave has a buffer of registers that the external master can |
<> | 150:02e0a0aed4ec | 165 | * read. Use this function to read the data from the registers. |
<> | 150:02e0a0aed4ec | 166 | * |
<> | 150:02e0a0aed4ec | 167 | * @param i2cs Pointer to I2CS regs. |
<> | 150:02e0a0aed4ec | 168 | * @param addr Address/Index to read from. |
<> | 150:02e0a0aed4ec | 169 | * |
<> | 150:02e0a0aed4ec | 170 | * @return Data contained in requested @c addr register. |
<> | 150:02e0a0aed4ec | 171 | */ |
<> | 150:02e0a0aed4ec | 172 | __STATIC_INLINE uint8_t I2CS_Read(mxc_i2cs_regs_t *i2cs, uint8_t addr) |
<> | 150:02e0a0aed4ec | 173 | { |
<> | 150:02e0a0aed4ec | 174 | // Make sure we don't overflow |
<> | 150:02e0a0aed4ec | 175 | MXC_ASSERT(addr < MXC_CFG_I2CS_BUFFER_SIZE); |
<> | 150:02e0a0aed4ec | 176 | return ((i2cs->data_byte[addr] & MXC_F_I2CS_DATA_BYTE_DATA_FIELD) >> |
<> | 150:02e0a0aed4ec | 177 | MXC_F_I2CS_DATA_BYTE_DATA_FIELD_POS); |
<> | 150:02e0a0aed4ec | 178 | } |
<> | 150:02e0a0aed4ec | 179 | |
<> | 150:02e0a0aed4ec | 180 | /** |
<> | 150:02e0a0aed4ec | 181 | * @brief Set the given index to read only (RO). |
<> | 150:02e0a0aed4ec | 182 | * @details This index will be flagged as read only. The slave will NACK the |
<> | 150:02e0a0aed4ec | 183 | * master if it attempts to write this location. Multiple calls with |
<> | 150:02e0a0aed4ec | 184 | * different index/address values will yield multiple read-only |
<> | 150:02e0a0aed4ec | 185 | * locations within the slave register set. |
<> | 150:02e0a0aed4ec | 186 | * |
<> | 150:02e0a0aed4ec | 187 | * @param i2cs Pointer to I2CS regs. |
<> | 150:02e0a0aed4ec | 188 | * @param addr Address/Index of the byte to set to RO. |
<> | 150:02e0a0aed4ec | 189 | */ |
<> | 150:02e0a0aed4ec | 190 | __STATIC_INLINE void I2CS_SetRO(mxc_i2cs_regs_t *i2cs, uint8_t addr) |
<> | 150:02e0a0aed4ec | 191 | { |
<> | 150:02e0a0aed4ec | 192 | // Make sure we don't overflow |
<> | 150:02e0a0aed4ec | 193 | MXC_ASSERT(addr < MXC_CFG_I2CS_BUFFER_SIZE); |
<> | 150:02e0a0aed4ec | 194 | i2cs->data_byte[addr] |= MXC_F_I2CS_DATA_BYTE_READ_ONLY_FL; |
<> | 150:02e0a0aed4ec | 195 | } |
<> | 150:02e0a0aed4ec | 196 | |
<> | 150:02e0a0aed4ec | 197 | /** |
<> | 150:02e0a0aed4ec | 198 | * @brief Sets the given address to R/W. |
<> | 150:02e0a0aed4ec | 199 | * @param i2cs Pointer to I2CS regs. |
<> | 150:02e0a0aed4ec | 200 | * @param addr Index to start clearing RO flag. |
<> | 150:02e0a0aed4ec | 201 | */ |
<> | 150:02e0a0aed4ec | 202 | __STATIC_INLINE void I2CS_ClearRO(mxc_i2cs_regs_t *i2cs, uint8_t addr) |
<> | 150:02e0a0aed4ec | 203 | { |
<> | 150:02e0a0aed4ec | 204 | // Make sure we don't overflow |
<> | 150:02e0a0aed4ec | 205 | MXC_ASSERT(addr < MXC_CFG_I2CS_BUFFER_SIZE); |
<> | 150:02e0a0aed4ec | 206 | i2cs->data_byte[addr] &= ~MXC_F_I2CS_DATA_BYTE_READ_ONLY_FL; |
<> | 150:02e0a0aed4ec | 207 | } |
<> | 150:02e0a0aed4ec | 208 | |
<> | 150:02e0a0aed4ec | 209 | /**@} end of group i2cs */ |
<> | 150:02e0a0aed4ec | 210 | |
<> | 150:02e0a0aed4ec | 211 | #ifdef __cplusplus |
<> | 150:02e0a0aed4ec | 212 | } |
<> | 150:02e0a0aed4ec | 213 | #endif |
<> | 150:02e0a0aed4ec | 214 | |
<> | 150:02e0a0aed4ec | 215 | #endif /* _I2CS_H_ */ |