示例#1
0
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USB_DEVICE_Init();

  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
示例#2
0
文件: main.c 项目: nihaopaul/Espruino
int main(void){
#ifdef STM32F103RB_MAPLE
  // get in quick and relocate vector table!
  SCB->VTOR = 0x08005000;
#else // quickly set up the vector table...
  SCB->VTOR = (unsigned int)&_VECTOR_TABLE;
#endif

  jshInit();
#ifdef USB
  MX_USB_DEVICE_Init();
#endif

  bool buttonState = false;
#ifdef BTN1_PININDEX
  buttonState = jshPinInput(BTN1_PININDEX) == BTN1_ONSTATE;
#endif
  jsvInit();
  jsiInit(!buttonState); // pressing USER button skips autoload

  while (1) {
    jsiLoop();
  }
  //jsiKill();
  //jsvKill();
  //jshKill();
}
示例#3
0
int main(void)
{

  /* USER CODE BEGIN 1 */
	USBD_StatusTypeDef result = USBD_OK;
	uint32_t userSw_old = 0;
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USB_DEVICE_Init();

  /* USER CODE BEGIN 2 */
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);
  BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO);

  userSw_old = BSP_PB_GetState(BUTTON_USER);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */
  /* USER CODE BEGIN 3 */
	  HAL_Delay(40);
	  BSP_LED_Toggle(LED4);

	  if ((BSP_PB_GetState(BUTTON_USER) == GPIO_PIN_SET) && (userSw_old == GPIO_PIN_RESET))
	  {
		  result = CDC_Transmit_FS(USB_TxBufferFS, sizeof(USB_TxBufferFS));
	  }
	  userSw_old = BSP_PB_GetState(BUTTON_USER);


	  /* USB Error */
	  if (result != USBD_OK)
	  {
		  while (1)
		  {
			  BSP_LED_On(LED3);
			  HAL_Delay(100);
		  }
	  }
  }
  /* USER CODE END 3 */

}
示例#4
0
int main()
{
	DBG_Configuration();
	SystemClock_Configuration();
	DelayManager::DelayMs(150);
	RCC_Configuration();
	GPIO_Configuration();
	EXTI_Configuration();
	NVIC_Configuration();
	I2C_Configuration(&i2c);
	USART_Configuration(&uart);
	DMA_I2C_TX_Configuration(&i2cDmaTx);
	//__HAL_LINKDMA(&i2c, hdmatx, i2cDmaTx);

	MX_USB_DEVICE_Init();

	systemMode = LOADING;
	graphMode = SECONDS;

	display.initDisplay(&i2c);
	display.setFont(font5x7);
	display.clearScreen();
	display.printf(12, 50, logoStr);
	display.drawLine(0, 44, 127, 44);
	display.printf(12, 15, ".... LOADING ....");
	display.drawFramebuffer();

	sensorOk = co2sensor.initSensor(&uart);
	systemMode = ACTIVE;
	if (!sensorOk)
	{
		display.clearScreen();
		display.printf(12, 50, logoStr);
		display.drawLine(0, 44, 127, 44);
		display.printf(12, 15, errorStr);
		display.drawFramebuffer();
		errorHandler(NULL);
	}

	osThreadDef(processSensorThread, processSensorTask, osPriorityNormal, 0, 128);
	processSensorTaskHandle = osThreadCreate(osThread(processSensorThread), NULL);

	osThreadDef(processKeysThread, processKeysTask, osPriorityLow, 0, configMINIMAL_STACK_SIZE);
	processKeysTaskHandle = osThreadCreate(osThread(processKeysThread), NULL);

	osThreadDef(drawDataThread, drawDataTask, osPriorityHigh, 0, 256);
	drawDataTaskHandle = osThreadCreate(osThread(drawDataThread), NULL);

	osKernelStart();
	
	while (true)
	{
	}
}
示例#5
0
int main(void)
{
	
	int autorun;
//		double calcfreq;
//	double CurrentFreq = 144e6;

	
  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
	//MX_SPI1_Init();
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET);

  MX_TIM3_Init();
	MX_TIM14_Init();
  MX_USB_DEVICE_Init();
	
	Morse_Init();
	
//	prepare_pll();
//  UpdateFrequencyRegisters(CurrentFreq, 50000000.0, 5000, 1, 1, &calcfreq); 	
//	PLL_Sync();
	
	autorun = cmd_isautorun() ;

  /* Infinite loop */
  while (1)
  {
	  if (is_line_received())
		{
//     Process received line

			cmd_proc(get_line_buffer());
		}
		HAL_Delay(10); ar_count++;
		if ((ar_count > 1000) & (autorun>0))
		{
			// Start Autorun
			cmd_autorun(autorun);
			cw_autorunning = 1;
			while(cw_autorunning) HAL_Delay(10);
		}
  }
}
示例#6
0
文件: main.c 项目: maya2003/bdm
/* StartDefaultTask function */
void StartDefaultTask(void const * argument)
{
  /* init code for USB_DEVICE */
  MX_USB_DEVICE_Init();

  /* USER CODE BEGIN 5 */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END 5 */ 
}
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USB_DEVICE_Init();

  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  //SH_SendString("Hello\n\r");

  while (1)
  {
	  HAL_GPIO_WritePin(GPIOD,GPIO_PIN_12, GPIO_PIN_SET);
	  HAL_Delay(100);
	  HAL_GPIO_WritePin(GPIOD,GPIO_PIN_12, GPIO_PIN_RESET);

	  HAL_GPIO_WritePin(GPIOD,GPIO_PIN_13, GPIO_PIN_SET);
	  HAL_Delay(100);
	  HAL_GPIO_WritePin(GPIOD,GPIO_PIN_13, GPIO_PIN_RESET);

	  HAL_GPIO_WritePin(GPIOD,GPIO_PIN_14, GPIO_PIN_SET);
	  HAL_Delay(100);
	  HAL_GPIO_WritePin(GPIOD,GPIO_PIN_14, GPIO_PIN_RESET);

	  HAL_GPIO_WritePin(GPIOD,GPIO_PIN_15, GPIO_PIN_SET);
	  HAL_Delay(100);
	  HAL_GPIO_WritePin(GPIOD,GPIO_PIN_15, GPIO_PIN_RESET);


  }
  /* USER CODE END 3 */

}
示例#8
0
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_ADC1_Init();
  MX_I2C1_Init();
  MX_IWDG_Init();
  MX_SDADC1_Init();
  MX_SDADC2_Init();
  MX_TSC_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_SDADC3_Init();
  MX_USB_DEVICE_Init();
  MX_RTC_Init();
  MX_TIM6_Init();
  MX_TIM7_Init();

  /* USER CODE BEGIN 2 */
  Setup();
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
	  loop();
  }
  /* USER CODE END 3 */

}
示例#9
0
int main(void)
{
	USB_HIDDEVICE_Keyboard_t Keyboard_Data;
	
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_TIM3_Init();
  MX_USB_DEVICE_Init();

  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
	
	
	delay_ms(1000);
//	MX_USB_DEVICE_SendHIDAction(0x01);
	USB_HIDDEVICE_KeyboardStructInit(&Keyboard_Data);
	
	Keyboard_Data.Key1 = 0x01;
	
	USB_HIDDEVICE_KeyboardSend(&Keyboard_Data);
	
	
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
示例#10
0
/**
  * @brief  CDC_DeInit_FS
  *         DeInitializes the CDC media low layer
  * @param  None
  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_DeInit_FS(void)
{
    if ( hUsbDevice_0 == NULL ) return USBD_FAIL;
    USBD_CDC_HandleTypeDef *pCDC =
            (USBD_CDC_HandleTypeDef *)hUsbDevice_0->pClassData;
    if ( pCDC->TxState != 0 ) {
        pCDC->TxState = 0;
        usb_deinit_while_tx_count++;
        MX_USB_DEVICE_DeInit();
        MX_USB_DEVICE_Init();
    }
    hUsbDevice_0 = NULL;
    usb_deinit_count++;
  /* USER CODE BEGIN 5 */ 
  return (USBD_OK);
  /* USER CODE END 5 */ 
}
示例#11
0
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USB_DEVICE_Init();

  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Call init function for freertos objects (in freertos.c) */
  MX_FREERTOS_Init();

  /* Start scheduler */
  osKernelStart();
  
  /* We should never get here as control is now taken by the scheduler */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
示例#12
0
文件: main.c 项目: TomRaven/navxmxp
int main(void)
{

    /* USER CODE BEGIN 1 */
    int spi_slave_enabled = 0;
    int uart_slave_enabled = 0;

    /* USER CODE END 1 */

    /* MCU Configuration----------------------------------------------------------*/
    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();
    /* Configure the system clock */
    SystemClock_Config();
    MX_GPIO_Init();

    USB_Soft_Disconnect();

    MX_DMA_Init();
    MX_I2C2_Init();

    HAL_DIP_Switches_Init();
    spi_slave_enabled = HAL_SPI_Slave_Enabled();
    uart_slave_enabled = HAL_UART_Slave_Enabled();

    MX_I2C3_Init();

    if (spi_slave_enabled) {
        MX_SPI1_Init();
    }

    if (uart_slave_enabled) {
        MX_USART6_UART_Init();
    }

    MX_USB_DEVICE_Init();
    /* USER CODE BEGIN 2 */
    nav10_init();
    /* USER CODE END 2 */

    nav10_main();

    return 0; /* Note:  Control will never reach this point. */
}
示例#13
0
int main(void)
{

  /* USER CODE BEGIN 1 */
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* System interrupt init*/
  /* Sets the priority grouping field */
  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_I2C1_Init();
  MX_I2S2_Init();
  MX_I2S3_Init();
  MX_SPI1_Init();
  MX_SPI4_Init();
  MX_TIM3_Init();
  MX_USART2_UART_Init();
  MX_USB_DEVICE_Init();

  /* USER CODE BEGIN 2 */
  /* USER CODE END 2 */

  /*## FatFS: Link the USER disk I/O driver ###############################*/
  USER_DriverNum = FATFS_LinkDriver(&USER_Driver, USER_Path);

  /* USER CODE BEGIN 3 */
  dabstick_loop(); // endless
  return 0;
  /* USER CODE END 3 */

}
示例#14
0
int main(void) {

	/* USER CODE BEGIN 1 */

	/* USER CODE END 1 */

	/* MCU Configuration----------------------------------------------------------*/

	/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
	HAL_Init();

	/* Configure the system clock */
	SystemClock_Config();

	/* Initialize all configured peripherals */
	MX_GPIO_Init();
	MX_TIM1_Init();
	MX_USB_DEVICE_Init();

	/* USER CODE BEGIN 2 */
	HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_1);

	/* USER CODE END 2 */

	/* Infinite loop */
	/* USER CODE BEGIN WHILE */

	//DBGMCU->CR |= DBGMCU_CR_DBG_TIM1_STOP; //this is for timer debugging

	while (1) {
		/* USER CODE END WHILE */

		/* USER CODE BEGIN 3 */
		if (data_ready) {
			USBD_HID_SendReport(&hUsbDeviceFS, (uint8_t*) rc_data, 10);
			data_ready = 0;
		}
	}
	/* USER CODE END 3 */

}
示例#15
0
void InitSystem(DeviceConfig *devState){
    // init HAL 
    HAL_Init();
   
    /* Configure the system clock */
    SystemClock_Config();

    /* Initialize all configured peripherals */ 
    InitDeviceConfig(devState);  
   
    MX_USB_DEVICE_Init();

    MX_GPIO_Init();
    MX_I2C2_Init(devState);
    MX_ADC1_Init(devState);
    MX_ADC1_Init(devState);
    MX_SPI2_Init(devState);
    MX_TIM4_Init(devState);
    MX_USART3_UART_Init(devState);
    init_printf(NULL,usb_putc);
}
示例#16
0
void USBSerial::init(void){
 
  /* Re-enumerate the USB */ 
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;  
  
#if defined(USB_DISC_PORT) 
	GPIO_InitStruct.Pin = USB_DISC_PIN;
	HAL_GPIO_Init(USB_DISC_PORT, &GPIO_InitStruct);

	HAL_GPIO_WritePin(USB_DISC_PORT, USB_DISC_PIN, GPIO_PIN_SET);
	for(volatile unsigned int i=0;i<512;i++);
	HAL_GPIO_WritePin(USB_DISC_PORT, USB_DISC_PIN, GPIO_PIN_RESET);
#else
	GPIO_InitStruct.Pin = GPIO_PIN_12;
	HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);
	for(volatile unsigned int i=0;i<512;i++);
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_SET);
#endif
  
	MX_USB_DEVICE_Init();
}
示例#17
0
文件: main.c 项目: dekuNukem/FAP_Z80
int main(void)
{

  /* USER CODE BEGIN 1 */
  my_usb_init();
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_TIM1_Init();
  MX_USB_DEVICE_Init();
  MX_USART3_UART_Init();
  MX_TIM2_Init();

  /* USER CODE BEGIN 2 */
  HAL_TIM_Base_Start(&htim2);
  delay_us_init(&htim2);
  softserial_init(SOFTSERIAL_TX_GPIO_Port, SOFTSERIAL_TX_Pin);
  hmi_lcd_init(&huart3);
  cpu_ctrl_init(&htim1);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  HAL_Delay(100);
  hsc_stop();
  cpu_reset();
  lcd_clear();
  addr_input();
  data_input();
  build_ui();
  HAL_Delay(100);

  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
    if(is_running == 0)
      addr_data_display_update();

    // z80 reset button
    if(is_button_1_pressed)
    {
      hsc_stop();
      cpu_reset();
      lcd_print_width(130, 110, 180, 45, "CYAN", "RESET");
      is_button_1_pressed = 0;
      HAL_Delay(500);
      build_ui();
    }

    // clk step button
    if(is_button_3_pressed)
    {
      hsc_stop();
      cycle_clock(1);
      lcd_print_width(130, 110, 180, 45, "RED", "CLK STEP");
      is_button_3_pressed = 0;
      HAL_Delay(100);
      build_ui();
    }

    // ins step button
    if(is_button_4_pressed)
    {
      hsc_stop();
      lcd_print_width(130, 110, 180, 45, "GREEN", "INS STEP");
      // cycle clock until we're at next M1 cycle
      while(HAL_GPIO_ReadPin(CPU_CTRL_PORT, M1_Pin) == LOW)
        cycle_clock(1);
      while(HAL_GPIO_ReadPin(CPU_CTRL_PORT, M1_Pin) == HIGH)
        cycle_clock(1);
      is_button_4_pressed = 0;
      HAL_Delay(100);
      build_ui();
    }

    // run/stop button
    if(is_button_5_pressed)
    {
      is_running = (is_running + 1) % 2;
      if(is_running)
      {
        lcd_print_width(130, 110, 180, 45, "GREEN", "RUNNING");
        hsc_start();
      }
      else
      {
        hsc_stop();
        build_ui();
      }
      is_button_5_pressed = 0;
    }

    usb_data = my_usb_readline();
    if(usb_data != NULL && strstr(usb_data, "epm") != NULL)
    {
      hsc_stop();
      program_mode();
      build_ui();
    }
  }
  /* USER CODE END 3 */

}
示例#18
0
文件: main.c 项目: thiemar/mucan
int __start(void) {
    const volatile uint32_t *src;
    volatile uint32_t *dest;

    /* Set up BSS and copy data from flash */
    for (src = &_eronly, dest = &_sdata; dest < &_edata;) {
        *dest++ = *src++;
    }

    for (dest = &_sbss; dest < &_ebss;) {
        *dest++ = 0;
    }

    SystemInit();
    HAL_Init();

    /* Configure the system clock */
    SystemClock_Config();

    /*
    Make sure the flash option bytes are set such that we don't re-enter
    bootloader mode
    */
    set_dfu_option_bytes(0u);

    MX_USB_DEVICE_Init();

    /* Configure GPIO for the CAN_SILENT signal */
    GPIO_InitTypeDef GPIO_InitStruct;

    /* GPIO Ports Clock Enable */
    __GPIOA_CLK_ENABLE();
    __GPIOB_CLK_ENABLE();
    __CRS_CLK_ENABLE();

    /*Configure GPIO pin : PB7 */
    GPIO_InitStruct.Pin = GPIO_PIN_7;
    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
    GPIO_InitStruct.Pull = GPIO_PULLDOWN;
    GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    /**CAN GPIO Configuration
    PB8     ------> CAN_RX
    PB9     ------> CAN_TX
    */
    GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF4_CAN;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    /* Configure the bxCAN transceiver */
    CAN_HandleTypeDef hcan;

    __CAN_CLK_ENABLE();

    hcan.Instance = CAN;
    hcan.Init.Mode = CAN_MODE_SILENT;
    hcan.Init.TTCM = DISABLE;
    hcan.Init.ABOM = ENABLE;
    hcan.Init.AWUM = ENABLE;
    hcan.Init.NART = DISABLE;
    hcan.Init.RFLM = DISABLE;
    hcan.Init.TXFP = DISABLE;

    /* Set the bitrate and init */
    set_can_bitrate(&hcan, 1000000u);

    CanRxMsgTypeDef rx_msg;
    hcan.pRxMsg = &rx_msg;

    CanTxMsgTypeDef tx_msg;
    hcan.pTxMsg = &tx_msg;

    CAN_FilterConfTypeDef filter;
    filter.FilterNumber = 0;
    filter.FilterMode = CAN_FILTERMODE_IDMASK;
    filter.FilterScale = CAN_FILTERSCALE_32BIT;
    filter.FilterFIFOAssignment = CAN_FILTER_FIFO0;
    filter.FilterActivation = ENABLE;
    filter.BankNumber = 0;
    filter.FilterMaskIdLow = filter.FilterIdLow = filter.FilterMaskIdHigh =
        filter.FilterIdHigh = 0;
    HAL_CAN_ConfigFilter(&hcan, &filter);

    __HAL_UNLOCK(&hcan);

    /*
    Now that USB is active, we need to sync with the 1 kHz SOF packets to
    tune the HSI48 so it's accurate enough not to disrupt the CAN bus.
    */
    RCC_CRSInitTypeDef crs_config;
    crs_config.Prescaler = RCC_CRS_SYNC_DIV1;
    crs_config.Source = RCC_CRS_SYNC_SOURCE_USB;
    crs_config.Polarity = RCC_CRS_SYNC_POLARITY_RISING;
    crs_config.ReloadValue = RCC_CRS_RELOADVALUE_DEFAULT;
    crs_config.ErrorLimitValue = RCC_CRS_ERRORLIMIT_DEFAULT;
    crs_config.HSI48CalibrationValue = RCC_CRS_HSI48CALIBRATION_DEFAULT;

    HAL_RCCEx_CRSConfig(&crs_config);

    /* Don't continue unless we're synced */
    while (!(HAL_RCCEx_CRSWaitSynchronization(1000000u) & RCC_CRS_SYNCOK));

    while (1) {
        /* Set up the command record */
        size_t i;
        uint8_t current_cmd;
        uint8_t current_cmd_data[32];
        uint8_t current_cmd_data_length;
        uint8_t channel_open;

        current_cmd = current_cmd_data_length = i = 0;
        channel_open = 0;
        rx_buffer_length = 0;

        while (hUsbDevice_0 && hUsbDevice_0->pClassData) {
            /*
            If the RX buffer is non-empty, process any commands/messages in it
            and then acknowledge the transfer to the USB stack
            */
            if (rx_buffer_length) {
                /*
                Exit if we've read the entire buffer, or if transmit mailboxes
                are full and the current command is a transmit.
                */
                for (; i < rx_buffer_length &&
                        ((current_cmd != 't' && current_cmd != 'T') ||
                         __HAL_CAN_GET_FLAG(&hcan, CAN_FLAG_TME0)); i++) {
                    if (rx_buffer[i] == '\r') {
                        uint8_t *buf = active_buffer ? tx_buffer_1 :
                                                       tx_buffer_0;

                        /* End of command -- process and reset state */
                        switch (current_cmd) {
                            case 'S':
                                /*
                                Setup bitrate -- data should be a number from
                                0 to 8.
                                */
                                if (current_cmd_data[0] < '0' ||
                                        current_cmd_data[0] > '8') {
                                    buf[active_buffer_length++] = '\a';
                                } else if (set_can_bitrate(
                                        &hcan,
                                        bitrate_lookup[current_cmd_data[0] - '0'])) {
                                    buf[active_buffer_length++] = '\r';
                                } else {
                                    buf[active_buffer_length++] = '\a';
                                }
                                break;
                            case 'O':
                                /*
                                Open channel -- take CAN out of silent mode
                                and start receiving.
                                */
                                if (!channel_open) {
                                    channel_open = 1;
                                    set_can_silent(&hcan, 0);
                                    buf[active_buffer_length++] = '\r';
                                } else {
                                    buf[active_buffer_length++] = '\a';
                                }
                                break;
                            case 'L':
                                /*
                                Open in listen-only -- CAN should already be
                                in silent mode but just make sure.
                                */
                                if (!channel_open) {
                                    channel_open = 1;
                                    set_can_silent(&hcan, 1);
                                    buf[active_buffer_length++] = '\r';
                                } else {
                                    buf[active_buffer_length++] = '\a';
                                }
                                break;
                            case 'C':
                                /*
                                Close channel -- put CAN back in silent mode.
                                */
                                if (channel_open) {
                                    channel_open = 0;
                                    set_can_silent(&hcan, 1);
                                    buf[active_buffer_length++] = '\r';
                                } else {
                                    buf[active_buffer_length++] = '\a';
                                }
                                break;
                            case 'V':
                                /* Hardware version */
                                buf[active_buffer_length++] = 'V';
                                buf[active_buffer_length++] = '0';
                                buf[active_buffer_length++] = '0';
                                buf[active_buffer_length++] = '0';
                                buf[active_buffer_length++] = '1';
                                buf[active_buffer_length++] = '\r';
                                break;
                            case 'v':
                                /* Major/minor version */
                                buf[active_buffer_length++] = 'v';
                                buf[active_buffer_length++] = '0';
                                buf[active_buffer_length++] = '0';
                                buf[active_buffer_length++] = '0';
                                buf[active_buffer_length++] = '1';
                                buf[active_buffer_length++] = '\r';
                                break;
                            case 'N':
                                /* Serial number */
                                buf[active_buffer_length++] = 'N';
                                buf[active_buffer_length++] = 'F';
                                buf[active_buffer_length++] = 'F';
                                buf[active_buffer_length++] = 'F';
                                buf[active_buffer_length++] = 'F';
                                buf[active_buffer_length++] = '\r';
                                break;
                            case 'T':
                                /* Extended message */
                                if (read_ext_message(&tx_msg, current_cmd_data,
                                                     current_cmd_data_length) &&
                                        HAL_CAN_Transmit(&hcan, 0) == HAL_OK) {
                                    buf[active_buffer_length++] = '\r';
                                } else {
                                    buf[active_buffer_length++] = '\a';
                                }
                                break;
                            case 't':
                                /* Standard message */
                                if (read_std_message(&tx_msg, current_cmd_data,
                                                     current_cmd_data_length) &&
                                        HAL_CAN_Transmit(&hcan, 0) == HAL_OK) {
                                    buf[active_buffer_length++] = '\r';
                                } else {
                                    buf[active_buffer_length++] = '\a';
                                }
                                break;
                            case 'R':
                                /* Extended RTR */
                                if (read_ext_rtr(&tx_msg, current_cmd_data,
                                                 current_cmd_data_length) &&
                                        HAL_CAN_Transmit(&hcan, 0) == HAL_OK) {
                                    buf[active_buffer_length++] = '\r';
                                } else {
                                    buf[active_buffer_length++] = '\a';
                                }
                                break;
                            case 'r':
                                /* Standard RTR */
                                if (read_std_rtr(&tx_msg, current_cmd_data,
                                                 current_cmd_data_length) &&
                                        HAL_CAN_Transmit(&hcan, 0) == HAL_OK) {
                                    buf[active_buffer_length++] = '\r';
                                } else {
                                    buf[active_buffer_length++] = '\a';
                                }
                                break;
                            case '_':
                                /* Bootloader request */
                                if (current_cmd_data[0] == '_' &&
                                        current_cmd_data[1] == 'd' &&
                                        current_cmd_data[2] == 'f' &&
                                        current_cmd_data[3] == 'u') {
                                    /*
                                    Set option bytes to force bootloader entry
                                    */
                                    set_dfu_option_bytes(1u);

                                    NVIC_SystemReset();
                                } else {
                                    buf[active_buffer_length++] = '\a';
                                }
                                break;
                            case 'F':
                                /* Read status flags -- return 4 hex digits */
                            case 'Z':
                                /* Timestamp on/off -- 0=off, 1=on */
                            case 'M':
                                /* Acceptance mask -- 8 hex digits */
                            case 'm':
                                /* Acceptance value -- 8 hex digits */
                            case 's':
                                /* Set bitrate register -- 6 hex digits */
                            default:
                                /* NACK */
                                buf[active_buffer_length++] = '\a';
                                break;
                        }

                        current_cmd = current_cmd_data_length = 0;
                    } else if (current_cmd) {
                        /* Command data -- save it */
                        current_cmd_data[current_cmd_data_length++] =
                            rx_buffer[i];

                        /* Reset command state if the data is too long */
                        if (current_cmd_data_length == 32u) {
                            current_cmd = current_cmd_data_length = 0;
                        }
                    } else {
                        /*
                        The first letter of a line is the command type --
                        don't bother validating as we can't NACK until the
                        data has been received.
                        */
                        current_cmd = rx_buffer[i];
                    }
                }

                if (i == rx_buffer_length) {
                    /* Mark last packet as received */
                    rx_buffer_length = i = 0;
                    USBD_CDC_ReceivePacket(hUsbDevice_0);
                }
            }

            /*
            Check the CAN controller for messages and process them if the
            channel is open
            */
            if (HAL_CAN_Receive(&hcan, CAN_FIFO0, 0) == HAL_OK && hUsbDevice_0 &&
                    channel_open) {
                /*
                Format the message and send it to the host.

                The data format for a standard ID message is:
                tiiildddddddddddddddd\r

                The data format for a standard ID RTR is:
                riii\r

                The data format for an extended ID message is:
                Tiiiiiiiildddddddddddddddd\r

                The data format for an extended ID RTR is:
                Riiiiiiii\r
                */
                uint8_t *write_location;

                if (active_buffer_length + EXT_MESSAGE_LEN > TX_BUFFER_SIZE) {
                    /*
                    Reset buffer if we're too far behind -- use worst-case
                    message length for calculation
                    */
                    active_buffer_length = 0;
                }

                write_location = &((active_buffer ? tx_buffer_1 : tx_buffer_0)[active_buffer_length]);

                if (rx_msg.IDE == CAN_ID_EXT && rx_msg.RTR) {
                    active_buffer_length += write_ext_rtr(
                        write_location, &rx_msg);
                } else if (rx_msg.IDE == CAN_ID_EXT && !rx_msg.RTR) {
                    active_buffer_length += write_ext_message(
                        write_location, &rx_msg);
                } else if (rx_msg.IDE == CAN_ID_STD && rx_msg.RTR) {
                    active_buffer_length += write_std_rtr(
                        write_location, &rx_msg);
                } else if (rx_msg.IDE == CAN_ID_STD && !rx_msg.RTR) {
                    active_buffer_length += write_std_message(
                        write_location, &rx_msg);
                }
            }

            if (!hUsbDevice_0 || !hUsbDevice_0->pClassData) {
                /* Reset TX buffer if USB is not connected */
                active_buffer_length = 0;
            } else if (active_buffer_length &&
                        ((USBD_CDC_HandleTypeDef*)hUsbDevice_0->pClassData)->TxState == 0) {
                /* Transmit the next buffer if one is available */
                CDC_Transmit_FS(active_buffer ? tx_buffer_1 : tx_buffer_0,
                                active_buffer_length);
                active_buffer_length = 0;
                active_buffer = active_buffer ? 0 : 1;
            }
        }
    }
}
int main(void)

{
    extern struct keypad buttons[MAX_BUTTONS];
    extern volatile uint8_t SBstore[MAX_BUTTONS];
    extern uint8_t total_buttons;
    uint8_t pov[4] = {0};


  /* Configure the system clock, Initializes the Flash interface and the Systick */
  sysclock_init();

  /* Initialize all configured peripherals */
  gpio_init();
//  adc_init();
  MX_USB_DEVICE_Init();


  while (1)
  {
	  	 fill_buffer_4_axises();
	  	 CheckRotaries();

	  	 for (uint8_t i=0;i<MAX_POVS;i++) {
	  		pov[i]=0;
	  	 }

		 for (uint8_t i=0;i<total_buttons;i++) {
				if (SBstore[i] == pov1up_button){
					if (buttons[i].pressed)
						pov[0] |= 1<<3;
				}
				if (SBstore[i] == pov1right_button){
					if (buttons[i].pressed)
						pov[0] |= 1<<2;
				}
				if (SBstore[i] == pov1down_button){
					if (buttons[i].pressed)
						pov[0] |= 1<<1;
				}
				if (SBstore[i] == pov1left_button){
					if (buttons[i].pressed)
						pov[0] |= 1;
				}
				if (SBstore[i] == pov2up_button){
					if (buttons[i].pressed)
						pov[1] |= 1<<3;
				}
				if (SBstore[i] == pov2right_button){
					if (buttons[i].pressed)
						pov[1] |= 1<<2;
				}
				if (SBstore[i] == pov2down_button){
					if (buttons[i].pressed)
						pov[1] |= 1<<1;
				}
				if (SBstore[i] == pov2left_button){
					if (buttons[i].pressed)
						pov[1] |= 1;
				}
				if (SBstore[i] == pov3up_button){
					if (buttons[i].pressed)
						pov[2] |= 1<<3;
				}
				if (SBstore[i] == pov3right_button){
					if (buttons[i].pressed)
						pov[2] |= 1<<2;
				}
				if (SBstore[i] == pov3down_button){
					if (buttons[i].pressed)
						pov[2] |= 1<<1;
				}
				if (SBstore[i] == pov3left_button){
					if (buttons[i].pressed)
						pov[2] |= 1;
				}
				if (SBstore[i] == pov4up_button){
					if (buttons[i].pressed)
						pov[3] |= 1<<3;
				}
				if (SBstore[i] == pov4right_button){
					if (buttons[i].pressed)
						pov[3] |= 1<<2;
				}
				if (SBstore[i] == pov4down_button){
					if (buttons[i].pressed)
						pov[3] |= 1<<1;
				}
				if (SBstore[i] == pov4left_button){
					if (buttons[i].pressed)
						pov[3] |= 1;
				}
			 if (SBstore[i] == joystick_button) {
				 if (buttons[i].pressed){
					 //USBSendBuffer[i/8+1] |= ButtonsCodes[i%8];
					 gamepad_report.buttons |= 1ULL<<i;
				 } else {
					 //USBSendBuffer[i/8+1] &= ~ButtonsCodes[i%8];
					 gamepad_report.buttons &= ~(1ULL<<i);
				 }
			 }
			if (SBstore[i] == mouseleft_button){
				if (buttons[i].pressed){
					mouse_report.left_button = 1;
				} else {
					mouse_report.left_button = 0;
				}
			}
			if (SBstore[i] == mousemiddle_button){
				if (buttons[i].pressed){
					mouse_report.middle_button = 1;
				} else {
					mouse_report.middle_button = 0;
				}
			}
			if (SBstore[i] == mouseright_button){
				if (buttons[i].pressed){
					mouse_report.right_button = 1;
				} else {
					mouse_report.right_button = 0;
				}
			}
			if (SBstore[i] == leftcontrol_button){
				if (buttons[i].pressed){
					keyboard_report.left_ctrl = 1;
				} else {
					keyboard_report.left_ctrl = 0;
				}
			}
			if (SBstore[i] == leftshift_button){
				if (buttons[i].pressed){
					keyboard_report.left_shft = 1;
				} else {
					keyboard_report.left_shft = 0;
				}
			}
			if (SBstore[i] == leftalt_button){
				if (buttons[i].pressed){
					keyboard_report.left_alt = 1;
				} else {
					keyboard_report.left_alt = 0;
				}
			}
			if (SBstore[i] == leftgui_button){
				if (buttons[i].pressed){
					keyboard_report.left_gui = 1;
				} else {
					keyboard_report.left_gui = 0;
				}
			}
			if (SBstore[i] == rightcontrol_button){
				if (buttons[i].pressed){
					keyboard_report.right_ctrl = 1;
				} else {
					keyboard_report.right_ctrl = 0;
				}
			}
			if (SBstore[i] == rightshift_button){
				if (buttons[i].pressed){
					keyboard_report.right_shft = 1;
				} else {
					keyboard_report.right_shft = 0;
				}
			}
			if (SBstore[i] == rightalt_button){
				if (buttons[i].pressed){
					keyboard_report.right_alt = 1;
				} else {
					keyboard_report.right_alt = 0;
				}
			}
			if (SBstore[i] == rightgui_button){
				if (buttons[i].pressed){
					keyboard_report.right_gui = 1;
				} else {
					keyboard_report.right_gui = 0;
				}
			}
			if 		(((SBstore[i] >= a_button) && (SBstore[i] <= space_button)) ||
					((SBstore[i] >= f1_button) && (SBstore[i] <= f12_button)) ||
					((SBstore[i] >= insert_button) && (SBstore[i] <= uparrow_button))) {
				if (buttons[i].pressed){
					keyboard_report.key1 = SBstore[i];
				} else {
					keyboard_report.key1 = 0;
				}
			}
			if (SBstore[i] == volumemute_button) {
				if (buttons[i].pressed){
					multimedia_report.volume_mute = 1;
				} else {
					multimedia_report.volume_mute = 0;
				}
			}
			if (SBstore[i] == volumeup_button) {
				if (buttons[i].pressed){
					multimedia_report.volume_up = 1;
				} else {
					multimedia_report.volume_up = 0;
				}
			}
			if (SBstore[i] == volumedown_button) {
				if (buttons[i].pressed){
					multimedia_report.volume_down = 1;
				} else {
					multimedia_report.volume_down = 0;
				}
			}
		 }

		 for (uint8_t i=0;i<MAX_POVS;i++) {
		 	  			 switch (pov[i]) {
		 	  			 	 case (8)	: gamepad_report.pov[i] = 0; break;
		 	  			 	 case (12)	: gamepad_report.pov[i] = 1; break;
		 	  			 	 case (4)	: gamepad_report.pov[i] = 2; break;
		 	  			 	 case (6)	: gamepad_report.pov[i] = 3; break;
		 	  			 	 case (2)	: gamepad_report.pov[i] = 4; break;
		 	  			 	 case (3)	: gamepad_report.pov[i] = 5; break;
		 	  			 	 case (1)	: gamepad_report.pov[i] = 6; break;
		 	  			 	 case (9)	: gamepad_report.pov[i] = 7; break;
		 	  			 	 default	: gamepad_report.pov[i] = 8; break;
		 	  			 }
		 	  		 }

/*
	  for (uint8_t i=0;i<Number_Rotaries + config.total_single_encoders;i++){

				  diff = millis - RotaryStore[i].time_pressed;

				  if (diff > config.rotary_press_time) {
					  USBSendBuffer[(i/4)+encoders_offset] &= ~ButtonsCodes[(i%4)*2];
					  USBSendBuffer[(i/4)+encoders_offset] &= ~ButtonsCodes[(i%4)*2+1];
					  RotaryStore[i].pressed = 0;
					  RotaryStore[i].previous_state = 0;
				  } else {
					  if (!RotaryStore[i].previous_state){
						  if (RotaryStore[i].pressed == DIR_CW) {
							  USBSendBuffer[(i/4)+encoders_offset] |= ButtonsCodes[(i%4)*2];
						  }
						  if (RotaryStore[i].pressed == DIR_CCW) {
							  USBSendBuffer[(i/4)+encoders_offset] |= ButtonsCodes[(i%4)*2+1];
						  }
						  RotaryStore[i].previous_state = RotaryStore[i].pressed;
					  }
				  }
	  }

				  if (!RotaryStore[i].pressed) {
					  USBSendBuffer[(i/4)+encoders_offset] &= ~ButtonsCodes[(i%4)*2];
					  USBSendBuffer[(i/4)+encoders_offset] &= ~ButtonsCodes[(i%4)*2+1];
				  }


				  if (RotaryStore[i].pressed == DIR_CW) {
					  if ( diff > config.rotary_press_time){
						  USBSendBuffer[(i/4)+encoders_offset] &= ~ButtonsCodes[(i%4)*2];
						  RotaryStore[i].pressed = 0;
					  }
				  		 else
				  			 USBSendBuffer[(i/4)+encoders_offset] |= ButtonsCodes[(i%4)*2];
				  	 }

				  if (RotaryStore[i].pressed == DIR_CCW) {
					  if (diff > config.rotary_press_time){
						  USBSendBuffer[(i/4)+encoders_offset] &= ~ButtonsCodes[(i%4)*2+1];
						  RotaryStore[i].pressed = 0;
					  }
				  		  else
				  			  USBSendBuffer[(i/4)+encoders_offset] |= ButtonsCodes[(i%4)*2+1];
				  		}
			  }
*/

	  //We should send report only if some action exist
			/*  for (uint8_t i=1;i<21;i++) {
				  chk |= USBSendBuffer[i];
			  }
			  for (uint8_t i=21;i<25;i++) {
				  if (USBSendBuffer[i] != 8) chk |= USBSendBuffer[i];
			  }
			  if (chk) {
				 USBD_CUSTOM_HID_SendReport(hUsbDevice_0, USBSendBuffer, USEDPINS+1);
				 packet_counter=0;
			  } else {
				  packet_counter++;
				  if (packet_counter < 6) USBD_CUSTOM_HID_SendReport(hUsbDevice_0, USBSendBuffer, USEDPINS+1);
			  }*/
  }
}
示例#20
0
static void main_task(void *pvParameters) {
  int i;
  char ch;
  bool selftestPasses = true;

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_I2C1_Init();
  MX_USART1_UART_Init();
  MX_SPI1_Init();
  MX_USB_DEVICE_Init();

  // Light up all LEDs to test
  ledOn(ledRanging);
  ledOn(ledSync);
  ledOn(ledMode);

  printf("\r\n\r\n====================\r\n");

  printf("SYSTEM\t: CPU-ID: ");
  for (i=0; i<12; i++) {
    printf("%02x", uid[i]);
  }
  printf("\r\n");

  // Initializing pressure sensor (if present ...)
  lps25hInit(&hi2c1);
  testSupportPrintStart("Initializing pressure sensor");
  if (lps25hTestConnection()) {
    printf("[OK]\r\n");
    lps25hSetEnabled(true);
  } else {
    printf("[FAIL] (%u)\r\n", (unsigned int)hi2c1.ErrorCode);
    selftestPasses = false;
  }

  testSupportPrintStart("Pressure sensor self-test");
  testSupportReport(&selftestPasses, lps25hSelfTest());

  // Initializing i2c eeprom
  eepromInit(&hi2c1);
  testSupportPrintStart("EEPROM self-test");
  testSupportReport(&selftestPasses, eepromTest());

  cfgInit();

  // Initialising radio
  testSupportPrintStart("Initialize UWB ");
  uwbInit();
  if (uwbTest()) {
    printf("[OK]\r\n");
  } else {
    printf("[ERROR]: %s\r\n", uwbStrError());
    selftestPasses = false;
  }

  if (!selftestPasses) {
    printf("TEST\t: One or more self-tests failed, blocking startup!\r\n");
    usbcommSetSystemStarted(true);
  }

  // Printing UWB configuration
  struct uwbConfig_s * uwbConfig = uwbGetConfig();
  printf("CONFIG\t: Address is 0x%X\r\n", uwbConfig->address[0]);
  printf("CONFIG\t: Mode is %s\r\n", uwbAlgorithmName(uwbConfig->mode));
  printf("CONFIG\t: Tag mode anchor list (%i): ", uwbConfig->anchorListSize);
  for (i = 0; i < uwbConfig->anchorListSize; i++) {
    printf("0x%02X ", uwbConfig->anchors[i]);
  }
  printf("\r\n");

  HAL_Delay(500);

  ledOff(ledRanging);
  ledOff(ledSync);
  ledOff(ledMode);

  printf("SYSTEM\t: Node started ...\r\n");
  printf("SYSTEM\t: Press 'h' for help.\r\n");

  usbcommSetSystemStarted(true);

  // Starts UWB protocol
  uwbStart();

  // Main loop ...
  while(1) {
    usbcommPrintWelcomeMessage();

    ledTick();
    // // Measure pressure
    // if (uwbConfig.mode != modeSniffer) {
    //   if(lps25hGetData(&pressure, &temperature, &asl)) {
    //     pressure_ok = true;
    //   } else {
    //     printf("Fail reading pressure\r\n");
    //     printf("pressure not ok\r\n");
    //   }
    // }

    // Accepts serial commands
#ifdef USE_FTDI_UART
    if (HAL_UART_Receive(&huart1, (uint8_t*)&ch, 1, 0) == HAL_OK) {
#else
    if(usbcommRead(&ch, 1)) {
#endif
      handleInput(ch);
    }
  }
}

/* Function required to use "printf" to print on serial console */
int _write (int fd, const void *buf, size_t count)
{
  // stdout
  if (fd == 1) {
    #ifdef USE_FTDI_UART
      HAL_UART_Transmit(&huart1, (uint8_t *)buf, count, HAL_MAX_DELAY);
    #else
      usbcommWrite(buf, count);
    #endif
  }

  // stderr
  if (fd == 2) {
    HAL_UART_Transmit(&huart1, (uint8_t *)buf, count, HAL_MAX_DELAY);
  }

  return count;
}

static void handleInput(char ch) {
  bool configChanged = true;
  static enum menu_e {mainMenu, modeMenu} currentMenu = mainMenu;

  switch (currentMenu) {
    case mainMenu:
      switch (ch) {
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
          changeAddress(ch - '0');
          break;
        case 'a': changeMode(MODE_ANCHOR); break;
        case 't': changeMode(MODE_TAG); break;
        case 's': changeMode(MODE_SNIFFER); break;
        case 'm':
          printModeList();
          printf("Type 0-9 to choose new mode...\r\n");
          currentMenu = modeMenu;
          configChanged = false;
          break;
        case 'd': restConfig(); break;
        case 'h':
          help();
          configChanged = false;
          break;
        case '#':
          productionTestsRun();
          printf("System halted, reset to continue\r\n");
          while(true){}
          break;
        default:
          configChanged = false;
          break;
      }
      break;
    case modeMenu:
      switch(ch) {
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
          changeMode(ch - '0');
          currentMenu = mainMenu;
          break;
        default:
          printf("Incorrect mode '%c'\r\n", ch);
          currentMenu = mainMenu;
          configChanged = false;
          break;
      }
      break;
  }

  if (configChanged) {
    printf("EEPROM configuration changed, restart for it to take effect!\r\n");
  }
}
示例#21
0
int main(void)
{

  /* USER CODE BEGIN 1 */


  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_CRC_Init();
  MX_I2C1_Init();
  MX_SPI2_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_TIM4_Init();
  MX_USART2_UART_Init();

  /* USER CODE BEGIN 2 */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);

  // reinitialize uart with speed from config
  huart2.Init.BaudRate = USART_DEBUG_SPEED;
  HAL_UART_Init(&huart2);

  DEBUG_PRINTF("Hello, Lepton!\n\r");
  fflush(stdout);

  lepton_init();

  HAL_Delay(1000);

  init_lepton_command_interface();
#ifdef ENABLE_LEPTON_AGC
  enable_lepton_agc();
#endif

#ifdef Y16
  enable_telemetry();
#else
  enable_rgb888(PSUEDOCOLOR_LUT);
#endif

  DEBUG_PRINTF("reading_tmp007_regs...\n\r");

  read_tmp007_regs();

  DEBUG_PRINTF("Initialized...\n\r");

  HAL_Delay(250);

  MX_USB_DEVICE_Init();

  PT_INIT(&lepton_task_pt);
  PT_INIT(&usb_task_pt);
  PT_INIT(&uart_task_pt);

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

	  PT_SCHEDULE(lepton_task(&lepton_task_pt));
	  PT_SCHEDULE(usb_task(&usb_task_pt));
	  PT_SCHEDULE(uart_task(&uart_task_pt));
	  PT_SCHEDULE(button_task(&button_task_pt));

  }
  /* USER CODE END 3 */

}
示例#22
0
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_LWIP_Init();
  MX_USART1_UART_Init();
  MX_USB_DEVICE_Init();

  /* USER CODE BEGIN 2 */
  printf("Application startup successful....\n");
  httpd_init();

  ip4_addr_t ip_addr;

  IP4_ADDR(&ip_addr, 192, 168, 1, 1);

  err_t err;

  // Setup an empty client info structure
  struct mqtt_connect_client_info_t ci;
  memset(&ci, 0, sizeof(ci));

  ci.client_id = "lwip_test";

  err = mqtt_client_connect(&client, &ip_addr, MQTT_PORT, mqtt_connection_cb, 0, &ci);

    // For now just print the result code if something goes wrong
    if(err != ERR_OK) {
      printf("mqtt_connect return %d\n", err);
    }

   uint8_t published=0;

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	  MX_LWIP_Process();

	  if(mqtt_client_is_connected(&client) && !published)
	  {
		  example_publish(&client, "Hallo Welt!");
		  published=1;
	  }

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
示例#23
0
int main(void)
{
    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();

    /* Configure the system clock */
    SystemClock_Config();

    /* Initialize all configured peripherals */
    MX_GPIO_Init();
    MX_DMA_Init();
    MX_ADC_Init();
    MX_SPI1_Init();
    MX_USB_DEVICE_Init();
    MX_TIM14_Init();

    HAL_FLASH_Unlock();
    EE_Init();

    EE_ReadVariable(VirtAddVarTab[0], &x_low_th);
    EE_ReadVariable(VirtAddVarTab[1], &x_high_th);
    EE_ReadVariable(VirtAddVarTab[2], &y_low_th);
    EE_ReadVariable(VirtAddVarTab[3], &y_high_th);

    HAL_FLASH_Lock();

    HAL_ADC_Start_DMA(&hadc, (uint32_t*)axis, 5);

    while (1)
    {
        HAL_GPIO_WritePin(SPI1_nCS_GPIO_Port, SPI1_nCS_Pin, GPIO_PIN_SET);

        HAL_TIM_Base_Start_IT(&htim14);
        while (!u100ticks) /* do nothing for 100 us */;
        HAL_TIM_Base_Stop_IT(&htim14);
        u100ticks = 0;

        HAL_StatusTypeDef status =
            HAL_SPI_Receive(&hspi1, rx_buffer, sizeof(rx_buffer), 3000);

        switch(status)
        {
        case HAL_OK:
            report.buttons[0] = 0x00;
            // report.buttons[1] = 0x00;
            report.buttons[2] = 0x00;

            if ((rx_buffer[0] & 0xff) != 0xff)   // if all bits of rx_buffer[0] is 1 assume shifter is disconnected
            {
                if (rx_buffer[0] & 4)   report.buttons[0] |= 1;         else report.buttons[0] &= ~1;
                if (rx_buffer[0] & 1)   report.buttons[0] |= (1 << 1);  else report.buttons[0] &= ~(1 << 1);
                if (rx_buffer[0] & 2)   report.buttons[0] |= (1 << 2);  else report.buttons[0] &= ~(1 << 2);
                if (rx_buffer[0] & 8)   report.buttons[0] |= (1 << 3);  else report.buttons[0] &= ~(1 << 3);

                if (rx_buffer[1] & 1)   report.buttons[2] |= 1;         else report.buttons[2] &= ~1;
                if (rx_buffer[1] & 2)   report.buttons[2] |= (1 << 1);  else report.buttons[2] &= ~(1 << 1);
                if (rx_buffer[1] & 4)   report.buttons[2] |= (1 << 2);  else report.buttons[2] &= ~(1 << 2);
                if (rx_buffer[1] & 8)   report.buttons[2] |= (1 << 3);  else report.buttons[2] &= ~(1 << 3);

                if (rx_buffer[1] & 32)  report.buttons[0] |= (1 << 4);  else report.buttons[0] &= ~(1 << 4);
                if (rx_buffer[1] & 128) report.buttons[0] |= (1 << 5);  else report.buttons[0] &= ~(1 << 5);
                if (rx_buffer[1] & 64)  report.buttons[0] |= (1 << 6);  else report.buttons[0] &= ~(1 << 6);
                if (rx_buffer[1] & 16)  report.buttons[0] |= (1 << 7);  else report.buttons[0] &= ~(1 << 7);
            }
            break;

        case HAL_TIMEOUT:
        case HAL_BUSY:
        case HAL_ERROR:
            Error_Handler();
        default:
            report.buttons[0] = 0xff;
            break;
        }

        HAL_GPIO_WritePin(SPI1_nCS_GPIO_Port, SPI1_nCS_Pin, GPIO_PIN_RESET);
        report.id = 0x01;

        x_axis = ((X_AXIS << 2) + x_axis * 96) / 100;
        y_axis = ((Y_AXIS << 2) + y_axis * 96) / 100;

        if (rx_buffer[0] & 16)
        {
            if (y_axis < y_low_th)   // stick towards player
            {
                report.buttons[1] = 128;
                report.buttons[2] &= ~(1 << 4);
            }
            else if (y_axis > y_high_th)   // stick opposite to player
            {
                report.buttons[1] = 0; // neutral
                report.buttons[2] |= (1 << 4);
            }
            else
            {
                report.buttons[1] = 0; // neutral
                report.buttons[2] &= ~(1 << 4);
            }
        }
        else
        {
            report.buttons[1] &= ~(1 << 7);
            report.buttons[2] &= ~(1 << 4);

            if (y_axis < y_low_th)   // stick towards player
            {
                if (x_axis < x_low_th)
                {
                    if (!report.buttons[1]) report.buttons[1] = 2; // 2nd gear
                }
                else if (!report.buttons[1])
                {
                    report.buttons[1] = (x_axis > x_high_th) ? ((rx_buffer[0] & 64) ? 64 : 32) : 8;
                }
            }
            else
            {
                if (y_axis > y_high_th)   // stick opposite to player
                {
                    if (x_axis < x_low_th)
                    {
                        if (!report.buttons[1]) report.buttons[1] = 1; // 1st gear
                    }
                    else if (!report.buttons[1])
                    {
                        report.buttons[1] = (x_axis > x_high_th) ? 16 : 4;
                    }
                }
                else
                {
                    report.buttons[1] = 0; // neutral
                }
            }
        }

        report.axis[0] = x_axis;
        report.axis[1] = y_axis;

        if (report2send == 2)
        {
            HAL_FLASH_Unlock();

            EE_WriteVariable(VirtAddVarTab[0], x_low_th);
            EE_WriteVariable(VirtAddVarTab[1], x_high_th);
            EE_WriteVariable(VirtAddVarTab[2], y_low_th);
            EE_WriteVariable(VirtAddVarTab[3], y_high_th);

            HAL_FLASH_Lock();
            report2send = 0;
        }

        if (hUsbDeviceFS.pClassData
                && ((USBD_HID_HandleTypeDef *)hUsbDeviceFS.pClassData)->state == HID_IDLE)
        {
            USBD_HID_SendReport(&hUsbDeviceFS, (uint8_t *)&report, sizeof(report));
        }
    }
}
示例#24
0
int main(void)
{

  /* USER CODE BEGIN 1 */
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART1_UART_Init();
  MX_USB_DEVICE_Init();

  /* USER CODE BEGIN 2 */
  HAL_PCDEx_SetConnectionState(hUsbDeviceFS.pData, connectionState);// USB Activate
  HAL_Delay(3000);
  printf("Hello world.\r\n");

  uint8_t buf = 0;
  uint8_t cbuf[100];
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

    // USART1 <=> VCP echo test
    if (USB_IS_ACTIVE())
    {
      HAL_Delay(5000);

      printf("\r\nVCP Connected > ");
      fflush(stdout);
      VCP_write("\r\nVCP Connected > ", 18);

      while (USB_IS_ACTIVE())
      {
        // VCP to USART1
        if (VCP_read(&buf, 1) == 1 && buf)
        {
          printf("\033[36m%c\033[0m", buf);
          fflush(stdout);
          VCP_write(&buf, 1);
          buf = 0;
        }

        // USART1 to VCP
        HAL_UART_Receive(&huart1, &buf, 1, 1);
        if (buf)
        {
          sprintf(cbuf, "\033[36m%c\033[0m", buf);
          VCP_write(&cbuf, 10);
          printf("%c", buf);
          fflush(stdout);
          buf = 0;
        }
      }

      printf("\r\nVCP Disconnected.\r\n");
    }
    else
    {
      // [debug] dump device status
      printf("\rdev_state = %d", hUsbDeviceFS.dev_state);
      fflush(stdout);
      HAL_Delay(500);
    }
  }
  /* USER CODE END 3 */

}