How to list for library in mos.yml - libs: sources: includes:

#1
  1. My goal is: To be able to look at a mongoose-os-libs/library and from the library .yml, c-code and headers be able to correctly put together what is needed in my mos.yml and main.c #includes.

  2. My actions are: I have started a project using esp8266 with bme280 connected for i2c communication. I have setup the mos.yml, a main.c code template and have been able to successfully build and run the project, however, I don’t fully understand what needs to be in the project mos.yml.

  3. The result I see is: Depending on my mos.yml and #includes implementation I get compiler errors.

  4. My expectation & question is: Can someone help me understand, for a given library, how one figures out what needs to be listed in the mos.yml libs: sources: and includes: and what to list in the main.c includes?

For example the library I am looking at is the “https://github.com/mongoose-os-libs/bme280”. In the bme280 library root is a mos.yml that lists:

bme280 library mos.yml
includes:
  - include

sources:
  - src
  - src/BME280_driver

I will list the files in the library folders and what they #include below:

bme280/include/BME280.h 
	#include "mgos_bme280.h"

bme280/include/mgos_bme280.h
	#include <stdint.h>

bme280/src/mgos_bme280.c
	#include <mgos.h> 
	#include <mgos_i2c.h> 
	#include <mgos_spi.h> 
	#include "mgos_bme280.h" 
	#include "BME280_driver/bme280.h"

bme280/src/mgos_bme280_c.c
	#include <stdbool.h>

src/BME_driver/bme280.c
	#include "bme280.h"

src/BME_driver/bme280.h
	#include "bme280_defs.h"

src/BME_driver/bme280_defs.h
	#ifdef __KERNEL__
	#include <linux/types.h>
	#include <linux/kernel.h>
	#else
	#include <stdint.h>
	#include <stddef.h>
	#endif

Note that the Mongoose OS API Reference/Drivers/BME280/BMP280 lists BME280.h as the C Header which hyperlinks to /include/mgos_bme280.h

Here is my mos.yml

author: mongoose-os
description: A Mongoose OS app skeleton
version: 1.0

libs_version: ${mos.version}
modules_version: ${mos.version}
mongoose_os_version: ${mos.version}

# Optional. List of tags for online search.
tags:
  - c

# List of files / directories with C sources. No slashes at the end of dir names.
sources:
  - src

config_schema:
#I2C
  - ["i2c.enable", true]
  - ["i2c.sda_gpio", 4]
  - ["i2c.scl_gpio", 5]

# List of dirs. Files from these dirs will be copied to the device filesystem
filesystem:
  - fs
  
cdefs:
# Using 32 bit integer calculation by default
  BME280_32BIT_ENABLE: 1
# If 64 bit integer or double calculation is needed, 
# set BME280_64BIT_ENABLE or
# BME280_FLOAT_ENABLE in application's mos.yml

includes:

libs:
# AWS Defaults
  - origin: https://github.com/mongoose-os-libs/boards
  - origin: https://github.com/mongoose-os-libs/ca-bundle
  - origin: https://github.com/mongoose-os-libs/aws
  - origin: https://github.com/mongoose-os-libs/dash
  - origin: https://github.com/mongoose-os-libs/http-server
  - origin: https://github.com/mongoose-os-libs/ota-shadow
  - origin: https://github.com/mongoose-os-libs/ota-http-client
  - origin: https://github.com/mongoose-os-libs/ota-http-server
  - origin: https://github.com/mongoose-os-libs/rpc-service-config
  - origin: https://github.com/mongoose-os-libs/rpc-service-fs
  - origin: https://github.com/mongoose-os-libs/rpc-uart
  - origin: https://github.com/mongoose-os-libs/shadow
  - origin: https://github.com/mongoose-os-libs/sntp
# Additions
  - origin: https://github.com/mongoose-os-libs/spi
  - origin: https://github.com/mongoose-os-libs/i2c
  - origin: https://github.com/mongoose-os-libs/bme280 

The main.c includes are:

	#include "mgos.h"
	#include "mgos_mqtt.h"
	#include <mgos_i2c.h>
	#include <mgos_spi.h>
	#include "mgos_bme280.h"

To illustrate my confusion here, why include mgos_bme280.h in the main.c and not BME280.h, why not include both? Thanks in advance

#2

BME280.h is a C++ wrapper for mgos_bme280.h

If using the library in a C application, you only need to

#include "mgos_bme280.h"

You don’t need to add #include <mgos_i2c.h> or #include <mgos_spi.h> in the application.
Only

- ["i2c.enable", true]

or

- ["spi.enable", true]

are needed in mos.yml depending on the version of the sensor (I2C or SPI).