Giter VIP home page Giter VIP logo

ccs811's Introduction

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:

struct ccs811_dev_s {
	/*! Device address; default is 0x5B */
	uint8_t address;
	/*! Harware ID */
	uint8_t hw_id;
	/*! Harware version */
	uint8_t hw_version;
	/*! Firmware version of the boot code */
	uint16_t fw_boot_version;
	/*! Firmware version of the application code */
	uint16_t fw_app_version;
	/*! Read function pointer for the I2C implementation */
	ccs811_func_ptr read;
	/*! Write function pointer for the I2C implementation */
	ccs811_func_ptr write;
};

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

typedef uint8_t (*ccs811_func_ptr)(ccs811_dev_t *dev, uint8_t reg_addr,
		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

uint8_t read_iaq_i2c(ccs811_dev_t *dev, uint8_t reg_addr, uint8_t *data,
		uint16_t len) {

	uint8_t result = 0;
	result = HAL_I2C_Master_Transmit(&hi2c1, dev->address, &reg_addr, 1, 100);

	if (result == HAL_OK) {
		result = HAL_I2C_Master_Receive(&hi2c1, dev->address, data, len, 100);
	}
	return hi2c1.ErrorCode;
}

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

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

(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.

Links

ccs811's People

Contributors

matt-richardson-cardinalpeak avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.