Select missions with right encoder
This commit is contained in:
		@ -1,17 +0,0 @@
 | 
			
		||||
#include "graphics.h"
 | 
			
		||||
 | 
			
		||||
#include "stm32h7xx_hal.h"
 | 
			
		||||
#include "tx_api.h"
 | 
			
		||||
 | 
			
		||||
#include "hx8357d.h"
 | 
			
		||||
#include "main.h"
 | 
			
		||||
 | 
			
		||||
void graphics_thread_entry(ULONG _) {
 | 
			
		||||
  HX8357D_Init();
 | 
			
		||||
  HX8357D_Mode_RGB666();
 | 
			
		||||
 | 
			
		||||
  while (1) {
 | 
			
		||||
    HAL_GPIO_TogglePin(STATUS2_GPIO_Port, STATUS2_Pin);
 | 
			
		||||
    tx_thread_sleep(100);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -135,6 +135,8 @@ int main(void) {
 | 
			
		||||
    Error_Handler();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  HX8357D_Init();
 | 
			
		||||
  HX8357D_Mode_RGB666();
 | 
			
		||||
  /* USER CODE END 2 */
 | 
			
		||||
 | 
			
		||||
  MX_ThreadX_Init();
 | 
			
		||||
@ -395,8 +397,7 @@ static void MX_LTDC_Init(void) {
 | 
			
		||||
  pLayerCfg.Alpha0 = 0;
 | 
			
		||||
  pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
 | 
			
		||||
  pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA;
 | 
			
		||||
  // pLayerCfg.FBStartAdress = (uint32_t)&image_data_ft_logo_rainbow_rgb565;
 | 
			
		||||
  pLayerCfg.FBStartAdress = (uint32_t)0x24040000;
 | 
			
		||||
  pLayerCfg.FBStartAdress = 0;
 | 
			
		||||
  pLayerCfg.ImageWidth = 320;
 | 
			
		||||
  pLayerCfg.ImageHeight = 480;
 | 
			
		||||
  pLayerCfg.Backcolor.Blue = 0;
 | 
			
		||||
@ -717,7 +718,7 @@ static void MX_GPIO_Init(void) {
 | 
			
		||||
 | 
			
		||||
  /*Configure GPIO pins : ENC1A_Pin ENC1B_Pin ENC2A_Pin ENC2B_Pin */
 | 
			
		||||
  GPIO_InitStruct.Pin = ENC1A_Pin | ENC1B_Pin | ENC2A_Pin | ENC2B_Pin;
 | 
			
		||||
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
 | 
			
		||||
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
 | 
			
		||||
  GPIO_InitStruct.Pull = GPIO_NOPULL;
 | 
			
		||||
  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
 | 
			
		||||
 | 
			
		||||
@ -758,6 +759,16 @@ static void MX_GPIO_Init(void) {
 | 
			
		||||
  GPIO_InitStruct.Pull = GPIO_NOPULL;
 | 
			
		||||
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 | 
			
		||||
  HAL_GPIO_Init(BOOT0_SET_GPIO_Port, &GPIO_InitStruct);
 | 
			
		||||
 | 
			
		||||
  /* EXTI interrupt init*/
 | 
			
		||||
  HAL_NVIC_SetPriority(EXTI3_IRQn, 0, 0);
 | 
			
		||||
  HAL_NVIC_EnableIRQ(EXTI3_IRQn);
 | 
			
		||||
 | 
			
		||||
  HAL_NVIC_SetPriority(EXTI4_IRQn, 0, 0);
 | 
			
		||||
  HAL_NVIC_EnableIRQ(EXTI4_IRQn);
 | 
			
		||||
 | 
			
		||||
  HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
 | 
			
		||||
  HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* USER CODE BEGIN 4 */
 | 
			
		||||
 | 
			
		||||
@ -160,6 +160,49 @@ void DebugMon_Handler(void)
 | 
			
		||||
/* please refer to the startup file (startup_stm32h7xx.s).                    */
 | 
			
		||||
/******************************************************************************/
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief This function handles EXTI line3 interrupt.
 | 
			
		||||
  */
 | 
			
		||||
void EXTI3_IRQHandler(void)
 | 
			
		||||
{
 | 
			
		||||
  /* USER CODE BEGIN EXTI3_IRQn 0 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END EXTI3_IRQn 0 */
 | 
			
		||||
  HAL_GPIO_EXTI_IRQHandler(ENC1A_Pin);
 | 
			
		||||
  /* USER CODE BEGIN EXTI3_IRQn 1 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END EXTI3_IRQn 1 */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief This function handles EXTI line4 interrupt.
 | 
			
		||||
  */
 | 
			
		||||
void EXTI4_IRQHandler(void)
 | 
			
		||||
{
 | 
			
		||||
  /* USER CODE BEGIN EXTI4_IRQn 0 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END EXTI4_IRQn 0 */
 | 
			
		||||
  HAL_GPIO_EXTI_IRQHandler(ENC1B_Pin);
 | 
			
		||||
  /* USER CODE BEGIN EXTI4_IRQn 1 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END EXTI4_IRQn 1 */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief This function handles EXTI line[9:5] interrupts.
 | 
			
		||||
  */
 | 
			
		||||
void EXTI9_5_IRQHandler(void)
 | 
			
		||||
{
 | 
			
		||||
  /* USER CODE BEGIN EXTI9_5_IRQn 0 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END EXTI9_5_IRQn 0 */
 | 
			
		||||
  HAL_GPIO_EXTI_IRQHandler(ENC2A_Pin);
 | 
			
		||||
  HAL_GPIO_EXTI_IRQHandler(ENC2B_Pin);
 | 
			
		||||
  /* USER CODE BEGIN EXTI9_5_IRQn 1 */
 | 
			
		||||
 | 
			
		||||
  /* USER CODE END EXTI9_5_IRQn 1 */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief This function handles TIM6 global interrupt, DAC1_CH1 and DAC1_CH2 underrun error interrupts.
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										97
									
								
								Core/Src/ui.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								Core/Src/ui.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,97 @@
 | 
			
		||||
#include "ui.h"
 | 
			
		||||
 | 
			
		||||
#include "stm32h7a3xx.h"
 | 
			
		||||
#include "stm32h7xx_hal.h"
 | 
			
		||||
#include "stm32h7xx_hal_gpio.h"
 | 
			
		||||
#include "tx_api.h"
 | 
			
		||||
 | 
			
		||||
#include "hx8357d.h"
 | 
			
		||||
#include "main.h"
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
void ui_thread_entry(ULONG _) {
 | 
			
		||||
  GPIO_TypeDef *button_ports[NUM_BUTTONS] = {BTN1_GPIO_Port, BTN2_GPIO_Port,
 | 
			
		||||
                                             BTN3_GPIO_Port, BTN4_GPIO_Port,
 | 
			
		||||
                                             BTN5_GPIO_Port, BTN6_GPIO_Port};
 | 
			
		||||
  uint16_t button_pins[NUM_BUTTONS] = {BTN1_Pin, BTN2_Pin, BTN3_Pin,
 | 
			
		||||
                                       BTN4_Pin, BTN5_Pin, BTN6_Pin};
 | 
			
		||||
  GPIO_PinState button_states[NUM_BUTTONS] = {GPIO_PIN_RESET};
 | 
			
		||||
  uint32_t button_change_times[NUM_BUTTONS] = {HAL_GetTick()};
 | 
			
		||||
 | 
			
		||||
  while (1) {
 | 
			
		||||
    for (int i = 0; i < NUM_BUTTONS; i++) {
 | 
			
		||||
      GPIO_PinState state = HAL_GPIO_ReadPin(button_ports[i], button_pins[i]);
 | 
			
		||||
      if (state != button_states[i]) {
 | 
			
		||||
        uint32_t now = HAL_GetTick();
 | 
			
		||||
        if (state == GPIO_PIN_RESET && now - button_change_times[i]) {
 | 
			
		||||
          // Button release event!
 | 
			
		||||
          UIMessage msg = {.kind = UMK_BTN_RELEASED, .number = i};
 | 
			
		||||
          tx_queue_send(&ui_queue, &msg, TX_NO_WAIT);
 | 
			
		||||
        }
 | 
			
		||||
        button_change_times[i] = now;
 | 
			
		||||
        button_states[i] = state;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    // Release so other threads can get scheduled
 | 
			
		||||
    tx_thread_sleep(1);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
 | 
			
		||||
  // This gets called when an edge on one of the encoder pins is detected.
 | 
			
		||||
  static uint32_t last_change[NUM_ENCS * 2] = {0};
 | 
			
		||||
  static GPIO_PinState last_state[NUM_ENCS * 2] = {GPIO_PIN_RESET};
 | 
			
		||||
 | 
			
		||||
  if (GPIO_Pin == ENC2B_Pin) {
 | 
			
		||||
    // ENC2A and ENC2B share an interrupt line, so the HAL calls this callback
 | 
			
		||||
    // once with each pin. Since we already handled the interrupt once for
 | 
			
		||||
    // ENC2A, we can just ignore it now.
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  uint32_t now = HAL_GetTick();
 | 
			
		||||
 | 
			
		||||
  uint16_t pin_a, pin_b;
 | 
			
		||||
  int idx_a, idx_b;
 | 
			
		||||
  UIMessage msg;
 | 
			
		||||
  if (GPIO_Pin == ENC1A_Pin || GPIO_Pin == ENC1B_Pin) {
 | 
			
		||||
    pin_a = ENC1A_Pin;
 | 
			
		||||
    pin_b = ENC1B_Pin;
 | 
			
		||||
    idx_a = 0;
 | 
			
		||||
    idx_b = 1;
 | 
			
		||||
    msg.number = 0;
 | 
			
		||||
  } else {
 | 
			
		||||
    pin_a = ENC2A_Pin;
 | 
			
		||||
    pin_b = ENC2B_Pin;
 | 
			
		||||
    idx_a = 2;
 | 
			
		||||
    idx_b = 3;
 | 
			
		||||
    msg.number = 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // All encoder pins are on port E
 | 
			
		||||
  GPIO_PinState state_a = HAL_GPIO_ReadPin(GPIOE, pin_a);
 | 
			
		||||
  GPIO_PinState state_b = HAL_GPIO_ReadPin(GPIOE, pin_b);
 | 
			
		||||
  int a_changed = state_a != last_state[idx_a];
 | 
			
		||||
  int b_changed = state_b != last_state[idx_b];
 | 
			
		||||
  last_state[idx_a] = state_a;
 | 
			
		||||
  last_state[idx_b] = state_b;
 | 
			
		||||
 | 
			
		||||
  if (state_a == GPIO_PIN_RESET && state_b == GPIO_PIN_RESET) {
 | 
			
		||||
    // Second falling edge, direction depends on which pin changed last
 | 
			
		||||
    if (a_changed && b_changed) {
 | 
			
		||||
      // This shouldn't happen. Ignore this event.
 | 
			
		||||
      last_change[idx_a] = now;
 | 
			
		||||
      last_change[idx_b] = now;
 | 
			
		||||
      return;
 | 
			
		||||
    } else if (a_changed) {
 | 
			
		||||
      last_change[idx_a] = now;
 | 
			
		||||
      msg.kind = UMK_ENC_CCW;
 | 
			
		||||
    } else if (b_changed) {
 | 
			
		||||
      last_change[idx_b] = now;
 | 
			
		||||
      msg.kind = UMK_ENC_CW;
 | 
			
		||||
    } else {
 | 
			
		||||
      // This shouldn't happen. Ignore this event.
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    tx_queue_send(&ui_queue, &msg, TX_NO_WAIT);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user