Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP-DSP demo features for azure IoT dev board (BSP-296) #158

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions components/fbm320/fbm320.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
peter-marcisovsky marked this conversation as resolved.
Show resolved Hide resolved
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -174,7 +174,11 @@ esp_err_t fbm320_get_data(fbm320_handle_t sensor, const fbm320_measure_mode_t me
if (ESP_OK != ret) {
return ret;
}
vTaskDelay(10 / portTICK_PERIOD_MS);
if (meas_mode == FBM320_MEAS_PRESS_OSR_8192) {
vTaskDelay(20 / portTICK_PERIOD_MS);
} else {
vTaskDelay(10 / portTICK_PERIOD_MS);
}
ret = fbm320_read_result(sensor, &pressure_raw);
if (ESP_OK != ret) {
return ret;
Expand Down
2 changes: 1 addition & 1 deletion components/fbm320/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.0.3"
version: "1.0.4"
description: I2C driver for FBM320 digital barometer
url: https://github.com/espressif/esp-bsp/tree/master/components/fbm320
dependencies:
Expand Down
5 changes: 3 additions & 2 deletions components/fbm320/include/fbm320.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -31,7 +31,8 @@ extern "C" {
typedef enum {
FBM320_MEAS_PRESS_OSR_1024 = 0x34, /* 2.5ms wait for measurement */
FBM320_MEAS_PRESS_OSR_2048 = 0x74, /* 3.7ms wait for measurement */
FBM320_MEAS_PRESS_OSR_4096 = 0xB4 /* 6ms wait for measurement */
FBM320_MEAS_PRESS_OSR_4096 = 0xB4, /* 6ms wait for measurement */
FBM320_MEAS_PRESS_OSR_8192 = 0xF4 /* 11ms wait for measurement */
} fbm320_measure_mode_t;

typedef void *fbm320_handle_t;
Expand Down
2 changes: 1 addition & 1 deletion components/mag3110/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.0.6"
version: "1.0.7"
description: I2C driver for MAG3110 3-axis digital magnetometer
url: https://github.com/espressif/esp-bsp/tree/master/components/mag3110
dependencies:
Expand Down
16 changes: 15 additions & 1 deletion components/mag3110/include/mag3110.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -101,6 +101,20 @@ void mag3110_delete(mag3110_handle_t sensor);
*/
esp_err_t mag3110_start(mag3110_handle_t sensor, const mag3110_data_rate_t data_rate);

/**
* @brief Start mag3110 sensor to measure, in raw mode - ignoring the user offset register values that are set in
*
* mag3110_calibrate function, thus it is not needed to calibrate the sensor to run it in the raw mode
peter-marcisovsky marked this conversation as resolved.
Show resolved Hide resolved
*
* @param sensor object handle of mag3110
* @param[in] data_rate Data rate and oversampling settings
*
* @return
* - ESP_OK Success
* - ESP_FAIL Fail
*/
esp_err_t mag3110_start_raw(mag3110_handle_t sensor, const mag3110_data_rate_t data_rate);

/**
* @brief Stop MAG3110 measurement
*
Expand Down
12 changes: 11 additions & 1 deletion components/mag3110/mag3110.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -102,6 +102,16 @@ esp_err_t mag3110_start(mag3110_handle_t sensor, const mag3110_data_rate_t data_
return mag3110_write(sensor, MAG3110_CTRL_REG1, ctrl_reg, sizeof(ctrl_reg));
}

esp_err_t mag3110_start_raw(mag3110_handle_t sensor, const mag3110_data_rate_t data_rate)
{
uint8_t ctrl_reg[2];

ctrl_reg[0] = data_rate | MAG3110_ACTIVE_MODE;
ctrl_reg[1] = MAG3110_AUTO_MRST_EN | MAG3110_RAW_DATA;

return mag3110_write(sensor, MAG3110_CTRL_REG1, ctrl_reg, sizeof(ctrl_reg));
}

esp_err_t mag3110_stop(mag3110_handle_t sensor)
{
const uint8_t ctrl_reg1 = MAG3110_STANDBY_MODE;
Expand Down
2 changes: 1 addition & 1 deletion components/ssd1306/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.0.4"
version: "1.0.5"
description: I2C driver for SSD1306 OLED display
url: https://github.com/espressif/esp-bsp/tree/master/components/ssd1306
dependencies:
Expand Down
13 changes: 12 additions & 1 deletion components/ssd1306/include/ssd1306.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -141,6 +141,17 @@ void ssd1306_draw_3216char(ssd1306_handle_t dev, uint8_t chXpos, uint8_t chYpos,
void ssd1306_draw_bitmap(ssd1306_handle_t dev, uint8_t chXpos, uint8_t chYpos,
const uint8_t *pchBmp, uint8_t chWidth, uint8_t chHeight);

/**
* @brief draw line between two specified points
*
* @param dev object handle of ssd1306
* @param chXpos1 Specifies the X position of the starting point of the line
* @param chYpos1 Specifies the Y position of the starting point of the line
* @param chXpos2 Specifies the X position of the ending point of the line
* @param chYpos2 Specifies the Y position of the ending point of the line
*/
void ssd1306_draw_line(ssd1306_handle_t dev, int16_t chXpos1, int16_t chYpos1, int16_t chXpos2, int16_t chYpos2);

/**
* @brief refresh dot matrix panel
*
Expand Down
56 changes: 55 additions & 1 deletion components/ssd1306/ssd1306.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -11,6 +11,9 @@
#define SSD1306_WRITE_CMD (0x00)
#define SSD1306_WRITE_DAT (0x40)

#define COORDINATE_SWAP(x1, x2, y1, y2) { int16_t temp = x1; x1 = x2, x2 = temp; \
temp = y1; y1 = y2; y2 = temp; }

typedef struct {
i2c_port_t bus;
uint16_t dev_addr;
Expand Down Expand Up @@ -242,6 +245,57 @@ void ssd1306_draw_bitmap(ssd1306_handle_t dev, uint8_t chXpos, uint8_t chYpos,
}
}

peter-marcisovsky marked this conversation as resolved.
Show resolved Hide resolved
void ssd1306_draw_line(ssd1306_handle_t dev, int16_t chXpos1, int16_t chYpos1, int16_t chXpos2, int16_t chYpos2)
{
// 16-bit variables allowing a display overflow effect
int16_t x_len = abs(chXpos1 - chXpos2);
int16_t y_len = abs(chYpos1 - chYpos2);

if (y_len < x_len) {
if (chXpos1 > chXpos2) {
COORDINATE_SWAP(chXpos1, chXpos2, chYpos1, chYpos2);
}
int16_t len = x_len;
int16_t diff = y_len;

do {
if (diff >= x_len) {
diff -= x_len;
if (chYpos1 < chYpos2) {
chYpos1++;
} else {
chYpos1--;
}
}

diff += y_len;
ssd1306_fill_point(dev, chXpos1++, chYpos1, 1);
} while (len--);
}

else {
if (chYpos1 > chYpos2) {
COORDINATE_SWAP(chXpos1, chXpos2, chYpos1, chYpos2);
}
int16_t len = y_len;
int16_t diff = x_len;

do {
if (diff >= y_len) {
diff -= y_len;
if (chXpos1 < chXpos2) {
chXpos1++;
} else {
chXpos1--;
}
}

diff += x_len;
ssd1306_fill_point(dev, chXpos1, chYpos1++, 1);
} while (len--);
}
}

esp_err_t ssd1306_init(ssd1306_handle_t dev)
{
esp_err_t ret;
Expand Down
49 changes: 48 additions & 1 deletion esp32_azure_iot_kit/esp32_azure_iot_kit.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2021 Espressif Systems (Shanghai) CO LTD
// Copyright 2015-2023 Espressif Systems (Shanghai) CO LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,23 @@

sdmmc_card_t *bsp_sdcard = NULL;

typedef enum {
I2C_CLK_100K_LOW_PERIOD = 399, I2C_CLK_100K_HIGH_PERIOD = 387,
I2C_CLK_100K_DATA_SETUP = 200, I2C_CLK_100K_DATA_HOLD = 200,
I2C_CLK_100K_START_SETUP = 400, I2C_CLK_100K_START_HOLD = 400,
I2C_CLK_100K_STOP_SETUP = 400, I2C_CLK_100K_STOP_HOLD = 400,

I2C_CLK_400K_LOW_PERIOD = 99, I2C_CLK_400K_HIGH_PERIOD = 87,
I2C_CLK_400K_DATA_SETUP = 50, I2C_CLK_400K_DATA_HOLD = 50,
I2C_CLK_400K_START_SETUP = 100, I2C_CLK_400K_START_HOLD = 100,
I2C_CLK_400K_STOP_SETUP = 100, I2C_CLK_400K_STOP_HOLD = 100,

I2C_CLK_600K_LOW_PERIOD = 65, I2C_CLK_600K_HIGH_PERIOD = 53,
I2C_CLK_600K_DATA_SETUP = 33, I2C_CLK_600K_DATA_HOLD = 33,
I2C_CLK_600K_START_SETUP = 66, I2C_CLK_600K_START_HOLD = 66,
I2C_CLK_600K_STOP_SETUP = 66, I2C_CLK_600K_STOP_HOLD = 66
} bsp_i2c_clk_params_set_t;

esp_err_t bsp_i2c_init(void)
{
const i2c_config_t i2c_conf = {
Expand All @@ -41,6 +58,36 @@ esp_err_t bsp_i2c_deinit(void)
return ESP_OK;
}

esp_err_t bsp_i2c_set_clk_speed(bsp_i2c_clk_speed_t i2c_clk)
{
switch (i2c_clk) {
case I2C_CLK_100KHZ:
BSP_ERROR_CHECK_RETURN_ERR(i2c_set_period(BSP_I2C_NUM, I2C_CLK_100K_HIGH_PERIOD, I2C_CLK_100K_LOW_PERIOD));
BSP_ERROR_CHECK_RETURN_ERR(i2c_set_data_timing(BSP_I2C_NUM, I2C_CLK_100K_DATA_SETUP, I2C_CLK_100K_DATA_HOLD));
BSP_ERROR_CHECK_RETURN_ERR(i2c_set_start_timing(BSP_I2C_NUM, I2C_CLK_100K_START_SETUP, I2C_CLK_100K_START_HOLD));
BSP_ERROR_CHECK_RETURN_ERR(i2c_set_stop_timing(BSP_I2C_NUM, I2C_CLK_100K_STOP_SETUP, I2C_CLK_100K_STOP_HOLD));
break;

case I2C_CLK_400KHZ:
BSP_ERROR_CHECK_RETURN_ERR(i2c_set_period(BSP_I2C_NUM, I2C_CLK_400K_HIGH_PERIOD, I2C_CLK_400K_LOW_PERIOD));
BSP_ERROR_CHECK_RETURN_ERR(i2c_set_data_timing(BSP_I2C_NUM, I2C_CLK_400K_DATA_SETUP, I2C_CLK_400K_DATA_HOLD));
BSP_ERROR_CHECK_RETURN_ERR(i2c_set_start_timing(BSP_I2C_NUM, I2C_CLK_400K_START_SETUP, I2C_CLK_400K_START_HOLD));
BSP_ERROR_CHECK_RETURN_ERR(i2c_set_stop_timing(BSP_I2C_NUM, I2C_CLK_400K_STOP_SETUP, I2C_CLK_400K_STOP_HOLD));
break;

case I2C_CLK_600KHZ:
BSP_ERROR_CHECK_RETURN_ERR(i2c_set_period(BSP_I2C_NUM, I2C_CLK_600K_HIGH_PERIOD, I2C_CLK_600K_LOW_PERIOD));
BSP_ERROR_CHECK_RETURN_ERR(i2c_set_data_timing(BSP_I2C_NUM, I2C_CLK_600K_DATA_SETUP, I2C_CLK_600K_DATA_HOLD));
BSP_ERROR_CHECK_RETURN_ERR(i2c_set_start_timing(BSP_I2C_NUM, I2C_CLK_600K_START_SETUP, I2C_CLK_600K_START_HOLD));
BSP_ERROR_CHECK_RETURN_ERR(i2c_set_stop_timing(BSP_I2C_NUM, I2C_CLK_600K_STOP_SETUP, I2C_CLK_600K_STOP_HOLD));
break;

default:
break;
}
return ESP_OK;
}

esp_err_t bsp_leds_init(void)
{
const gpio_config_t led_io_config = {
Expand Down
2 changes: 1 addition & 1 deletion esp32_azure_iot_kit/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.0.2"
version: "1.0.3"
description: Board Support Package for ESP32-Azure-IoT-Kit
url: https://github.com/espressif/esp-bsp/tree/master/esp32_azure_iot_kit

Expand Down
18 changes: 17 additions & 1 deletion esp32_azure_iot_kit/include/bsp/esp32_azure_iot_kit.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
Expand Down Expand Up @@ -33,6 +33,12 @@ extern "C" {
#define BSP_I2C_SDA_IO GPIO_NUM_25
#define BSP_I2C_NUM CONFIG_BSP_I2C_NUM

typedef enum {
I2C_CLK_100KHZ = 0,
I2C_CLK_400KHZ = 1,
I2C_CLK_600KHZ = 2
} bsp_i2c_clk_speed_t;

/**
* @brief Init I2C driver
*
Expand All @@ -52,6 +58,16 @@ esp_err_t bsp_i2c_init(void);
*/
esp_err_t bsp_i2c_deinit(void);

/**
* @brief Set I2C clk after initialization of the I2C driver
*
* @param i2c_clk I2C clk frequency
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
*/
esp_err_t bsp_i2c_set_clk_speed(bsp_i2c_clk_speed_t i2c_clk);

/**************************************************************************************************
*
* uSD card
Expand Down