SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
esp_idf_sensor_hub/main/main.cpp
Go to the documentation of this file.
1
30#include "sdkconfig.h"
31#include "freertos/FreeRTOS.h"
32#include "i2c_driver.h"
33
34static const char *TAG = "main";
35
36#ifdef CONFIG_PCF8563
37extern esp_err_t pcf8563_init();
38extern void pcf8563_loop();
39#endif
40
41
42#ifdef CONFIG_BMA423
43extern esp_err_t bma423_init();
44extern void bma423_loop();
45#endif
46
47#ifdef CONFIG_FT636X
48extern esp_err_t ft63x6_init();
49extern void ft63x6_loop();
50#endif
51
52#ifdef CONFIG_BHI260
53extern esp_err_t bhi260_init();
54extern void bhi260_loop();
55#endif
56
57#ifdef CONFIG_XL9555
58extern esp_err_t xl9555_init();
59extern void xl9555_loop();
60#endif
61
62
63static void app_task(void *args);
64
65extern "C" void app_main(void)
66{
67
68#if CONFIG_I2C_COMMUNICATION_METHOD_BUILTIN_RW || CONFIG_I2C_COMMUNICATION_METHOD_CALLBACK_RW
69 ESP_ERROR_CHECK(i2c_drv_init());
70 ESP_LOGI(TAG, "I2C initialized successfully");
71
72 // Run bus scan
74#endif
75
76#ifdef CONFIG_PCF8563
77 ESP_ERROR_CHECK(pcf8563_init());
78#endif
79
80#ifdef CONFIG_BMA423
81 ESP_ERROR_CHECK(bma423_init());
82#endif
83
84#ifdef CONFIG_FT636X
85 ESP_ERROR_CHECK(ft63x6_init());
86#endif
87
88#ifdef CONFIG_BHI260
89 ESP_ERROR_CHECK(bhi260_init());
90#endif
91
92#ifdef CONFIG_XL9555
93 xl9555_init();
94#endif
95
96 ESP_LOGI(TAG, "Run...");
97
98 xTaskCreate(app_task, "App", 20 * 1024, NULL, 10, NULL);
99
100}
101
102static void app_task(void *args)
103{
104 while (1) {
105
106#ifdef CONFIG_BMA423
107 bma423_loop();
108 vTaskDelay(pdMS_TO_TICKS(1000));
109#endif
110
111#ifdef CONFIG_FT636X
112 ft63x6_loop();
113#endif
114
115#ifdef CONFIG_BHI260
116 bhi260_loop();
117#endif
118
119#ifdef CONFIG_XL9555
120 xl9555_loop();
121#endif
122
123 vTaskDelay(pdMS_TO_TICKS(10));
124 }
125}
126
127
128#if CONFIG_I2C_COMMUNICATION_METHOD_CALLBACK_RW
137uint32_t hal_callback(SensorCommCustomHal::Operation op, void *param1, void *param2)
138{
139 switch (op) {
140 // Set GPIO mode
142 uint8_t pin = reinterpret_cast<uintptr_t>(param1);
143 uint8_t mode = reinterpret_cast<uintptr_t>(param2);
144 gpio_config_t config;
145 memset(&config, 0, sizeof(config));
146 config.pin_bit_mask = 1ULL << pin;
147 switch (mode) {
148 case INPUT:
149 config.mode = GPIO_MODE_INPUT;
150 break;
151 case OUTPUT:
152 config.mode = GPIO_MODE_OUTPUT;
153 break;
154 }
155 config.pull_up_en = GPIO_PULLUP_DISABLE;
156 config.pull_down_en = GPIO_PULLDOWN_DISABLE;
157 config.intr_type = GPIO_INTR_DISABLE;
158 ESP_ERROR_CHECK(gpio_config(&config));
159 }
160 break;
161 // Set GPIO level
163 uint8_t pin = reinterpret_cast<uintptr_t>(param1);
164 uint8_t level = reinterpret_cast<uintptr_t>(param2);
165 gpio_set_level((gpio_num_t )pin, level);
166 }
167 break;
168 // Read GPIO level
170 uint8_t pin = reinterpret_cast<uintptr_t>(param1);
171 return gpio_get_level((gpio_num_t)pin);
172 }
173 break;
174 // Get the current running milliseconds
176 return (uint32_t) (esp_timer_get_time() / 1000LL);
177
178 // Delay in milliseconds
180 if (param1) {
181 uint32_t ms = reinterpret_cast<uintptr_t>(param1);
182 ets_delay_us((ms % portTICK_PERIOD_MS) * 1000UL);
183 }
184 }
185 break;
186 // Delay in microseconds
188 uint32_t us = reinterpret_cast<uintptr_t>(param1);
189 ets_delay_us(us);
190 }
191 break;
192 default:
193 break;
194 }
195 return 0;
196}
197
198
199#endif
uint8_t level
uint32_t hal_callback(SensorCommCustomHal::Operation op, void *param1, void *param2)
void app_main(void)
esp_err_t i2c_drv_init(void)
i2c master initialization
@license MIT License