33 lines
880 B
C
33 lines
880 B
C
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include "MMC56x3.h"
|
|
#include "MMC56x3_hal.h"
|
|
#include "esp_err.h"
|
|
#include "esp_log.h"
|
|
|
|
#define PRODUCT_ID_1 0x39
|
|
#define TEMPERATURE 0x09
|
|
#define IC0 0x1B
|
|
#define STATUS1 0x18
|
|
|
|
#define TAKE_MEAS_T 1
|
|
#define MEAS_T_DONE 7
|
|
|
|
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){
|
|
uint8_t startMeas = 1<<TAKE_MEAS_T;
|
|
ESP_ERROR_CHECK(i2c_write_reg(IC0, &startMeas, 1));
|
|
for(int i=0; i<5; i++){ // wait for meas_t_done
|
|
uint8_t status1_content;
|
|
ESP_ERROR_CHECK(i2c_read_reg(STATUS1, &status1_content, 1));
|
|
ESP_LOGI("MMC56x3", "status 1 %d", status1_content);
|
|
if(status1_content & (1 << MEAS_T_DONE)) break;
|
|
i2c_hal_wait_ms(1);
|
|
}
|
|
ESP_ERROR_CHECK(i2c_read_reg(TEMPERATURE, temp, 1));
|
|
return ESP_OK;
|
|
} |