Integration Guide

To be able to use the Embever IoT library the Integration Layer needs to be set up. The Integration Layer provides access to the hardware resources in order to establish communication with an Embever IoT device. For more information about the Integration Layer refer to the The Integration Layer topic under the API section.

Integrating the Embever IoT library will take 3 parts: the Embever I2C driver, the Embever GPIO driver and the Embever Delay Function. The integration layer needs to be set up before using the other parts of the Embever IoT library.

Integrating the Embever Delay Function

The Embever Delay Function is necessary to the Embever IoT Library to detect timeout events. The following example shows how to set up the Embever Delay Function using the Arduino framework.



The functions passed to the delay registration routine expects only 1 argument, which defines the delay value in milliseconds.

The function definition is the following:

void ebv_delay_register(void (*delay)(unsigned long ms));

Integrating the Embever GPIO Driver

The Embever GPIO Driver requires 2 functions to be able to read the digital signals on the designed pins. To set it up, you need to provide those 2 functions and then register them on ebv_esp_gpio_cb (more details bellow). Take a look at the following code sample, using the Arduino framework:


// Interface function for reading the ready state
bool gpio_readReady(){
    return digitalRead(PIN_EBV_READY);

// Interface function for reading the irq state
bool gpio_readIrq(){
    return digitalRead(PIN_EBV_IRQ);

The above example shows the 2 required interface functions which can fullfil the Embever GPIO Driver requirements. The functions should have boolean return type based on the following logic.

Return value logic

GPIO Pin logic level

Function return





After defining those functions they should be registered into the Embever GPIO Driver using the ebv_esp_gpio_cb structure. A possible implementation might look’s like the following:

struct ebv_esp_gpio_cb gpio_cb;
gpio_cb.readReady = gpio_readReady;
gpio_cb.readIRQ = gpio_readIrq;

Integrating the Embever I2C Driver

To integrate the Embever I2C Driver, a few interface functions need to be set up. Starting with a possible implementation first and then discussing them in details.

void wire_begin(uint8_t address){

void wire_end(){

int wire_available(){
    return Wire.available();

size_t wire_write(uint8_t data){
    return Wire.write(data);

void wire_requestFrom(uint8_t address, uint8_t nof_bytes){
    Wire.requestFrom(address, nof_bytes);

int wire_read(){

void wire_begin (uint8_t address)

Initiate the device address by the address parameter and prepare the peripheral to transmit data (but don’t transmit anything to the bus yet).

size_t wire_write (uint8_t data)

Copy data to the internal buffer. Not sending anything to the bus yet. Return 1 if the operation was successful, return 0 if not.

void wire_end ()

Flushes the internal buffers, if any, by writing them to the I2C bus and issue a stop sequence.

void wire_requestFrom(uint8_t address, uint8_t nof_bytes)

Issues a read sequence on the I2C bus and tries to read nof_bytes from device specified by address. Puts the incoming data into an internal buffer.

int wire_available ()

Returns the number of received bytes during the last transaction.

int wire_read()

Reads the incoming data from the internal buffer. This function reads and returns only 1 byte from the internal buffer. This function should called only if there are data in the internal buffer only. If the internal buffer is empty, should return with -1.

As the above topic suggest, implementing the required I2C driver can be more challenging than the Embever GPIO Driver implementation. Using an internal receive and transmit buffer might also be necessary to fullfil the requirements. The Embever I2C Driver interface was inspired by the Arduino Wire library. To get more information about the working principles and the expectation of the Embever I2C Driver, take look at the Arduino Wire library.