Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit67936a330a93c734c275182142b8b6ba52501ede (patch)
Author
 Syndamia <kamen@syndamia.com>
2024-05-04 16:32:10 +0300
Committer
 Syndamia <kamen@syndamia.com>
2024-05-04 16:32:10 +0300
Files6210e738c2b589354ba50fd1c5720858bf68562b
uni-projects-67936a330a93c734c275182142b8b6ba52501ede.tar
uni-projects-67936a330a93c734c275182142b8b6ba52501ede.tar.gz
uni-projects-67936a330a93c734c275182142b8b6ba52501ede.zip
Parent7cdc1d74d621fa512202c8705b860ccfc5e0c886 (diff)
[iot/goam] Added rought communication with camera
1 files changed, 55 insertions, 21 deletions
-rw-r--r--Year 3/Internet of things/goam/main/main.c76
diff --git a/Year 3/Internet of things/goam/main/main.c b/Year 3/Internet of things/goam/main/main.c
index d7969e3..607adb0 100644
--- a/Year 3/Internet of things/goam/main/main.c
+++ b/Year 3/Internet of things/goam/main/main.c
@@ -13,6 +13,8 @@
#include "esp_flash.h"
#include "driver/gpio.h"
+#include "driver/uart.h"
+#include <string.h>
void print_chip_data() {
/* Print chip information */
@@ -41,10 +43,15 @@ void print_chip_data() {
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
}
+#define GPIO_INPUT_CAMERA 13
+#define GPIO_OUTPUT_CAMERA 14
+
+#define gpio_to_bitmask(pin) (1ULL << pin)
+
#define ESP_INTR_FLAG_DEFAULT 0
-/* static QueueHandle_t gpio_evt_queue = NULL; */
-/* */
+static QueueHandle_t gpio_evt_queue = NULL;
+
/* static void IRAM_ATTR gpio_isr_handler(void* arg) */
/* { */
/* uint32_t gpio_num = (uint32_t) arg; */
@@ -53,39 +60,66 @@ void print_chip_data() {
void app_main(void)
{
- printf("Hello world!\n");
-
- print_chip_data();
-
- gpio_config_t io_conf = {
+ gpio_config_t o_conf = {
.intr_type = GPIO_INTR_DISABLE,
//set as output mode
.mode = GPIO_MODE_OUTPUT,
//bit mask of the pins that you want to set,e.g.GPIO18/19
- .pin_bit_mask = 1ULL << 13,
+ .pin_bit_mask = gpio_to_bitmask(GPIO_OUTPUT_CAMERA),
//disable pull-down mode
.pull_down_en = 0,
//disable pull-up mode
.pull_up_en = 0
};
- gpio_config(&io_conf);
+ gpio_config(&o_conf);
- /* //create a queue to handle gpio event from isr */
- /* gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t)); */
- /* //start gpio task */
- /* xTaskCreate(gpio_task_example, "gpio_task_example", 2048, NULL, 10, NULL); */
- /* */
- /* //install gpio isr service */
- /* gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT); */
- /* //hook isr handler for specific gpio pin */
- /* gpio_isr_handler_add(GPIO_INPUT_IO_0, gpio_isr_handler, (void*) GPIO_INPUT_IO_0); */
+
+
+
+
+ uart_config_t uart_config = {
+ .baud_rate = 115200,
+ .data_bits = UART_DATA_8_BITS,
+ .parity = UART_PARITY_DISABLE,
+ .stop_bits = UART_STOP_BITS_1,
+ .flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS,
+ .rx_flow_ctrl_thresh = 122,
+ };
+ // Configure UART parameters
+ ESP_ERROR_CHECK(uart_param_config(UART_NUM_2, &uart_config));
+
+ // Set UART pins(TX: IO17 (UART2 default), RX: IO16 (UART2 default), RTS: IO18, CTS: IO19)
+ ESP_ERROR_CHECK(uart_set_pin(UART_NUM_2, 17, 16, 18, 19));
+
+ // Setup UART buffered IO with event queue
+ QueueHandle_t uart_queue;
+ // Install UART driver using an event queue here
+ ESP_ERROR_CHECK(uart_driver_install(UART_NUM_2, 1024 * 2, 1024 * 2, 10, &uart_queue, 0));
+
+ printf("camera boot...\n");
+ vTaskDelay(3000 / portTICK_PERIOD_MS);
+
+ // Write data to UART.
+ const char reset[4] = { 0x56, 0x00, 0x26, 0x00 };
+ int am = uart_write_bytes(UART_NUM_2, (const char*)reset, 4);
+ ESP_ERROR_CHECK(uart_wait_tx_done(UART_NUM_2, 100));
+ printf("sent %d\n", am);
+
+ // Read data from UART.
+ uint8_t data[5] = { 0, 0, 0, 0, 0 };
+ int length = 4;
+ ESP_ERROR_CHECK(uart_get_buffered_data_len(UART_NUM_2, (size_t*)&am));
+ length = uart_read_bytes(UART_NUM_2, data, length, 5);
+ printf("got %d\n", length);
+
+ printf("result: %d %d %d %d\n", data[0], data[1], data[2], data[3]);
for (int i = 0; true; i++) {
- gpio_set_level(13, (i / 2) % 2);
- printf("%d seconds, %d\n", i, (i / 2) % 2);
+ gpio_set_level(GPIO_OUTPUT_CAMERA, (i / 2) % 2);
+ printf("%d seconds, %d\n", i, gpio_get_level(GPIO_INPUT_CAMERA));
vTaskDelay(1000 / portTICK_PERIOD_MS);
- /* gpio_set_level(13, i > 5); */
}
+
printf("Restarting now.\n");
fflush(stdout);
esp_restart();