lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /*******************************************************************************
|
| 2 | * Copyright (C) 2007, ZTE Corporation.
|
| 3 | *
|
| 4 | * File Name:
|
| 5 | * File Mark:
|
| 6 | * Description:
|
| 7 | * Others:
|
| 8 | * Version: V0.5
|
| 9 | * Author: Zhenghong
|
| 10 | * Date: 2008-01-10
|
| 11 | * History 1:
|
| 12 | * Date: 2012-07-16
|
| 13 | * Version: V1.0
|
| 14 | * Author: zhouqi
|
| 15 | * Modification: 1. Ôö¼Ó T_ZDrvI2c_BusFreq ö¾ÙÖÐ 300KHZ ¶¨Òå
|
| 16 | 2. ÐÞ¸Ä T_ZDrvI2c_DevFlagType ÖеÚÒ»¸ö I2C_DFLT_ADDR_DEV Ϊ I2C_10BIT_SLAVE_ADDR
|
| 17 | 3. ÔÚ T_ZDrvI2c_DevFlagType Ôö¼Ó I2C_USE_INT ¶¨Òå
|
| 18 | 4. Ôö¼Ó²¿·Ö×¢ÊÍÓë˵Ã÷
|
| 19 | * History 2:
|
| 20 | ******************************************************************************/
|
| 21 | #ifndef _DRVS_I2C_H
|
| 22 | #define _DRVS_I2C_H
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 | /**********************************************************/
|
| 27 | /** @defgroup T_ZDrvI2c_BusNum 7520ÓÐ 3 ¸öI2C½Ó¿Ú, 7520V2 È¥µôÒ»¸öI2C
|
| 28 | */
|
| 29 | typedef enum
|
| 30 | {
|
| 31 | //I2C_BUS_0 = 0,
|
| 32 | I2C_BUS_1 = 1,
|
| 33 | I2C_BUS_2 = 2, /* pmic i2c */
|
| 34 | MAX_I2C_BUS_NUM
|
| 35 | }T_ZDrvI2c_BusNum;
|
| 36 |
|
| 37 |
|
| 38 | /**********************************************************/
|
| 39 | /** @defgroup T_ZDrvI2c_BusFreq
|
| 40 | */
|
| 41 | typedef enum{
|
| 42 | I2C_FREQ_ONE_HUNDRED_KILO_HZ = 100*1000,
|
| 43 | I2C_FREQ_THREE_HUNDRED_KILO_HZ = 300*1000,
|
| 44 | I2C_FREQ_FOUR_HUNDRED_KILO_HZ = 400*1000,
|
| 45 | MAX_I2C_BUS_FREQ
|
| 46 | }T_ZDrvI2c_BusFreq;
|
| 47 |
|
| 48 |
|
| 49 | /**********************************************************/
|
| 50 | /** @defgroup T_ZDrvI2c_DevFlagType
|
| 51 | */
|
| 52 | typedef enum {
|
| 53 | I2C_10BIT_SLAVE_ADDR = 0x0001 << 0, /* ±êʶʹÓà --10λ´Ó»úµØÖ·-- */
|
| 54 | /* ĬÈϲ»Ê¹ÓÃλ 7λ´Ó»úµØÖ· */
|
| 55 |
|
| 56 | I2C_MEM_DEV = 0x0001 << 1, /* ±êʶʹÓà --16λ¼Ä´æÆ÷µØÖ·-- */
|
| 57 | I2C_REG_DEV = 0x0001 << 2, /* ±êʶʹÓà --8λ¼Ä´æÆ÷µØÖ·-- */
|
| 58 |
|
| 59 | I2C_NACK_LAST_BYTE = 0x0001 << 3, /* NACK last byte read from slave */
|
| 60 | I2C_NOP_LAST_BYTE = 0x0001 << 4, /* Let slave release SDA after last */
|
| 61 | I2C_M_COMBINE = 0x0001 << 5, /* ¾µäµÄ×éºÏ¶Áģʽ */
|
| 62 | I2C_STOP_START_BEFORE_READ = 0x0001 << 6, /* During a read transaction, gen. */
|
| 63 | /* a STOP & START after writing */
|
| 64 | /* the slave addr(just before read) */
|
| 65 | I2C_CLK_START_BEFORE_RW = 0x0001 << 7, /* Generate a clock and a START */
|
| 66 | /* before every I/O operation. */
|
| 67 | I2C_USE_INT = 0x0001 << 8 /* ʹÓÃÖжÏģʽ´«ÊäÊý¾Ý */
|
| 68 | /* Çø±ðΪ START ºó£¬»ñÈ¡ÐźÅÁ¿£¬Ïß³Ì¹ÒÆð*/
|
| 69 | /* ½¨ÒéÔÚ´«ËͶà×Ö½ÚʱʹÓà */
|
| 70 | } T_ZDrvI2c_DevFlagType;
|
| 71 |
|
| 72 | /**********************************************************************/
|
| 73 | /* ˵Ã÷:
|
| 74 |
|
| 75 | 1. ÔÚĬÈÏÇé¿öÏ£¬Ê¹Óà 7λ ´Ó»úµØÖ·£¬
|
| 76 | 8λ ¼Ä´æÆ÷µØÖ·
|
| 77 | ±ê׼ʱÐòµÄ ¼òµ¥Ð´¡¢ ¼òµ¥¶Á¡¢ ×éºÏ¶Áģʽ--
|
| 78 | ²»Ê¹ÓÃÖжÏ
|
| 79 |
|
| 80 | 2. ÒÔǰÅäÖÃµÄ ÒÔϲÎÊýÏÖÔÚ²»ÔÙʹÓã¬ÏÈǰÅäÖõÄÒ²²»Óøü¸Ä£¬µ«¶¼Ä¬ÈÏΪ --±ê×¼×éºÏ¶ÁʱÐò--
|
| 81 | Èç¹ûÓÐÌØÊâʱÐò£¬Çë¸æÖª
|
| 82 |
|
| 83 | I2C_NACK_LAST_BYTE ÔÚU207ûÓз¢ÏÖʹÓÃ
|
| 84 | I2C_NOP_LAST_BYTE ÔÚU207ûÓз¢ÏÖʹÓÃ
|
| 85 | I2C_M_COMBINE RDA5802\mt9d113ʹÓÃ
|
| 86 | I2C_STOP_START_BEFORE_READ PMIC\OV7670\0V9656ʹÓÃ
|
| 87 | I2C_CLK_START_BEFORE_RW ÔÚU207ûÓз¢ÏÖʹÓÃ
|
| 88 |
|
| 89 | 3. ÏÖÔڿɸù¾ÝÒ»ÏÂÁÐ×ÓÅäÖÃ:
|
| 90 |
|
| 91 | static T_ZDrvI2c_Device s_mt9d113I2cDev =
|
| 92 | {
|
| 93 | I2C_BUS_0,
|
| 94 | EXAMPLE_SLAVE_ADDRESS,
|
| 95 | I2C_FREQ_THREE_HUNDRED_KILO_HZ,
|
| 96 | 100,
|
| 97 | 1,
|
| 98 | -----------------------------------------------------------
|
| 99 | I2C_10BIT_SLAVE_ADDR | I2C_REG_DEV | I2C_USE_INT,
|
| 100 | // ʹÓÃ10´Ó»úµØÖ· 8λ¼Ä´æÆ÷µØÖ· ʹÓÃÖжϷ½Ê½
|
| 101 |
|
| 102 | I2C_MEM_DEV,
|
| 103 | // 16λ¼Ä´æÆ÷µØÖ·, 8´Ó»úµØÖ· ²»Ê¹ÓÃÖжÏ
|
| 104 | ----------------------------------------------------------
|
| 105 | NULL,
|
| 106 | };
|
| 107 | *********************************************************************/
|
| 108 | /**********************************************************/
|
| 109 | /** @defgroup T_ZDrvI2c_Device
|
| 110 | */
|
| 111 | typedef struct _T_ZDrvI2c_Device
|
| 112 | {
|
| 113 |
|
| 114 | T_ZDrvI2c_BusNum bus_num; /* indicate which i2c bus the device belongs to */
|
| 115 | UINT16 slv_addr; /* device addr on the i2c bus, 10bits for memory device and 7bits for registers */
|
| 116 | T_ZDrvI2c_BusFreq bus_freq; /* the i2c bus transfer freq according to the device require*/
|
| 117 | UINT32 timeout; /* time threshold waiting for bus idle */
|
| 118 | UINT8 retries; /* times we'll try again if the bus is busy */
|
| 119 | T_ZDrvI2c_DevFlagType flags; /* indicate the operation features */
|
| 120 |
|
| 121 | VOID *privData;
|
| 122 | }T_ZDrvI2c_Device;
|
| 123 |
|
| 124 |
|
| 125 | /*******************************************************************************
|
| 126 | * Function Prototypes *
|
| 127 | *******************************************************************************/
|
| 128 |
|
| 129 |
|
| 130 | /*******************************************************************************
|
| 131 | * Function: zDrvI2c_DevRead
|
| 132 | * Description: I2C×ÜÏß¼òµ¥¶Á
|
| 133 | * Parameters:
|
| 134 | * Input:
|
| 135 | *
|
| 136 | * Output:
|
| 137 | *
|
| 138 | * Returns:
|
| 139 | *
|
| 140 | *
|
| 141 | * Others: 1. ×ñÑI2C×ÜÏß ×éºÏ¶Á ±êÏßÐÒé¡£
|
| 142 | 2. ×î´óÒ»´Î¶ÁÈ¡ --32-- ¸ö×Ö½ÚÊý¾Ý¡£
|
| 143 | ********************************************************************************/
|
| 144 | SINT32 zDrvI2c_DevRead( T_ZDrvI2c_Device *i2c_dev, UINT16 regAddr, UINT8 *readBuf, UINT32 readNum );
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 | /*******************************************************************************
|
| 149 | * Function: zDrvI2c_DevWrite
|
| 150 | * Description: I2C×ÜÏß¼òµ¥Ð´
|
| 151 | * Parameters:
|
| 152 | * Input:
|
| 153 | *
|
| 154 | * Output:
|
| 155 | *
|
| 156 | * Returns:
|
| 157 | *
|
| 158 | *
|
| 159 | * Others: 1. ×ñÑI2C×ÜÏß ¼òµ¥Ð´ ±êÏßÐÒé¡£
|
| 160 | 2. ×î´óÒ»´ÎдÈë --30-- ¸ö×Ö½ÚÊý¾Ý¡£
|
| 161 | ********************************************************************************/
|
| 162 | SINT32 zDrvI2c_DevWrite( T_ZDrvI2c_Device *i2c_dev, UINT16 regAddr, UINT8 *writeBuf, UINT32 writeNum );
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 | /*******************************************************************************
|
| 167 | * Function: zDrvI2c_DevLock_BeforePSM
|
| 168 | * Description: ÔÚ¹ØÖжϲ¢µ÷Óà PSM ½Ó¿Úǰ£¬»ñÈ¡ I2C Éè±¸Ëø¡£
|
| 169 | * Parameters:
|
| 170 | * Input:
|
| 171 | *
|
| 172 | * Output:
|
| 173 | *
|
| 174 | * Returns:
|
| 175 | *
|
| 176 | *
|
| 177 | * Others: 1. ¹ØÖжϲ¢µ÷Óà PSM ½Ó¿Úʱ£¬I2C ¿ÉÄÜÕýÔÚ±»ÆäËûÏß³ÌʹÓá£
|
| 178 | * ʹÓô˽ӿڵȴýÆäËûÏß³ÌʹÓÃÍê±ÏºóÍ˳ö¡£
|
| 179 | ********************************************************************************/
|
| 180 | SINT32 zDrvI2c_DevLock_BeforePSM( T_ZDrvI2c_BusNum busNum);
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 | /*******************************************************************************
|
| 185 | * Function: zDrvI2c_DevUnlock_AfterPSM
|
| 186 | * Description: ²»ÔÙʹÓà PSM ½Ó¿Úʱ£¬ÊÍ·Å I2C Éè±¸Ëø¡£
|
| 187 | * Parameters:
|
| 188 | * Input:
|
| 189 | *
|
| 190 | * Output:
|
| 191 | *
|
| 192 | * Returns:
|
| 193 | *
|
| 194 | *
|
| 195 | * Others: 1. ÓëzDrvI2c_DevLock_BeforePSM½á¶ÔʹÓá£
|
| 196 | ********************************************************************************/
|
| 197 | SINT32 zDrvI2c_DevUnlock_AfterPSM( T_ZDrvI2c_BusNum busNum);
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 | /*******************************************************************************
|
| 202 | * Function: zDrvI2c_DevRead
|
| 203 | * Description: I2C×ÜÏß¼òµ¥¶Á£¬Ê¹ÓÃÊ¡µçģʽ
|
| 204 | * Parameters:
|
| 205 | * Input:
|
| 206 | *
|
| 207 | * Output:
|
| 208 | *
|
| 209 | * Returns:
|
| 210 | *
|
| 211 | *
|
| 212 | * Others: 1. ×ñÑI2C×ÜÏß ×éºÏ¶Á ±êÏßÐÒé¡£
|
| 213 | 2. ×î´óÒ»´Î¶ÁÈ¡ --32-- ¸ö×Ö½ÚÊý¾Ý¡£
|
| 214 | 3. Ö÷ÒªÊÇÔÚ²Ù×÷ÖÐ --²»»ñÈ¡»¥³âÁ¿--£¬ Á½µÄÏ̲߳»ÄÜͬʱµ÷ÓÃ
|
| 215 | ********************************************************************************/
|
| 216 | SINT32 zDrvI2c_DevRead_PSM( T_ZDrvI2c_Device *i2c_dev, UINT16 regAddr, UINT8 *readBuf, UINT32 readNum );
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 | /*******************************************************************************
|
| 222 | * Function: zDrvI2c_DevWrite
|
| 223 | * Description: I2C×ÜÏß¼òµ¥Ð´£¬Ê¹ÓÃÊ¡µçģʽ
|
| 224 | * Parameters:
|
| 225 | * Input:
|
| 226 | *
|
| 227 | * Output:
|
| 228 | *
|
| 229 | * Returns:
|
| 230 | *
|
| 231 | *
|
| 232 | * Others: 1. ×ñÑI2C×ÜÏß ¼òµ¥Ð´ ±êÏßÐÒé¡£
|
| 233 | 2. ×î´óÒ»´ÎдÈë --30-- ¸ö×Ö½ÚÊý¾Ý¡£
|
| 234 | 3. Ö÷ÒªÊÇÔÚ²Ù×÷ÖÐ --²»»ñÈ¡»¥³âÁ¿--£¬ Á½µÄÏ̲߳»ÄÜͬʱµ÷ÓÃ
|
| 235 | ********************************************************************************/
|
| 236 | SINT32 zDrvI2c_DevWrite_PSM( T_ZDrvI2c_Device *i2c_dev, UINT16 regAddr, UINT8 *writeBuf, UINT32 writeNum );
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 | /*******************************************************************************
|
| 241 | * Function: zDrvI2c_DevRead_ByteStream
|
| 242 | * Description: I2C×ÜÏß×Ö½ÚÁ÷¶Á
|
| 243 | * Parameters:
|
| 244 | * Input:
|
| 245 | *
|
| 246 | * Output:
|
| 247 | *
|
| 248 | * Returns:
|
| 249 | *
|
| 250 | *
|
| 251 | * Others: 1. ×ñÑI2C×ÜÏß ¼òµ¥¶Á ±êÏßÐÒé¡£
|
| 252 | 2. ֻд I2C Æ÷¼þµØÖ·£¬----------²»Ê¹ÓüĴæÆ÷µØÖ·-----¡£
|
| 253 | 2. ×î´óÒ»´Î¶ÁÈ¡ 32 ¸ö×Ö½ÚÊý¾Ý¡£
|
| 254 | ********************************************************************************/
|
| 255 | SINT32 zDrvI2c_DevRead_ByteStream( T_ZDrvI2c_Device *i2c_dev, UINT8 *readBuf, UINT32 readNum );
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 | /*******************************************************************************
|
| 261 | * Function: zDrvI2c_DevWrite_ByteStream
|
| 262 | * Description: I2C×ÜÏß×Ö½ÚÁ÷д
|
| 263 | * Parameters:
|
| 264 | * Input:
|
| 265 | *
|
| 266 | * Output:
|
| 267 | *
|
| 268 | * Returns:
|
| 269 | *
|
| 270 | *
|
| 271 | * Others: 1. ×ñÑI2C×ÜÏß ¼òµ¥Ð´ ±êÏßÐÒé¡£
|
| 272 | 2. ֻд I2C Æ÷¼þµØÖ·£¬----------²»Ê¹ÓüĴæÆ÷µØÖ·-----¡£
|
| 273 | 2. ×î´óÒ»´ÎдÈë 30 ¸ö×Ö½ÚÊý¾Ý¡£
|
| 274 | ********************************************************************************/
|
| 275 | SINT32 zDrvI2c_DevWrite_ByteStream( T_ZDrvI2c_Device *i2c_dev, UINT8 *writeBuf, UINT32 writeNum );
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 | #endif /* _DRVS_I2C_H */
|
| 282 |
|
| 283 |
|