179 lines
8.1 KiB
C
179 lines
8.1 KiB
C
/*******************************************************************************
|
||
* @note Copyright (C) 2017 Shanghai Panchip Microelectronics Co., Ltd.
|
||
* All rights reserved.
|
||
*
|
||
* @file driver_swiic_pan159.h
|
||
* @brief PAN159 GPIO IICͨÓÃÇý¶¯
|
||
*
|
||
* @history - V1.0, 2017-08-25, xiaoguolin, first implementation.
|
||
*******************************************************************************/
|
||
#ifndef __DRIVER_SWIIC_PAN159_H
|
||
#define __DRIVER_SWIIC_PAN159_H
|
||
|
||
#ifdef __cplusplus
|
||
extern "C"{
|
||
#endif
|
||
|
||
#include "lib_driver_delay_pan159.h"
|
||
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_578K 0x00000000
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_540K 0x00010000
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_515K 0x00020000
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_476K 0x00010001
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_457K 0x00020001
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_426K 0x00020002
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_412K 0x00030002
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_397K 0x00040002
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_385K 0x00030003
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_373K 0x00040003
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_361K 0x00050003
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_351K 0x00060003
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_341K 0x00050004
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_331K 0x00060004
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_322K 0x00070004
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_313K 0x00060005
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_306K 0x00070005
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_298K 0x00080005
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_291K 0x00090005
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_284K 0x00080006
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_278K 0x00090006
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_271K 0x000A0006
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_265K 0x000B0006
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_259K 0x000C0006
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_254K 0x000D0006
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_249K 0x000C0007
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_244K 0x000D0007
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_239K 0x000E0007
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_234K 0x000F0007
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_230K 0x000E0008
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_225K 0x000F0008
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_220K 0x00100008
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_215K 0x00110008
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_200K 0x0010000B
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_190K 0x0011000C
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_181K 0x0010000E
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_171K 0x00100010
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_161K 0x00140010
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_151K 0x00190010
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_141K 0x001E0010
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_129K 0x001E0014
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_119K 0x001E0018
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_108K 0x001E001D
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_100K 0x00220020
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_81K 0x00380023
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_69K 0x00480028
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_54K 0x00580038
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_42K 0x00690050
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_31K 0x00880070
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_20K 0x010000A0
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_10K 0x02000160
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_1K 0x0FFF0F69
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_750 0x1A01123B
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_500 0x20001EDD
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_200 0x60004539
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_FASTEST 0x00000000
|
||
#define SWIIC_PAN159_SPEED_SYS_48M_IIC_DEFAULT 0xFFFFFFFF
|
||
|
||
typedef struct{
|
||
volatile uint32_t *sda;
|
||
volatile uint32_t *scl;
|
||
union{
|
||
uint32_t code;
|
||
struct{
|
||
uint16_t l;
|
||
uint16_t h;
|
||
}scl_tim_code;
|
||
}speed;
|
||
}swiic_pan159_t;
|
||
|
||
/*******************************************************************************
|
||
* @brief GPIO IIC³õʼ»¯
|
||
* @param[in] hiic - IICÉ豸¾ä±ú
|
||
* iic_speed - IICËÙÂÊ
|
||
* sda_port_n - SDA¶Ë¿ÚºÅ
|
||
* sda_pin_n - SDAÒý½ÅºÅ
|
||
* scl_port_n - SCL¶Ë¿ÚºÅ
|
||
* scl_pin_n - SCLÒý½ÅºÅ
|
||
* @return ÎÞ
|
||
* @history - V1.0, 2017-08-25, xiaoguolin, first implementation.
|
||
*******************************************************************************/
|
||
void swiic_pan159_init(swiic_pan159_t* hiic, uint32_t iic_speed,
|
||
uint32_t sda_port_n, uint32_t sda_pin_n,
|
||
uint32_t scl_port_n, uint32_t scl_pin_n);
|
||
|
||
/*******************************************************************************
|
||
* @brief GPIO IIC¶ÁÈ¡(¸Ãº¯Êý¶ÁÈ¡¾ßÓÐÒ»¶¨µÄ·çÏÕ,ÎÞ·¨Çø·Ö¶Áȡʧ°ÜºÍ¶Áµ½0)
|
||
* @param[in] dhiic - Ä¿±êIICÉ豸¾ä±ú
|
||
* shiic - Ô´IICÉ豸¾ä±ú
|
||
* iic_speed - IICËÙÂÊ
|
||
* @return ÎÞ
|
||
* @history - V1.0, 2017-09-12, xiaoguolin, first implementation.
|
||
*******************************************************************************/
|
||
void swiic_pan159_copy(swiic_pan159_t* dhiic, const swiic_pan159_t* shiic,
|
||
uint32_t iic_speed);
|
||
|
||
/*******************************************************************************
|
||
* @brief GPIO IIC¶ÁÈ¡(¸Ãº¯Êý¶ÁÈ¡¾ßÓÐÒ»¶¨µÄ·çÏÕ,ÎÞ·¨Çø·Ö¶Áȡʧ°ÜºÍ¶Áµ½0)
|
||
* @param[in] hiic - IICÉ豸¾ä±ú
|
||
* dev - IICÉ豸µØÖ·
|
||
* reg - ¼Ä´æÆ÷µØÖ·
|
||
* @return ¶ÁÈ¡µ½µÄ×Ö½Ú
|
||
* @history - V1.0, 2017-08-25, xiaoguolin, first implementation.
|
||
*******************************************************************************/
|
||
uint8_t swiic_pan159_read_byte(const swiic_pan159_t* hiic,
|
||
uint8_t dev, uint8_t reg);
|
||
|
||
/*******************************************************************************
|
||
* @brief GPIO IIC¶ÁÈ¡
|
||
* @param[in] hiic - IICÉ豸¾ä±ú
|
||
* dev - IICÉ豸µØÖ·
|
||
* reg - ¼Ä´æÆ÷µØÖ·
|
||
* len - Òª¶ÁÈ¡µÄÊý¾Ý³¤¶È
|
||
* @param[out] _buf - Êý¾Ý»º³åÇø
|
||
* @return ¶ÁÈ¡µ½µÄ×Ö½ÚÊý
|
||
* @history - V1.0, 2017-08-25, xiaoguolin, first implementation.
|
||
*******************************************************************************/
|
||
uint32_t swiic_pan159_read_bytes(const swiic_pan159_t* hiic,
|
||
uint8_t dev, uint8_t reg,
|
||
uint8_t* buf, uint32_t len);
|
||
|
||
/*******************************************************************************
|
||
* @brief GPIO IICдÈë
|
||
* @param[in] hiic - IICÉ豸¾ä±ú
|
||
* dev - IICÉ豸µØÖ·
|
||
* reg - ¼Ä´æÆ÷µØÖ·
|
||
* ubyte - ´ýдÈë×Ö½Ú
|
||
* @return 1 - ³É¹¦
|
||
* 0 - ʧ°Ü
|
||
* @history - V1.0, 2017-08-25, xiaoguolin, first implementation.
|
||
*******************************************************************************/
|
||
uint8_t swiic_pan159_write_byte(const swiic_pan159_t* hiic,
|
||
uint8_t dev, uint8_t reg, uint8_t ubyte);
|
||
|
||
/*******************************************************************************
|
||
* @brief GPIO IICдÈë
|
||
* @param[in] hiic - IICÉ豸¾ä±ú
|
||
* dev - IICÉ豸µØÖ·
|
||
* reg - ¼Ä´æÆ÷µØÖ·
|
||
* buf - Êý¾Ý»º³åÇø
|
||
* len - ҪдÈëµÄÊý¾Ý³¤¶È
|
||
* @return дÈëµÄ×Ö½ÚÊý
|
||
* @history - V1.0, 2017-08-25, xiaoguolin, first implementation.
|
||
*******************************************************************************/
|
||
uint32_t swiic_pan159_write_bytes(const swiic_pan159_t* hiic,
|
||
uint8_t dev, uint8_t reg,
|
||
const uint8_t* buf, uint32_t len);
|
||
|
||
typedef void (*TCallback)(void);
|
||
void iic_pan159_init(void);
|
||
void iic_start_send_bytes(uint16_t devAddr,uint8_t regAddr, uint8_t *buf, uint8_t len,TCallback cbk, TCallback fail_cbk);
|
||
void iic_start_read_bytes(uint16_t devAddr,uint8_t regAddr, uint8_t *buf, uint8_t len,TCallback cbk, TCallback fail_cbk);
|
||
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif /* __DRIVER_SWIIC_PAN159_H */
|
||
|