项目作者: lo-co

项目描述 :
Driver written in C for the CCS811 Indoor Air Quality measurement chip
高级语言: C
项目地址: git://github.com/lo-co/CCS811.git
创建时间: 2019-01-16T19:07:03Z
项目社区:https://github.com/lo-co/CCS811

开源协议:GNU General Public License v3.0

下载


CCS811 Air Quality Driver

This library provides a platform independent driver for the CCS811 Air Quality
measurement chip.

Implementation details

The details of the I2C bus communication are left to the implementation. In ccs811.h, a struct describing the IAQ device is defined as follows:

  1. struct ccs811_dev_s {
  2. /*! Device address; default is 0x5B */
  3. uint8_t address;
  4. /*! Harware ID */
  5. uint8_t hw_id;
  6. /*! Harware version */
  7. uint8_t hw_version;
  8. /*! Firmware version of the boot code */
  9. uint16_t fw_boot_version;
  10. /*! Firmware version of the application code */
  11. uint16_t fw_app_version;
  12. /*! Read function pointer for the I2C implementation */
  13. ccs811_func_ptr read;
  14. /*! Write function pointer for the I2C implementation */
  15. ccs811_func_ptr write;
  16. };

Read and write operations are defined as as function pointers with type of ccs811_func_ptr which looks like:

  1. typedef uint8_t (*ccs811_func_ptr)(ccs811_dev_t *dev, uint8_t reg_addr,
  2. uint8_t *data, uint16_t len);

These should be implemented in the code that calls this. An example of implementation in the STM32 domain using the HAL provided by the manufacturer might looks like this

  1. uint8_t read_iaq_i2c(ccs811_dev_t *dev, uint8_t reg_addr, uint8_t *data,
  2. uint16_t len) {
  3. uint8_t result = 0;
  4. result = HAL_I2C_Master_Transmit(&hi2c1, dev->address, ®_addr, 1, 100);
  5. if (result == HAL_OK) {
  6. result = HAL_I2C_Master_Receive(&hi2c1, dev->address, data, len, 100);
  7. }
  8. return hi2c1.ErrorCode;
  9. }

for the read function where dev is defined as something that looks like

  1. ccs811_dev_t iaq_dev = {
  2. .address = (CCS811_DEFAULT_ADDRESS << 1),
  3. .read = &read_iaq_i2c,
  4. .write = &write_iaq_i2c
  5. };

(in the ST HAL, the address is a 7 bit address taht must be left-shifted by 1 bit). The write implementation is left as an exercise for the user.