Initial commit.
This commit is contained in:
commit
55888994c8
|
@ -0,0 +1,8 @@
|
|||
# For more information about build system see
|
||||
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
|
||||
# The following five lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(esp32_s2_cal_demo)
|
|
@ -0,0 +1,8 @@
|
|||
#
|
||||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
|
||||
# project subdirectory.
|
||||
#
|
||||
|
||||
PROJECT_NAME := sample_project
|
||||
|
||||
include $(IDF_PATH)/make/project.mk
|
|
@ -0,0 +1,32 @@
|
|||
# _Sample project_
|
||||
|
||||
(See the README.md file in the upper level 'examples' directory for more information about examples.)
|
||||
|
||||
This is the simplest buildable example. The example is used by command `idf.py create-project`
|
||||
that copies the project to user specified path and set it's name. For more information follow the [docs page](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html#start-a-new-project)
|
||||
|
||||
|
||||
|
||||
## How to use example
|
||||
We encourage the users to use the example as a template for the new projects.
|
||||
A recommended way is to follow the instructions on a [docs page](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html#start-a-new-project).
|
||||
|
||||
## Example folder contents
|
||||
|
||||
The project **sample_project** contains one source file in C language [main.c](main/main.c). The file is located in folder [main](main).
|
||||
|
||||
ESP-IDF projects are built using CMake. The project build configuration is contained in `CMakeLists.txt`
|
||||
files that provide set of directives and instructions describing the project's source files and targets
|
||||
(executable, library, or both).
|
||||
|
||||
Below is short explanation of remaining files in the project folder.
|
||||
|
||||
```
|
||||
├── CMakeLists.txt
|
||||
├── main
|
||||
│ ├── CMakeLists.txt
|
||||
│ └── main.c
|
||||
└── README.md This is the file you are currently reading
|
||||
```
|
||||
Additionally, the sample project contains Makefile and component.mk files, used for the legacy Make based build system.
|
||||
They are not used or needed when building with CMake and idf.py.
|
|
@ -0,0 +1,14 @@
|
|||
idf_component_register(SRCS
|
||||
"main.c"
|
||||
"app_task_led.c"
|
||||
"app_task_epd.c"
|
||||
"app_lib_i2c_system.c"
|
||||
"app_lib_bat_impl.c"
|
||||
"app_lib_epd_impl.c"
|
||||
"lib/gdew042t2_epd.c"
|
||||
"lib/ltc2941_battery.c"
|
||||
"lib/sht35_dht.c"
|
||||
INCLUDE_DIRS
|
||||
"."
|
||||
"./lib"
|
||||
)
|
|
@ -0,0 +1,15 @@
|
|||
#include "esp_log.h"
|
||||
#include "driver/i2c.h"
|
||||
|
||||
#include "app_lib_bat_impl.h"
|
||||
|
||||
#define LTC2941_ADDR 0x64 // Unshifted
|
||||
|
||||
static const char *TAG = "BAT_IMPL"
|
||||
|
||||
ltc2941_ret_t app_lib_bat_read_register(app_lib_bat_impl_t *impl, uint8_t reg, uint8_t *value) {
|
||||
|
||||
}
|
||||
ltc2941_ret_t app_lib_bat_write_register(app_lib_bat_impl_t *impl, uint8_t reg, uint8_t value) {
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef __APP_LIB_BAT_IMPL_H
|
||||
#define __APP_LIB_BAT_IMPL_H
|
||||
|
||||
#include "ltc2941_battery.h"
|
||||
|
||||
typedef struct {
|
||||
|
||||
} app_lib_bat_impl_t;
|
||||
|
||||
ltc2941_ret_t app_lib_bat_read_register(app_lib_bat_impl_t *impl, uint8_t reg, uint8_t *value);
|
||||
ltc2941_ret_t app_lib_bat_write_register(app_lib_bat_impl_t *impl, uint8_t reg, uint8_t value);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef __APP_LIB_EPD_IMPL_H
|
||||
#define __APP_LIB_EPD_IMPL_H
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,20 @@
|
|||
#include "esp_log.h"
|
||||
#include "driver/i2c.h"
|
||||
|
||||
#include "user_board.h"
|
||||
|
||||
void app_lib_i2c_system_init(void) {
|
||||
i2c_config_t conf = {
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.sda_io_num = BOARD_SYSTEM_I2C_SDA_PIN,
|
||||
.scl_io_num = BOARD_SYSTEM_I2C_SCL_PIN,
|
||||
.sda_pullup_en = GPIO_PULLUP_DISABLE,
|
||||
.scl_pullup_en = GPIO_PULLUP_DISABLE,
|
||||
.master.clk_speed = 400000
|
||||
};
|
||||
|
||||
esp_err_t err = i2c_param_config(BOARD_SYSTEM_I2C_NUM, &conf);
|
||||
if(err != ESP_OK) return;
|
||||
|
||||
i2c_driver_install(BOARD_SYSTEM_I2C_NUM, conf.mode, 0, 0, 0);
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
|
||||
#include "gdew042t2_epd.h"
|
||||
|
||||
void vTaskEPDExample(void *pvParameters) {
|
||||
for(;;) {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/ledc.h"
|
||||
|
||||
#include "user_board.h"
|
||||
|
||||
#define BREATHE_LED_NUM 3
|
||||
|
||||
TaskHandle_t xTaskLEDsHandle = NULL;
|
||||
void vTaskLEDs(void *pvParameters) {
|
||||
ledc_timer_config_t ledc_timer = {
|
||||
.duty_resolution = LEDC_TIMER_13_BIT,
|
||||
.freq_hz = 5000,
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.timer_num = LEDC_TIMER_0,
|
||||
.clk_cfg = LEDC_AUTO_CLK
|
||||
};
|
||||
|
||||
ledc_timer_config(&ledc_timer);
|
||||
|
||||
ledc_channel_config_t ledc_channels[BOARD_LED_NUM] = {
|
||||
{
|
||||
.channel = LEDC_CHANNEL_0,
|
||||
.duty = 0,
|
||||
.gpio_num = BOARD_RGB_LED_R_PIN,
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.hpoint = 0,
|
||||
.timer_sel = LEDC_TIMER_0,
|
||||
.flags.output_invert = 1
|
||||
},
|
||||
{
|
||||
.channel = LEDC_CHANNEL_1,
|
||||
.duty = 0,
|
||||
.gpio_num = BOARD_RGB_LED_G_PIN,
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.hpoint = 0,
|
||||
.timer_sel = LEDC_TIMER_0,
|
||||
.flags.output_invert = 1
|
||||
},
|
||||
{
|
||||
.channel = LEDC_CHANNEL_2,
|
||||
.duty = 0,
|
||||
.gpio_num = BOARD_RGB_LED_B_PIN,
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.hpoint = 0,
|
||||
.timer_sel = LEDC_TIMER_0,
|
||||
.flags.output_invert = 1
|
||||
},
|
||||
{
|
||||
.channel = LEDC_CHANNEL_3,
|
||||
.duty = 0,
|
||||
.gpio_num = BOARD_RGB_LED_W_PIN,
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.hpoint = 0,
|
||||
.timer_sel = LEDC_TIMER_0,
|
||||
.flags.output_invert = 1
|
||||
},
|
||||
{
|
||||
.channel = LEDC_CHANNEL_4,
|
||||
.duty = 0,
|
||||
.gpio_num = BOARD_LED1_PIN,
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.hpoint = 0,
|
||||
.timer_sel = LEDC_TIMER_0,
|
||||
.flags.output_invert = 1
|
||||
},
|
||||
{
|
||||
.channel = LEDC_CHANNEL_5,
|
||||
.duty = 0,
|
||||
.gpio_num = BOARD_LED2_PIN,
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.hpoint = 0,
|
||||
.timer_sel = LEDC_TIMER_0,
|
||||
.flags.output_invert = 1
|
||||
}
|
||||
};
|
||||
|
||||
for(uint8_t i = 0; i < BOARD_LED_NUM; i++) {
|
||||
ledc_channel_config(&ledc_channels[i]);
|
||||
}
|
||||
|
||||
ledc_fade_func_install(0);
|
||||
|
||||
for(;;) {
|
||||
ledc_set_fade_with_time(ledc_channels[BREATHE_LED_NUM].speed_mode,
|
||||
ledc_channels[BREATHE_LED_NUM].channel, 1023, 2500);
|
||||
ledc_fade_start(ledc_channels[BREATHE_LED_NUM].speed_mode,
|
||||
ledc_channels[BREATHE_LED_NUM].channel, LEDC_FADE_NO_WAIT);
|
||||
vTaskDelay(pdMS_TO_TICKS(2500));
|
||||
|
||||
ledc_set_fade_with_time(ledc_channels[BREATHE_LED_NUM].speed_mode,
|
||||
ledc_channels[BREATHE_LED_NUM].channel, 0, 2500);
|
||||
ledc_fade_start(ledc_channels[BREATHE_LED_NUM].speed_mode,
|
||||
ledc_channels[BREATHE_LED_NUM].channel, LEDC_FADE_NO_WAIT);
|
||||
vTaskDelay(pdMS_TO_TICKS(2500));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
#
|
||||
# "main" pseudo-component makefile.
|
||||
#
|
||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
|
@ -0,0 +1,54 @@
|
|||
#include "gdew042t2_epd.h"
|
||||
|
||||
gd_epd_042_ret_t gd_epd_042_init(gd_epd_042_t *epd) {
|
||||
epd->cb.reset_cb(epd->user_data);
|
||||
|
||||
uint8_t tx_buf[4] = { 0x06, 0x17, 0x17, 0x17 };
|
||||
epd->cb.write_cmd_cb(epd->user_data, tx_buf, 0x04);
|
||||
|
||||
tx_buf[0] = 0x04;
|
||||
epd->cb.write_cmd_cb(epd->user_data, tx_buf, 0x01);
|
||||
epd->cb.poll_busy_cb(epd->user_data);
|
||||
|
||||
tx_buf[0] = 0x00;
|
||||
tx_buf[1] = 0x1F;
|
||||
tx_buf[2] = 0x0D;
|
||||
epd->cb.write_cmd_cb(epd->user_data, tx_buf, 0x03);
|
||||
return EPD_OK;
|
||||
}
|
||||
|
||||
gd_epd_042_ret_t gd_epd_042_deepsleep(gd_epd_042_t *epd) {
|
||||
uint8_t tx_buf[3] = { 0x50, 0xF7 };
|
||||
epd->cb.write_cmd_cb(epd->user_data, tx_buf, 0x02);
|
||||
|
||||
tx_buf[0] = 0x02;
|
||||
epd->cb.write_cmd_cb(epd->user_data, tx_buf, 0x01);
|
||||
epd->cb.poll_busy_cb(epd->user_data);
|
||||
|
||||
tx_buf[0] = 0x07;
|
||||
tx_buf[1] = 0xA5;
|
||||
epd->cb.write_cmd_cb(epd->user_data, tx_buf, 0x01);
|
||||
|
||||
return EPD_OK;
|
||||
}
|
||||
|
||||
gd_epd_042_ret_t gd_epd_042_load(gd_epd_042_t *epd, uint8_t *old_data, uint8_t *new_data) {
|
||||
uint8_t tx_buf[2] = { 0x10 };
|
||||
epd->cb.write_cmd_cb(epd->user_data, tx_buf, 0x01);
|
||||
|
||||
epd->cb.write_data_cb(epd->user_data, old_data, 400 * 300 / 8);
|
||||
|
||||
tx_buf[0] = 0x13;
|
||||
epd->cb.write_cmd_cb(epd->user_data, tx_buf, 0x01);
|
||||
epd->cb.write_data_cb(epd->user_data, new_data, 400 * 300 / 8);
|
||||
|
||||
return EPD_OK;
|
||||
}
|
||||
|
||||
gd_epd_042_ret_t gd_epd_042_update(gd_epd_042_t *epd) {
|
||||
uint8_t tx_buf[2] = { 0x12 };
|
||||
epd->cb.write_cmd_cb(epd->user_data, tx_buf, 0x01);
|
||||
|
||||
epd->cb.poll_busy_cb(epd->user_data);
|
||||
return EPD_OK;
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef __GDEW042T2_EPD_H
|
||||
#define __GDEW042T2_EPD_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
EPD_OK = 0,
|
||||
EPD_ERR = 1
|
||||
} gd_epd_042_ret_t;
|
||||
|
||||
typedef struct {
|
||||
gd_epd_042_ret_t (* write_cmd_cb)(void *handle, uint8_t *cmd, uint8_t len);
|
||||
gd_epd_042_ret_t (* write_data_cb)(void *handle, uint8_t *data, uint32_t len);
|
||||
gd_epd_042_ret_t (* reset_cb)(void *handle);
|
||||
gd_epd_042_ret_t (* poll_busy_cb)(void *handle);
|
||||
} gd_epd_042_cb_t;
|
||||
|
||||
typedef struct {
|
||||
gd_epd_042_cb_t cb;
|
||||
void *user_data;
|
||||
} gd_epd_042_t;
|
||||
|
||||
gd_epd_042_ret_t gd_epd_042_init(gd_epd_042_t *epd);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,32 @@
|
|||
#include "ltc2941_battery.h"
|
||||
|
||||
#define LTC2941_REG_STATUS 0x00
|
||||
#define LTC2941_REG_CONTROL 0x01
|
||||
#define LTC2941_REG_CHARGE_MSB 0x02
|
||||
#define LTC2941_REG_CHARGE_LSB 0x03
|
||||
|
||||
ltc2941_ret_t ltc2941_init(ltc2941_t *bat) {
|
||||
|
||||
uint8_t control_reg =
|
||||
((bat->config.alert_mode & 0x03U) << 0x01U) |
|
||||
((bat->config.prescaler & 0x07U) << 0x03U) |
|
||||
((bat->config.alert_level & 0x03U) << 0x06U);
|
||||
|
||||
bat->cb.write_register_cb(bat->user_data, LTC2941_REG_CONTROL, control_reg);
|
||||
return LTC2941_OK;
|
||||
}
|
||||
|
||||
ltc2941_ret_t ltc2941_read_status(ltc2941_t *bat, uint8_t *status) {
|
||||
return bat->cb.read_register_cb(bat->user_data, LTC2941_REG_STATUS, status);
|
||||
}
|
||||
|
||||
ltc2941_ret_t ltc2941_read_charge(ltc2941_t *bat, uint16_t *charge) {
|
||||
uint8_t reg = 0x00;
|
||||
bat->cb.read_register_cb(bat->user_data, LTC2941_REG_CHARGE_MSB, ®);
|
||||
*charge = reg << 0x08U;
|
||||
|
||||
bat->cb.read_register_cb(bat->user_data, LTC2941_REG_CHARGE_LSB, ®);
|
||||
*charge |= reg;
|
||||
|
||||
return LTC2941_OK;
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
#ifndef __LTC2941_BATTERY_H
|
||||
#define __LTC2941_BATTERY_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
LTC2941_OK,
|
||||
LTC2941_ERROR
|
||||
} ltc2941_ret_t;
|
||||
|
||||
typedef enum {
|
||||
LTC2941_ALERT_3_0V = 0x03,
|
||||
LTC2941_ALERT_2_9V = 0x02,
|
||||
LTC2941_ALERT_2_8V = 0x01,
|
||||
LTC2941_ALERT_OFF = 0x00
|
||||
} ltc2941_battery_alert_t;
|
||||
|
||||
typedef enum {
|
||||
LTC2941_PRE_1 = 0x00,
|
||||
LTC2941_PRE_2 = 0x01,
|
||||
LTC2941_PRE_4 = 0x02,
|
||||
LTC2941_PRE_8 = 0x03,
|
||||
LTC2941_PRE_16 = 0x04,
|
||||
LTC2941_PRE_32 = 0x05,
|
||||
LTC2941_PRE_64 = 0x06,
|
||||
LTC2941_PRE_128 = 0x07
|
||||
} ltc2941_prescale_t;
|
||||
|
||||
typedef enum {
|
||||
LTC2941_ALERT_DISABLED = 0x00,
|
||||
LTC2941_ALERT_CC = 0x01,
|
||||
LTC2941_ALERT_AL = 0x02
|
||||
} ltc2941_alert_mode_t;
|
||||
|
||||
typedef struct {
|
||||
ltc2941_ret_t (*write_register_cb)(void * handle, uint8_t reg, uint8_t value);
|
||||
ltc2941_ret_t (*read_register_cb)(void *handle, uint8_t reg, uint8_t *value);
|
||||
} ltc2941_cb_t;
|
||||
|
||||
typedef struct {
|
||||
ltc2941_prescale_t prescaler;
|
||||
ltc2941_alert_mode_t alert_mode;
|
||||
ltc2941_battery_alert_t alert_level;
|
||||
} ltc2941_config_t;
|
||||
|
||||
typedef struct {
|
||||
ltc2941_cb_t cb;
|
||||
ltc2941_config_t config;
|
||||
void *user_data;
|
||||
} ltc2941_t;
|
||||
|
||||
#define LTC2941_STATUS_CHIPID (1 << 7U)
|
||||
#define LTC2941_STATUS_OVERFLOW (1 << 5U)
|
||||
#define LTC2941_STATUS_ALRT_HIGH (1 << 3U)
|
||||
#define LTC2941_STATUS_ALRT_LOW (1 << 2U)
|
||||
#define LTC2941_STATUS_ALRT_VBAT (1 << 1U)
|
||||
#define LTC2941_STATUS_ALRT_UVLO 1U
|
||||
|
||||
#endif
|
|
@ -0,0 +1,21 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
|
||||
#include "driver/gpio.h"
|
||||
|
||||
void vTaskLEDs(void *pvParameters);
|
||||
extern TaskHandle_t xTaskLEDsHandle;
|
||||
|
||||
void app_lib_i2c_system_init(void);
|
||||
|
||||
void app_main(void) {
|
||||
app_lib_i2c_system_init();
|
||||
xTaskCreate(vTaskLEDs, "TASK_LEDs", 1024, NULL, 4, &xTaskLEDsHandle);
|
||||
|
||||
for(;;) {
|
||||
vTaskSuspend(NULL);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef __USER_BOARD_H
|
||||
#define __USER_BOARD_H
|
||||
|
||||
#define BOARD_LED1_PIN GPIO_NUM_8
|
||||
#define BOARD_LED2_PIN GPIO_NUM_9
|
||||
|
||||
#define BOARD_RGB_LED_R_PIN GPIO_NUM_16
|
||||
#define BOARD_RGB_LED_G_PIN GPIO_NUM_17
|
||||
#define BOARD_RGB_LED_B_PIN GPIO_NUM_18
|
||||
#define BOARD_RGB_LED_W_PIN GPIO_NUM_21
|
||||
|
||||
#define BOARD_RGB_LED_NUM 4
|
||||
#define BOARD_LED_NUM 6
|
||||
|
||||
#define BOARD_SYSTEM_I2C_NUM I2C_NUM_0
|
||||
#define BOARD_SYSTEM_I2C_SDA_PIN GPIO_NUM_39
|
||||
#define BOARD_SYSTEM_I2C_SCL_PIN GPIO_NUM_40
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue