-
Notifications
You must be signed in to change notification settings - Fork 0
/
esp-qmc-example.c
52 lines (41 loc) · 1.05 KB
/
esp-qmc-example.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//esp sdk
#include "espressif/esp_common.h"
#include "esp/uart.h"
//rtos
#include "FreeRTOS.h"
#include "task.h"
//device drivers
#include "i2c/i2c.h"
#include "qmc5883l.h"
#define I2C_BUS 0
#define SCL_PIN 4
#define SDA_PIN 5
#define magformat "X:\t%d\nY:\t%d\nZ:\t%d\n--------------------------------------\n"
i2c_dev_t* magnetometer;
void magnetometerReader(void *pvParameters) {
printf("looking for Magnetometer\n");
while(!qmc5883l_init(magnetometer)) {
printf("Device not found!\n");
}
qmc5883l_data_t data;
while(1) {
if( qmc5883l_get_data(magnetometer, &data) ) {
printf(magformat, data.x, data.y, data.z);
} else {
while(!qmc5883l_init(magnetometer)) {
printf("Device not found!\n");
}
}
vTaskDelay(100);
}
}
void user_init(void) {
uart_set_baud(0, 115200);
//connected hardware
i2c_init(I2C_BUS, SCL_PIN, SDA_PIN, I2C_FREQ_100K);
magnetometer = malloc(sizeof(i2c_dev_t));
magnetometer->addr = QMC5883L_ADDR;
magnetometer->bus = I2C_BUS;
//start tasks
xTaskCreate(magnetometerReader, "readData", 512, NULL, 2, NULL);
}