80 lines
1.9 KiB
C
80 lines
1.9 KiB
C
#include <stdio.h>
|
|
|
|
#include "driver/gpio.h"
|
|
#include "driver/i2c.h"
|
|
#include "esp_err.h"
|
|
#include "esp_log.h"
|
|
#include "freertos/FreeRTOS.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_I2C_PORT I2C_NUM_0
|
|
#define BBOT_I2C_SCL_IO GPIO_NUM_3
|
|
#define BBOT_I2C_SDA_IO GPIO_NUM_2
|
|
#define BBOT_I2C_FREQ_HZ 100000
|
|
|
|
static bmi160_t imu;
|
|
|
|
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(){
|
|
const i2c_config_t i2c_conf = {
|
|
.mode = I2C_MODE_MASTER,
|
|
.sda_io_num = BBOT_I2C_SDA_IO,
|
|
.scl_io_num = BBOT_I2C_SCL_IO,
|
|
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
|
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
|
.master.clk_speed = BBOT_I2C_FREQ_HZ,
|
|
};
|
|
|
|
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));
|
|
}
|
|
|
|
void app_main(void){
|
|
|
|
init_input_gpio();
|
|
init_blink_gpio();
|
|
|
|
init_motors();
|
|
|
|
init_i2c();
|
|
imu_init(&imu, BBOT_I2C_PORT);
|
|
|
|
while (1) {
|
|
vTaskDelay(pdMS_TO_TICKS(10));
|
|
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);
|
|
}
|
|
}
|