diff --git a/Firmware/CMakeLists.txt b/Firmware/CMakeLists.txt index ab23837..6531502 100644 --- a/Firmware/CMakeLists.txt +++ b/Firmware/CMakeLists.txt @@ -135,6 +135,7 @@ target_link_options(${EXECUTABLE} PRIVATE -Wl,--start-group -lc -lm + -lnosys -lstdc++ -Wl,--end-group -Wl,--print-memory-usage) diff --git a/Firmware/Core/Cam/Cam.c b/Firmware/Core/Cam/Cam.c index 15db321..ba9c9b9 100644 --- a/Firmware/Core/Cam/Cam.c +++ b/Firmware/Core/Cam/Cam.c @@ -207,11 +207,11 @@ void Cam_Start_Burst_Read(SPI_HandleTypeDef *hspi) void Cam_Capture(SPI_HandleTypeDef *hspi) { - LED_On(); + //LED_On(); Cam_Start_Capture(hspi); Cam_Wait_Capture_Done(hspi); - LED_Off(); + //LED_Off(); } \ No newline at end of file diff --git a/Firmware/Core/Src/main.c b/Firmware/Core/Src/main.c index 3b6a80c..67a2497 100644 --- a/Firmware/Core/Src/main.c +++ b/Firmware/Core/Src/main.c @@ -68,6 +68,7 @@ static void MX_USB_PCD_Init(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ +/* static unsigned frame_num = 0; static unsigned tx_busy = 0; static unsigned interval_ms = 1000 / FRAME_RATE; @@ -86,7 +87,7 @@ static struct { {color_bar_7_jpg_len, color_bar_7_jpg}, }; - +*/ /* void cdc_task(void) { @@ -159,6 +160,7 @@ uint8_t sendT[600] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +/* int currentIdx = 0; int currentImg = 0; @@ -203,7 +205,7 @@ int send_CDC_Bulk(){ currentIdx = currentIdx + 10; return 1; } - +*/ /* USER CODE END 0 */ @@ -247,14 +249,35 @@ int main(void) tud_init(BOARD_DEVICE_RHPORT_NUM); - //HAL_Delay(10); - //SPI_Init(&hspi1); + HAL_Delay(10); + SPI_Init(&hspi1); // Wait for power stabilization //HAL_Delay(1000); - //Cam_Init(&hi2c1, &hspi1); + Cam_Init(&hi2c1, &hspi1); + + int currentSendingIndex = 0; + + + Cam_Capture(&hspi1); + + uint16_t image_size = Cam_FIFO_length(&hspi1); + //uint8_t *image_data = malloc((image_size + (image_size%10)) * sizeof(uint8_t)); + uint8_t image_data[10000]; + memset(image_data, 0x00, image_size + (image_size%10)); + + Cam_Start_Burst_Read(&hspi1); + + HAL_SPI_Receive_DMA(&hspi1, image_data, image_size); + + while (SPI_Rx_Done_Flag == 0) + { + // Wait for SPI transfer to finish + } + CS_Off(); + SPI_Rx_Done_Flag = 0; /* USER CODE END 2 */ @@ -262,42 +285,44 @@ int main(void) /* USER CODE BEGIN WHILE */ while (1) { + tud_task(); - //tud_cdc_write("1\r", 3); - //tud_cdc_write_flush(); - //video_task(); - //HAL_Delay(10); - send_CDC_Bulk(); - HAL_Delay(5); + if(currentSendingIndex >= 590){ + currentSendingIndex = 0; + //free(image_data); + Cam_Capture(&hspi1); - /* - Cam_Capture(&hspi1); + image_size = Cam_FIFO_length(&hspi1); - uint16_t image_size = Cam_FIFO_length(&hspi1); + //image_data = malloc((image_size + (image_size%10)) * sizeof(uint8_t)); + //memset(image_data, 0x00, image_size + (image_size%10)); - uint8_t *image_data = malloc(image_size * sizeof(uint8_t)); - memset(image_data, 0x00, image_size); + Cam_Start_Burst_Read(&hspi1); - Cam_Start_Burst_Read(&hspi1); + HAL_SPI_Receive_DMA(&hspi1, &(image_data[0]), image_size); + Debug_LED_On(); - HAL_SPI_Receive_DMA(&hspi1, image_data, image_size); - Debug_LED_On(); - - while (SPI_Rx_Done_Flag == 0) - { - // Wait for SPI transfer to finish + while (SPI_Rx_Done_Flag == 0) + { + // Wait for SPI transfer to finish + } + CS_Off(); + SPI_Rx_Done_Flag = 0; + if(image_size < 1){ + currentSendingIndex = 10000; + } + + } + else { + LED_On(); + tud_cdc_write(&sendT[currentSendingIndex], 10); + tud_cdc_write_flush(); + currentSendingIndex = currentSendingIndex + 10; + HAL_Delay(5); } - Debug_LED_Off(); - CS_Off(); - - SPI_Rx_Done_Flag = 0; - HAL_UART_Transmit(&huart2, image_data, image_size, HAL_MAX_DELAY); - Debug_LED_Off(); - free(image_data); - */ /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ diff --git a/HW/fp-info-cache b/HW/fp-info-cache new file mode 100644 index 0000000..573541a --- /dev/null +++ b/HW/fp-info-cache @@ -0,0 +1 @@ +0 diff --git a/Receiver/Displayer.o b/Receiver/Displayer.o new file mode 100644 index 0000000..1a56250 Binary files /dev/null and b/Receiver/Displayer.o differ diff --git a/Receiver/ImageView.o b/Receiver/ImageView.o new file mode 100644 index 0000000..c37b2cf Binary files /dev/null and b/Receiver/ImageView.o differ diff --git a/Receiver/Receiver.cpp b/Receiver/Receiver.cpp index ed8b69a..dad7a1c 100644 --- a/Receiver/Receiver.cpp +++ b/Receiver/Receiver.cpp @@ -11,7 +11,7 @@ void Receiver::printHex(unsigned char value) { void Receiver::openStream(){ while(1){ // Open the CDC device file for reading - cdcFile = open("/dev/ttyACM2", O_RDWR | O_NOCTTY); + cdcFile = open("/dev/ttyACM1", O_RDWR | O_NOCTTY); if (cdcFile == -1) { std::cerr << "Failed to open CDC device file" << std::endl; std::this_thread::sleep_for(std::chrono::milliseconds(500)); diff --git a/Receiver/Receiver.o b/Receiver/Receiver.o new file mode 100644 index 0000000..a7af35a Binary files /dev/null and b/Receiver/Receiver.o differ diff --git a/Receiver/Transfer.o b/Receiver/Transfer.o new file mode 100644 index 0000000..7c642ec Binary files /dev/null and b/Receiver/Transfer.o differ diff --git a/Receiver/main b/Receiver/main new file mode 100755 index 0000000..63bb424 Binary files /dev/null and b/Receiver/main differ diff --git a/Receiver/main.cpp b/Receiver/main.cpp index 494d30b..4379262 100644 --- a/Receiver/main.cpp +++ b/Receiver/main.cpp @@ -9,13 +9,22 @@ int cdcFile; struct termios tty; -void readLoop(){ - openStream(&cdcFile); - initSerial(&tty, &cdcFile); + +void readLoop(Receiver ** receiverPtr){ + (*receiverPtr)->openStream(); + (*receiverPtr)->initSerial(); while (true) { - readCdcData(&cdcFile); - std::this_thread::sleep_for(std::chrono::milliseconds(5)); + unsigned char character[10]; + (*receiverPtr)->readCdcData(&character); + if((*receiverPtr)->findStart(&character) != -1) + {std::cout << "start" << std::endl;} + else if((*receiverPtr)->findEnd(&character) != -1) + {std::cout << "stop" << std::endl;} + else{ + std::cout << "-"; + } + std::this_thread::sleep_for(std::chrono::milliseconds(20)); } close(cdcFile); @@ -36,12 +45,13 @@ void receiverLoop(Receiver ** receiverPtr){ int main() { - Displayer dis; + Receiver *rec = new Receiver(&dis); + + /* dis.createWindow(); dis.renderWindow(); - Receiver *rec = new Receiver(&dis); rec->openStream(); rec->initSerial(); rec->fillBuffer(); @@ -52,8 +62,8 @@ int main() dis.windowLoop(); t1.join(); + */ - - //readLoop(); + readLoop(&rec); return 0; } diff --git a/Receiver/main.o b/Receiver/main.o new file mode 100644 index 0000000..8fb3a53 Binary files /dev/null and b/Receiver/main.o differ