This commit is contained in:
leo 2022-11-26 14:22:50 +01:00
parent 2acd83103f
commit ffc4831b9a
Signed by: leo
GPG Key ID: 0DD993BFB2B307DB
8 changed files with 5757 additions and 0 deletions

1603
MMC5603_i2c.vcd Normal file

File diff suppressed because it is too large Load Diff

4081
SCD4x_i2c.vcd Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,3 @@
idf_component_register(SRCS "MMC56x3.c" "MMC56x3_hal.c"
INCLUDE_DIRS "include"
REQUIRES "driver")

View File

@ -0,0 +1,17 @@
#include <stdio.h>
#include "MMC56x3.h"
#include "MMC56x3_hal.h"
#include "esp_err.h"
#define PRODUCT_ID_1 0x39
#define TEMPERATURE 0x09
esp_err_t MMC56x3_get_product_ID(uint8_t* id){
ESP_ERROR_CHECK(i2c_read_reg(PRODUCT_ID_1, id, 1));
return ESP_OK;
}
esp_err_t MMC56x3_get_temperature(uint8_t* temp){
ESP_ERROR_CHECK(i2c_read_reg(TEMPERATURE, temp, 1));
return ESP_OK;
}

View File

@ -0,0 +1,39 @@
#include "esp_err.h"
#include "driver/i2c.h"
#include "MMC56x3_hal.h"
#include "hal/i2c_types.h"
#define MMC56x3_I2C_ADDRESS 0x30
esp_err_t i2c_read_reg(uint8_t address, uint8_t* data, uint16_t count){
esp_err_t err=ESP_OK;
i2c_write(&address, 1);
i2c_read(data, count);
return err;
}
esp_err_t i2c_read(uint8_t* data, uint16_t count){
i2c_cmd_handle_t cmdLnk = i2c_cmd_link_create();
esp_err_t err = ESP_OK;
err = i2c_master_start(cmdLnk);
err = i2c_master_write_byte(cmdLnk, MMC56x3_I2C_ADDRESS << 1 | I2C_MASTER_READ, true);
if(count>1)
err = i2c_master_read(cmdLnk, data, count-1, I2C_MASTER_ACK);
err = i2c_master_read(cmdLnk, data + count - 1, 1, I2C_MASTER_NACK);
err = i2c_master_stop(cmdLnk);
i2c_master_cmd_begin(I2C_NUM_0,cmdLnk,1000 / portTICK_PERIOD_MS);
i2c_cmd_link_delete(cmdLnk);
return err;
}
esp_err_t i2c_write(const uint8_t* data, uint16_t count){
i2c_cmd_handle_t cmdLnk = i2c_cmd_link_create();
esp_err_t err = ESP_OK;
err = i2c_master_start(cmdLnk);
err = i2c_master_write_byte(cmdLnk, MMC56x3_I2C_ADDRESS << 1 | I2C_MASTER_WRITE, true);
err = i2c_master_write(cmdLnk, data, count, true);
err = i2c_master_stop(cmdLnk);
i2c_master_cmd_begin(I2C_NUM_0,cmdLnk,1000 / portTICK_PERIOD_MS); /* TODO:non const port */
i2c_cmd_link_delete(cmdLnk);
return err;
}

View File

@ -0,0 +1,3 @@
#include "esp_err.h"
esp_err_t MMC56x3_get_product_ID(uint8_t* id);
esp_err_t MMC56x3_get_temperature(uint8_t* temp);

View File

@ -0,0 +1,4 @@
#include "esp_err.h"
esp_err_t i2c_read_reg(uint8_t address, uint8_t* data, uint16_t count);
esp_err_t i2c_read(uint8_t* data, uint16_t count);
esp_err_t i2c_write(const uint8_t* data, uint16_t count);

View File

@ -20,6 +20,7 @@
#include "sensirion_i2c_hal.h"
#include "scd4x_data.h"
#include "BTlib_nimble.h"
#include "MMC56x3.h"
void app_main(void){
init_nvs();
@ -49,7 +50,13 @@ void app_main(void){
initBle(conf);
// start sensor
init_i2c();
init_scd4x();
uint8_t id=0;
MMC56x3_get_product_ID(&id);
ESP_LOGI("MAIN", "MMC5603 product id %d", id);
switch(conf->sensor->mode){
case SCD4X_NORMAL_MODE:
ESP_ERROR_CHECK(scd4x_start_periodic_measurement());