×

ADPD188BI无操作系统驱动程序

消耗积分:10 | 格式:pdf | 大小:117.81KB | 2021-03-23

世态薄凉

分享资料个

This version (28 Jul 2020 08:32) was approved by Andrei Drimbarean.

ADPD188 - No-OS Driver

Supported Devices

Overview

The ADPD188BI is a complete photometric system for smoke detection using optical dual wavelength technology. The module integrates a highly efficient photometric front end, two light emitting diodes (LEDs), and two photodiodes (PDs). These items are housed in a custom package that prevents light from going directly from the LED to the photodiode without first entering the smoke detection chamber. The front end of the application specific integrated circuit (ASIC) consists of a control block, a 14-bit analog-to-digital converter (ADC) with a 20-bit burst accumulator, and three flexible, independently configurable LED drivers. The control circuitry includes flexible LED signaling and synchronous detection. The analog front end (AFE) features best-in-class rejection of signal offset and corruption due to modulated interference commonly caused by ambient light. The data output and functional configuration occur over a 1.8 V I2C interface or serial peripheral interface (SPI) port.

Applications:

  • Smoke detection

Driver Description

The driver contains two parts:

  • The driver for the ADPD188BI part, which may be used, without modifications, with any microcontroller.
  • The Communication Drivers, where the specific communication functions for the desired type of processor and communication protocol have to be implemented. This driver implements the communication with the device and hides the actual details of the communication protocol to the ADI driver.

The Communication Driver has a standard interface, so the ADPD188BI driver can be used exactly as it is provided.

the Communication Drivers must include two things: I2C or SPI transmission methods and GPIO control methods. For the I2C method, the ADPD188BI driver calls four functions:

  • i2c_init() – initializes the I2C communication peripheral.
  • i2c_remove() – frees memory allocated by the I2C communication driver.
  • i2c_write() – writes data to the device.
  • i2c_read() – reads data from the device.

For the SPI method, the ADPD188BI driver calls three functions:

  • spi_init() - initializes the SPI communication peripheral.
  • spi_remove() – frees memory allocated by the SPI communication driver.
  • spi_write_and_read() – conduct information transfer with the device.

For the GPIO control methods, the ADPD188BI driver calls three functions:

  • gpio_get() - initialize GPIO peripheral and allocate memory for one GPIO control.
  • gpio_remove() - frees memory allocated by the GPIO control driver.
  • gpio_direction_input() - set GPIO as input.

Functions Declarations

Function Description
int32_t adpd188_init(struct adpd188_dev **device, struct adpd188_init_param *init_param);
Initialize the ADPD188 driver.
int32_t adpd188_remove(struct adpd188_dev *dev);
Free resources allocated by adpd188_init().
int32_t adpd188_reg_read(struct adpd188_dev *dev, uint8_t reg_addr, uint16_t *reg_val);
Read one 16 bit register of the ADPD188.
int32_t adpd188_reg_write(struct adpd188_dev *dev, uint8_t reg_addr, uint16_t reg_val);
Write one 16 bit register of the ADPD188.
int32_t adpd188_mode_get(struct adpd188_dev *dev, enum adpd188_mode *mode);
Get the mode of operation of the ADPD188.
int32_t adpd188_mode_set(struct adpd188_dev *dev, enum adpd188_mode new_mode);
Set the mode of operation of the ADPD188.
int32_t adpd188_fifo_status_get(struct adpd188_dev *dev, uint8_t *bytes_no);
Get the number of bytes currently present in FIFO.
int32_t adpd188_fifo_clear(struct adpd188_dev *dev);
Empty the FIFO.
int32_t adpd188_fifo_thresh_set(struct adpd188_dev *dev, uint8_t word_no);
Set the number of 16 bit words that need to be in the FIFO to trigger an interrupt.
int32_t adpd188_interrupt_get(struct adpd188_dev *dev, uint8_t *flags);
Get the slot and FIFO interrupt flags.
int32_t adpd188_interrupt_clear(struct adpd188_dev *dev, uint8_t flags);
Clear the slot and FIFO interrupt flags.
int32_t adpd188_interrupt_en(struct adpd188_dev *dev, uint8_t flags);
Enable the slot and FIFO interrupt flags.
int32_t adpd188_gpio_setup(struct adpd188_dev *dev, struct adpd188_gpio_config config);
Setup drive and polarity of the GPIOs.
int32_t adpd188_gpio_alt_setup(struct adpd188_dev *dev, uint8_t gpio_id, enum adpd188_gpio_alt_config config);
Setup the GPIO source.
int32_t adpd188_sw_reset(struct adpd188_dev *dev);
Do software reset of the device.
int32_t adpd188_clk32mhz_cal(struct adpd188_dev *dev);
Do internal 32MHz clock calibration.
int32_t adpd188_slot_setup(struct adpd188_dev *dev, struct adpd188_slot_config config);
Enable slot and setup its FIFO interaction.
int32_t adpd188_adc_fsample_set(struct adpd188_dev *dev, float freq_hz);
Set sample frequency of the ADC.
int32_t adpd188_adc_fsample_get(struct adpd188_dev *dev, float *freq_hz);
Get sample frequency of the ADC.
int32_t adpd188_smoke_detect_setup(struct adpd188_dev *dev);
Do initial configuration of the device to use as a smoke detector.

Types Declarations

/**
 * @union adpd188_phy_init
 * @brief Communication physical protocol initialization structure. Can be I2C
 *        or SPI.
 */
union adpd188_phy_init {
	/** I2C initialization structure. */
	struct i2c_init_param i2c_phy;
	/** SPI initialization structure. */
	struct spi_init_param spi_phy;
};
 
/**
 * @enum adpd188_phy_opt
 * @brief Types of physical communication protocol.
 */
enum adpd188_phy_opt {
	/** SPI communication. */
	ADPD188_SPI,
	/** I2C communication. */
	ADPD188_I2C
};
 
/**
 * @enum adpd188_mode
 * @brief ADPD188 operation modes.
 */
enum adpd188_mode {
	/** Standby mode. */
	ADPD188_STANDBY,
	/** Program mode. */
	ADPD188_PROGRAM,
	/** Normal mode. */
	ADPD188_NORMAL
};
 
/**
 * @enum adpd188_interrupt
 * @brief Interrupt flags of the ADPD188.
 */
enum adpd188_interrupt {
	/** Slot A conversion interrupt flag. */
	ADPD188_SLOTA_INT = 0x1,
	/** Slot B conversion interrupt flag. */
	ADPD188_SLOTB_INT = 0x2,
	/** FIFO threshold reached interrupt flag. */
	ADPD188_FIFO_INT = 0x4
};
 
/**
 * @struct adpd188_gpio_config
 * @brief GPIO level configuration.
 */
struct adpd188_gpio_config {
	/** GPIO ID (0 or 1) */
	uint8_t gpio_id;
	/** GPIO polarity */
	uint8_t gpio_pol;
	/** Status of the GPIO driver (driven or open-drain) */
	uint8_t gpio_drv;
	/** GPIO enable (only for GPIO0) */
	uint8_t gpio_en;
};
 
/**
 * @enum adpd188_gpio_alt_config
 * @brief GPIO source configuration.
 */
enum adpd188_gpio_alt_config {
	/** GPIO backwards compatible with the ADPD103 INT functionality. */
	ADPD188_ADPD103 = 0x00,
	/** Interrupt function provided on GPIO. */
	ADPD188_INT_FUNC = 0x01,
	/**
	 * Asserts at the start of the first time slot and deasserts at end of last
	 * time slot.
	 */
	ADPD188_ACTIVE_PULSE = 0x02,
	/** Time Slot A pulse output. */
	ADPD188_SLOTA_PULSE = 0x05,
	/** Time Slot B pulse output. */
	ADPD188_SLOTB_PULSE = 0x06,
	/** Pulse output of both time slots. */
	ADPD188_ANYSLOT_PULSE = 0x07,
	/** Output data cycle occurred for Time Slot A. */
	ADPD188_SLOTA_OUT = 0x0C,
	/** Output data cycle occurred for Time Slot B. */
	ADPD188_SLOTB_OUT = 0x0D,
	/** Output data cycle occurred. */
	ADPD188_ANYSLOT_OUT = 0x0E,
	/**
	 * Toggles on every sample, which provides a signal at half the sampling
	 * rate.
	 */
	ADPD188_HALF_SAMPLING = 0x0F,
	/** Output = 0. */
	ADPD188_OUT_LOW = 0x10,
	/** Output = 1. */
	ADPD188_OUT_HIGH = 0x11,
	/** 32 kHz oscillator output. */
	ADPD188_32KHZ_OSC = 0x13
};
 
/**
 * @enum adpd188_slots
 * @brief ADPD188 time slots.
 */
enum adpd188_slots {
	/** First slot. */
	ADPD188_SLOTA,
	/** Second slot. */
	ADPD188_SLOTB
};
 
/**
 * @enum adpd188_slot_fifo_mode
 * @brief The way a time slot stores data in the FIFO.
 */
enum adpd188_slot_fifo_mode {
	/** No data to FIFO. */
	ADPD188_NO_FIFO,
	/** 16-bit sum of all four channels. */
	ADPD188_16BIT_SUM,
	/** 32-bit sum of all four channels. */
	ADPD188_32BIT_SUM,
	/** Four channels of 16-bit sample data for the time slot. */
	ADPD188_16BIT_4CHAN = 0x4,
	/** Four channels of 32-bit sample data for the time slot. */
	ADPD188_32BIT_4CHAN = 0x6
};
 
/**
 * @struct adpd188_slot_config
 * @brief Slot configuration initialization structure.
 */
struct adpd188_slot_config {
	/** Time slot ID. */
	enum adpd188_slots slot_id;
	/** Enable time slot. */
	bool slot_en;
	/** Time slot FIFO mode. */
	enum adpd188_slot_fifo_mode sot_fifo_mode;
};
 
/**
 * @struct adpd188_dev
 * @brief Driver descriptor structure.
 */
struct adpd188_dev {
	/** Communication physical type. */
	enum adpd188_phy_opt phy_opt;
	/** Communication physical descriptor. */
	void *phy_desc;
	/** GPIO 0 descriptor. */
	struct gpio_desc *gpio0;
	/** GPIO 1 descriptor. */
	struct gpio_desc *gpio1;
};
 
/**
 * @struct adpd188_init_param
 * @brief Driver initialization structure.
 */
struct adpd188_init_param {
	/** Communication physical type. */
	enum adpd188_phy_opt phy_opt;
	/** Communication physical initialization structure. */
	union adpd188_phy_init phy_init;
	/** GPIO 0 initialization structure. */
	struct gpio_init_param gpio0_init;
	/** GPIO 0 initialization structure. */
	struct gpio_init_param gpio1_init;
};

Initialization example

This is an initialization example. After doing this the user must put the device in GO mode and read data as described in the datasheet.

#include 
#include 
#include "adpd188.h"
 
void main()
{
    struct adpd188_dev *adpd_desc;
    struct adpd188_init_param adpd_init;
    int32_t ret;
    uint16_t reg_data;
 
    adpd_init.phy_opt = ADPD188_SPI;
    /* SPI initialization is generally dependent on the platform used */
    adpd_init.phy_init.spi_phy.extra = NULL; /* Platform dependent; this is a dummy value */
    adpd_init.phy_init.spi_phy.chip_select = 0; /* Platform dependent; this is a dummy value */
    adpd_init.phy_init.spi_phy.max_speed_hz = 6000000; /* Platform dependent; this is usually a good value */
    adpd_init.phy_init.spi_phy.mode = SPI_MODE_3; /* This should always be the mode */
    /* GPIO initialization is generally dependent on the platform used */
    adpd_init.gpio0_init.number = 1; /* Platform dependent; this is a dummy value */
    adpd_init.gpio0_init.extra = NULL; /* Platform dependent; this is a dummy value */
    adpd_init.gpio1_init.number = 2; /* Platform dependent; this is a dummy value */
    adpd_init.gpio1_init.extra = NULL; /* Platform dependent; this is a dummy value */
 
    ret = adpd188_init(&adpd_desc, &adpd_init);
    if (ret != 0)
        return -1;
 
    /* Read device ID. For ADPD188BI it must be 0x16. */
    ret = adpd188_reg_read(adpd_desc, ADPD188_REG_DEVID, &reg_data);
    if (ret != 0)
        return -1;
    if ((reg_data & ADPD188_DEVID_DEV_ID_MASK) != 0x16)
        return -1;
 
    /** Enable 32kHz clock */
    ret = adpd188_reg_read(adpd_desc, ADPD188_REG_SAMPLE_CLK, &reg_data);
    if (ret != 0)
        return -1;
    reg_data |= ADPD188_SAMPLE_CLK_CLK32K_EN_MASK;
    ret = adpd188_reg_write(adpd_desc, ADPD188_REG_SAMPLE_CLK, reg_data);
    if (ret != 0)
        return -1;
 
    /* Activate program mode */
    ret = adpd188_mode_set(adpd_desc, ADPD188_PROGRAM);
    if (ret != 0)
        return -1;
 
    /* Initialize device in the datasheet smoke detection configuration */
    ret = adpd188_smoke_detect_setup(adpd_desc);
    if (ret != 0)
        return -1;
}

Downloads

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(1)
发评论
禹丶_b08 2021-08-17
0 回复 举报
需要需要 收起回复

下载排行榜

全部1条评论

快来发表一下你的评论吧 !

'+ '

'+ '

'+ ''+ '
'+ ''+ ''+ '
'+ ''+ '' ); $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code ==5){ $(pop_this).attr('href',"/login/index.html"); return false } if(data.code == 2){ //跳转到VIP升级页面 window.location.href="//m.obk20.com/vip/index?aid=" + webid return false } //是会员 if (data.code > 0) { $('body').append(htmlSetNormalDownload); var getWidth=$("#poplayer").width(); $("#poplayer").css("margin-left","-"+getWidth/2+"px"); $('#tips').html(data.msg) $('.download_confirm').click(function(){ $('#dialog').remove(); }) } else { var down_url = $('#vipdownload').attr('data-url'); isBindAnalysisForm(pop_this, down_url, 1) } }); }); //是否开通VIP $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code == 2 || data.code ==5){ //跳转到VIP升级页面 $('#vipdownload>span').text("开通VIP 免费下载") return false }else{ // 待续费 if(data.code == 3) { vipExpiredInfo.ifVipExpired = true vipExpiredInfo.vipExpiredDate = data.data.endoftime } $('#vipdownload .icon-vip-tips').remove() $('#vipdownload>span').text("VIP免积分下载") } }); }).on("click",".download_cancel",function(){ $('#dialog').remove(); }) var setWeixinShare={};//定义默认的微信分享信息,页面如果要自定义分享,直接更改此变量即可 if(window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger'){ var d={ title:'ADPD188BI无操作系统驱动程序',//标题 desc:$('[name=description]').attr("content"), //描述 imgUrl:'https://'+location.host+'/static/images/ele-logo.png',// 分享图标,默认是logo link:'',//链接 type:'',// 分享类型,music、video或link,不填默认为link dataUrl:'',//如果type是music或video,则要提供数据链接,默认为空 success:'', // 用户确认分享后执行的回调函数 cancel:''// 用户取消分享后执行的回调函数 } setWeixinShare=$.extend(d,setWeixinShare); $.ajax({ url:"//www.obk20.com/app/wechat/index.php?s=Home/ShareConfig/index", data:"share_url="+encodeURIComponent(location.href)+"&format=jsonp&domain=m", type:'get', dataType:'jsonp', success:function(res){ if(res.status!="successed"){ return false; } $.getScript('https://res.wx.qq.com/open/js/jweixin-1.0.0.js',function(result,status){ if(status!="success"){ return false; } var getWxCfg=res.data; wx.config({ //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId:getWxCfg.appId, // 必填,公众号的唯一标识 timestamp:getWxCfg.timestamp, // 必填,生成签名的时间戳 nonceStr:getWxCfg.nonceStr, // 必填,生成签名的随机串 signature:getWxCfg.signature,// 必填,签名,见附录1 jsApiList:['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function(){ //获取“分享到朋友圈”按钮点击状态及自定义分享内容接口 wx.onMenuShareTimeline({ title: setWeixinShare.title, // 分享标题 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享给朋友”按钮点击状态及自定义分享内容接口 wx.onMenuShareAppMessage({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 type: setWeixinShare.type, // 分享类型,music、video或link,不填默认为link dataUrl: setWeixinShare.dataUrl, // 如果type是music或video,则要提供数据链接,默认为空 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ”按钮点击状态及自定义分享内容接口 wx.onMenuShareQQ({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口 wx.onMenuShareWeibo({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ空间”按钮点击状态及自定义分享内容接口 wx.onMenuShareQZone({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); }); }); } }); } function openX_ad(posterid, htmlid, width, height) { if ($(htmlid).length > 0) { var randomnumber = Math.random(); var now_url = encodeURIComponent(window.location.href); var ga = document.createElement('iframe'); ga.src = 'https://www1.elecfans.com/www/delivery/myafr.php?target=_blank&cb=' + randomnumber + '&zoneid=' + posterid+'&prefer='+now_url; ga.width = width; ga.height = height; ga.frameBorder = 0; ga.scrolling = 'no'; var s = $(htmlid).append(ga); } } openX_ad(828, '#berry-300', 300, 250);