Подключение тепловизора Seek Thermal к STM32

3ad79ad944a24f2daa5ab8b49aae3376.jpg
#define DELAY1 10
#define USB_PIPE_NUMBER 0x81
#define FRAME_WIDTH 208
#define FRAME_HEIGHT 156

uint8_t OutPipe, InPipe;
uint8_t usb_device_state;
uint8_t rawdata[FRAME_HEIGHT*FRAME_WIDTH*2];
uint8_t data[64];
USBH_StatusTypeDef status;
uint8_t transf_size;
int size;

int main(void)
{
  /* Enable the CPU Cache */
  CPU_CACHE_Enable();

  /* STM32F7xx HAL library initialization:
       - Configure the Flash ART accelerator on ITCM interface
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure the System clock to have a frequency of 200 MHz */
  SystemClock_Config();

  /* Init CDC Application */
  CDC_InitApplication();

  /* Init Host Library */
  USBH_Init(&hUSBHost, USBH_UserProcess, 0);

  /* Add Supported Class */
  //USBH_RegisterClass(&hUSBHost, USBH_CDC_CLASS);

  /* Start Host Process */
  USBH_Start(&hUSBHost);

  /* Run Application (Blocking mode) */
  while (1)
  {
    /* USB Host Background task */
    USBH_Process(&hUSBHost);

    if (hUSBHost.gState == HOST_CHECK_CLASS) {

        switch (usb_device_state) {
        case 1:
                status = USBH_Get_StringDesc(&hUSBHost,hUSBHost.device.DevDesc.iManufacturer, data , 64);
                if (status == USBH_OK) {
                        USBH_UsrLog("## Manufacturer : %s",  (char *)data);
                        HAL_Delay(1000);
                        usb_device_state = 1;
                }
                break;
        case 2:
                status = USBH_Get_StringDesc(&hUSBHost, hUSBHost.device.DevDesc.iProduct, data , 64);

                if (status == USBH_OK) {
                                        USBH_UsrLog("## Product : %s",  (char *)data);
                                        HAL_Delay(1000);
                                        usb_device_state = 2;
                                }
                break;
        case 0:

                InPipe = USBH_AllocPipe(&hUSBHost, 0x81);


                                      status = USBH_OpenPipe(&hUSBHost,
                                                                  InPipe,
                                                                  0x81,
                                                                  hUSBHost.device.address,
                                                                  hUSBHost.device.speed,
                                                                  USB_EP_TYPE_BULK,
                                                                  USBH_MAX_DATA_BUFFER);

                                      if (status == USBH_OK)
                                          usb_device_state = 3;

                break;
        case 3:
                HAL_Delay(1);

                const uint8_t data0[2] = {0x00, 0x00};
                vendor_transfer(0, SET_OPERATION_MODE, 0, 0, data0, 2);
                vendor_transfer(0, SET_OPERATION_MODE, 0, 0, data0, 2);
                vendor_transfer(0, SET_OPERATION_MODE, 0, 0, data0, 2);

                data[0] = 0x01;
                vendor_transfer(0, TARGET_PLATFORM, 0, 0, data, 1);

                data[0] = 0x00;
                data[1] = 0x00;
                vendor_transfer(0, SET_OPERATION_MODE, 0, 0, data);

                transf_size = vendor_transfer(1, GET_FIRMWARE_INFO, 0, 0, data, 4);

                transf_size = vendor_transfer(1, READ_CHIP_ID, 0, 0, data, 12);

                const uint8_t data1[6] = { 0x20, 0x00, 0x30, 0x00, 0x00, 0x00 };
                vendor_transfer(0, SET_FACTORY_SETTINGS_FEATURES, 0, 0, data1, 6);

                transf_size = vendor_transfer(1, GET_FACTORY_SETTINGS, 0, 0, data, 64);

                const uint8_t data2[6] = { 0x20, 0x00, 0x50, 0x00, 0x00, 0x00 };
                vendor_transfer(0, SET_FACTORY_SETTINGS_FEATURES, 0, 0, data2, 6);

                transf_size = vendor_transfer(1, GET_FACTORY_SETTINGS, 0, 0, data, 64);

                const uint8_t data3[6] = { 0x0c, 0x00, 0x70, 0x00, 0x00, 0x00 };
                vendor_transfer(0, SET_FACTORY_SETTINGS_FEATURES, 0, 0, data3, 6);

                transf_size = vendor_transfer(1, GET_FACTORY_SETTINGS, 0, 0, data, 24);

                const uint8_t data4[6] = { 0x06, 0x00, 0x08, 0x00, 0x00, 0x00 };
                vendor_transfer(0, SET_FACTORY_SETTINGS_FEATURES, 0, 0, data4, 6);

                vendor_transfer(1, GET_FACTORY_SETTINGS, 0, 0, data, 12);

                const uint8_t data5[2] = { 0x08, 0x00 };
                vendor_transfer(0, SET_IMAGE_PROCESSING_MODE, 0, 0, data5, 2);

                vendor_transfer(1, GET_OPERATION_MODE, 0, 0, data,2);

                const uint8_t data6[2] = { 0x08, 0x00 };
                vendor_transfer(0, SET_IMAGE_PROCESSING_MODE, 0, 0, data6, 2);

                const uint8_t data7[2] = { 0x01, 0x00 };
                vendor_transfer(0, SET_OPERATION_MODE, 0, 0, data7, 2);

                vendor_transfer(1, GET_OPERATION_MODE, 0, 0, data, 2);

                USBH_UsrLog("SeeK Thermal Init Done.\n");

                size = FRAME_WIDTH * FRAME_HEIGHT;

                int bufsize = size * sizeof(uint16_t);
                status = CDC_IDLE;
                usb_device_state = 4;
                break;
        case 4:
                //while(1 ){
                 // request a frame
                data[0] = (uint8_t)(size & 0xff);
                data[1] = (uint8_t)((size>>8)&0xff);
                data[2] = 0;
                data[3] = 0;

                if (status == CDC_IDLE)
                vendor_transfer(0, 0x53, 0, 0, data, 4);
                
                status = CAM_ProcessReception(&hUSBHost);

                if (status == CDC_IDLE)
                BSP_LCD_DrawArray(10, 10, FRAME_WIDTH, FRAME_HEIGHT, 16, rawdata);

                usb_device_state = 4;

                break;

        }
                  }
  }
}


© Geektimes