Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of the module for the sensor "SGP30" #199

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "MicroPython_BUILD/components/micropython/esp32/libs/sgp"]
path = MicroPython_BUILD/components/micropython/esp32/libs/sgp
url = https://github.com/Sensirion/embedded-sgp.git
[submodule "MicroPython_BUILD/components/micropython/esp32/libs/sgp"]
path = MicroPython_BUILD/components/micropython/esp32/libs/sgp
url = [email protected]:Sensirion/embedded-sgp.git
6 changes: 6 additions & 0 deletions MicroPython_BUILD/components/micropython/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ menu "MicroPython"
default n
help
Include Display module into build

config MICROPY_USE_SGP30_SENSOR
bool "Use SGP30 sensor"
default n
help
Include sensor driver SGP30 into build

config MICROPY_USE_TFT
depends on MICROPY_USE_DISPLAY
Expand Down
17 changes: 17 additions & 0 deletions MicroPython_BUILD/components/micropython/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ ifdef CONFIG_MICROPY_USE_REQUESTS
MP_EXTRA_INC += -I$(ESPCOMP)/esp_http_client/include/
endif

ifdef CONFIG_MICROPY_USE_SGP30_SENSOR
MP_EXTRA_INC += -I$(COMPONENT_PATH)/esp32/libs/sgp/sgp30
MP_EXTRA_INC += -I$(COMPONENT_PATH)/esp32/libs/sgp/embedded-common
MP_EXTRA_INC += -I$(COMPONENT_PATH)/esp32/libs/sgp/sgp-common
endif

# CPP macro
# ------------
CPP = $(CC) -E
Expand Down Expand Up @@ -189,6 +195,10 @@ ifdef CONFIG_MICROPY_USE_DISPLAY
SRC_C += esp32/moddisplay.c
endif

ifdef CONFIG_MICROPY_USE_SGP30_SENSOR
SRC_C += esp32/modsgp30.c
endif

ifdef CONFIG_MICROPY_USE_CURL
SRC_C += esp32/modcurl.c
endif
Expand Down Expand Up @@ -278,6 +288,13 @@ LIBS_SRC_C += \
esp32/libs/tft/def_small.c
endif

ifdef CONFIG_MICROPY_USE_SGP30_SENSOR
LIBS_SRC_C += \
esp32/libs/sgp/sgp30/sgp30.c \
esp32/libs/sgp/sgp30/sgp30_featureset.c \
esp32/libs/sgp/embedded-common/sensirion_common.c
endif

ifdef CONFIG_MICROPY_USE_EVE
LIBS_SRC_C += \
esp32/libs/eve/FT8_commands.c \
Expand Down
1 change: 1 addition & 0 deletions MicroPython_BUILD/components/micropython/esp32/libs/sgp
Submodule sgp added at 8919f3
24 changes: 3 additions & 21 deletions MicroPython_BUILD/components/micropython/esp32/machine_hw_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "py/obj.h"

#include "modmachine.h"
#include "machine_hw_i2c.h"

#define I2C_ACK_CHECK_EN (1)
#define I2C_RX_MAX_BUFF_LEN 2048 // maximum low level commands receive buffer length
Expand All @@ -53,25 +54,6 @@
#define I2C_SLAVE_CBTYPE_DATA_RX 2
#define I2C_SLAVE_CBTYPE_DATA_TX 4

typedef struct _mp_machine_i2c_obj_t {
mp_obj_base_t base;
uint32_t speed;
uint8_t mode;
uint8_t scl;
uint8_t sda;
int8_t bus_id;
i2c_cmd_handle_t cmd;
uint16_t rx_buflen; // low level commands receive buffer length
uint16_t rx_bufidx; // low level commands receive buffer index
uint8_t *rx_data; // low level commands receive buffer
int8_t slave_addr; // slave only, slave 8-bit address
uint16_t slave_buflen; // slave only, data buffer length
uint16_t slave_rolen; // slave only, read only buffer area length
uint32_t *slave_cb; // slave only, slave callback function
bool slave_busy;
uint8_t slave_cbtype;
} mp_machine_i2c_obj_t;


extern int MainTaskCore;

Expand Down Expand Up @@ -121,7 +103,7 @@ STATIC esp_err_t i2c_init_slave (mp_machine_i2c_obj_t *i2c_obj, bool busy)
}

//------------------------------------------------------------------------------------------------------------------------------------------------------------
STATIC int mp_i2c_master_write(mp_machine_i2c_obj_t *i2c_obj, uint16_t slave_addr, uint8_t memwrite, uint32_t memaddr, uint8_t *data, uint16_t len, bool stop)
int mp_i2c_master_write(mp_machine_i2c_obj_t *i2c_obj, uint16_t slave_addr, uint8_t memwrite, uint32_t memaddr, uint8_t *data, uint16_t len, bool stop)
{
esp_err_t ret = ESP_FAIL;

Expand Down Expand Up @@ -154,7 +136,7 @@ STATIC int mp_i2c_master_write(mp_machine_i2c_obj_t *i2c_obj, uint16_t slave_add
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------
STATIC int mp_i2c_master_read(mp_machine_i2c_obj_t *i2c_obj, uint16_t slave_addr, uint8_t memread, uint32_t memaddr, uint8_t *data, uint16_t len, bool stop)
int mp_i2c_master_read(mp_machine_i2c_obj_t *i2c_obj, uint16_t slave_addr, uint8_t memread, uint32_t memaddr, uint8_t *data, uint16_t len, bool stop)
{
esp_err_t ret = ESP_FAIL;

Expand Down
36 changes: 36 additions & 0 deletions MicroPython_BUILD/components/micropython/esp32/machine_hw_i2c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* machine_hw_i2c.h
*
* Created on: 31 июл. 2018 г.
* Author: vrubel
*/

#ifndef COMPONENTS_MICROPYTHON_ESP32_MACHINE_HW_I2C_H_
#define COMPONENTS_MICROPYTHON_ESP32_MACHINE_HW_I2C_H_

#include "driver/i2c.h"
#include "py/obj.h"

typedef struct _mp_machine_i2c_obj_t {
mp_obj_base_t base;
uint32_t speed;
uint8_t mode;
uint8_t scl;
uint8_t sda;
int8_t bus_id;
i2c_cmd_handle_t cmd;
uint16_t rx_buflen; // low level commands receive buffer length
uint16_t rx_bufidx; // low level commands receive buffer index
uint8_t *rx_data; // low level commands receive buffer
int8_t slave_addr; // slave only, slave 8-bit address
uint16_t slave_buflen; // slave only, data buffer length
uint16_t slave_rolen; // slave only, read only buffer area length
uint32_t *slave_cb; // slave only, slave callback function
bool slave_busy;
uint8_t slave_cbtype;
} mp_machine_i2c_obj_t;

int mp_i2c_master_write(mp_machine_i2c_obj_t *i2c_obj, uint16_t slave_addr, uint8_t memwrite, uint32_t memaddr, uint8_t *data, uint16_t len, bool stop);
int mp_i2c_master_read(mp_machine_i2c_obj_t *i2c_obj, uint16_t slave_addr, uint8_t memread, uint32_t memaddr, uint8_t *data, uint16_t len, bool stop);

#endif /* COMPONENTS_MICROPYTHON_ESP32_MACHINE_HW_I2C_H_ */
Loading