Formatted and added bmi task
This commit is contained in:
59
main/bbot.c
59
main/bbot.c
@@ -5,14 +5,13 @@
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
#include "motors.h"
|
||||
#include "bmi160.h"
|
||||
|
||||
#define BBOT_INPUT_PIN GPIO_NUM_1
|
||||
#define BBOT_BLINK_PIN GPIO_NUM_8
|
||||
#define BBOT_BLINK_DELAY_MS 500
|
||||
#define BBOT_DRDY_INPUT_PIN GPIO_NUM_1
|
||||
|
||||
#define BBOT_I2C_PORT I2C_NUM_0
|
||||
#define BBOT_I2C_SCL_IO GPIO_NUM_3
|
||||
@@ -20,33 +19,10 @@
|
||||
#define BBOT_I2C_FREQ_HZ 100000
|
||||
|
||||
static bmi160_t imu;
|
||||
static QueueHandle_t imu_queue;
|
||||
|
||||
static void init_blink_gpio(){
|
||||
const gpio_config_t io_conf = {
|
||||
.pin_bit_mask = (1ULL << BBOT_BLINK_PIN),
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
};
|
||||
|
||||
gpio_config(&io_conf);
|
||||
gpio_set_level(BBOT_BLINK_PIN, 0);
|
||||
}
|
||||
|
||||
static void init_input_gpio(){
|
||||
const gpio_config_t io_conf = {
|
||||
.pin_bit_mask = (1ULL << BBOT_INPUT_PIN),
|
||||
.mode = GPIO_MODE_INPUT,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
};
|
||||
|
||||
gpio_config(&io_conf);
|
||||
}
|
||||
|
||||
static void init_i2c(){
|
||||
static esp_err_t init_i2c()
|
||||
{
|
||||
const i2c_config_t i2c_conf = {
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.sda_io_num = BBOT_I2C_SDA_IO,
|
||||
@@ -58,22 +34,21 @@ static void init_i2c(){
|
||||
|
||||
ESP_ERROR_CHECK(i2c_param_config(BBOT_I2C_PORT, &i2c_conf));
|
||||
ESP_ERROR_CHECK(i2c_driver_install(BBOT_I2C_PORT, i2c_conf.mode, 0, 0, 0));
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void app_main(void){
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_ERROR_CHECK(init_motors());
|
||||
ESP_ERROR_CHECK(init_i2c());
|
||||
ESP_ERROR_CHECK(imu_init(&imu, BBOT_I2C_PORT, BBOT_DRDY_INPUT_PIN, &imu_queue));
|
||||
|
||||
init_input_gpio();
|
||||
init_blink_gpio();
|
||||
|
||||
init_motors();
|
||||
|
||||
init_i2c();
|
||||
imu_init(&imu, BBOT_I2C_PORT);
|
||||
|
||||
while (1) {
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
while (1)
|
||||
{
|
||||
bmi160_value_t v;
|
||||
imu_read(&imu, &v);
|
||||
ESP_LOGI("[<IMU>]", "%d %d %d %d %d %d", v.acc.x, v.acc.y, v.acc.z, v.gyr.x, v.gyr.y, v.gyr.z);
|
||||
while (xQueueReceive(imu_queue, &v, pdMS_TO_TICKS(1000)) == pdTRUE)
|
||||
{
|
||||
ESP_LOGI("[<IMU>]", "%d %d %d %d %d %d %d", v.time, v.acc.x, v.acc.y, v.acc.z, v.gyr.x, v.gyr.y, v.gyr.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user