The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_MAX32625PICO/TARGET_Maxim/TARGET_MAX32625/mxc/i2cs.h@169:a7c7b631e539
mbed library. Release version 164

Who changed what in which revision?

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