Handle Mission Select
This commit is contained in:
		@ -1,4 +1,60 @@
 | 
			
		||||
#ifndef __EVENTS_H
 | 
			
		||||
#define __EVENTS_H
 | 
			
		||||
 | 
			
		||||
#include "stm32g441xx.h"
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
typedef enum {
 | 
			
		||||
  BTN_PRESS_PREV,
 | 
			
		||||
  BTN_PRESS_R2D,
 | 
			
		||||
  BTN_PRESS_OK,
 | 
			
		||||
  BTN_PRESS_NEXT
 | 
			
		||||
} ButtonPressEvent;
 | 
			
		||||
 | 
			
		||||
typedef enum { ENC0, ENC1 } Encoder;
 | 
			
		||||
typedef enum { ENC_CHANGE_INC, ENC_CHANGE_DEC } EncoderChangeDirection;
 | 
			
		||||
typedef struct {
 | 
			
		||||
  Encoder encoder;
 | 
			
		||||
  EncoderChangeDirection dir;
 | 
			
		||||
} EncoderChangeEvent;
 | 
			
		||||
 | 
			
		||||
typedef enum { EV_BTN_PRESS, EV_ENC_CHANGE } EventType;
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
  EventType type;
 | 
			
		||||
  union {
 | 
			
		||||
    ButtonPressEvent btn_press;
 | 
			
		||||
    EncoderChangeEvent enc_change;
 | 
			
		||||
  };
 | 
			
		||||
} Event;
 | 
			
		||||
 | 
			
		||||
#define EVENT_QUEUE_SIZE 32
 | 
			
		||||
typedef struct {
 | 
			
		||||
  Event ring_buffer[EVENT_QUEUE_SIZE];
 | 
			
		||||
  uint16_t read_idx;
 | 
			
		||||
  uint16_t write_idx;
 | 
			
		||||
} EventQueue;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Push an event to the back of the queue.
 | 
			
		||||
 *
 | 
			
		||||
 * The event is deep-copied to the queue, so it can be deallocated after the
 | 
			
		||||
 * call is complete.
 | 
			
		||||
 */
 | 
			
		||||
void event_push(Event *ev);
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Pop an event from the start of the queue.
 | 
			
		||||
 *
 | 
			
		||||
 * The value in the queue may be overwritten with the next event_push() call.
 | 
			
		||||
 * Since that call can happen in an interrupt, i.e. is probably out of control
 | 
			
		||||
 * of the event_pop() caller, we return by value here.
 | 
			
		||||
 */
 | 
			
		||||
Event event_pop();
 | 
			
		||||
 | 
			
		||||
uint16_t event_num_pending();
 | 
			
		||||
uint16_t event_num_free();
 | 
			
		||||
 | 
			
		||||
void handle_events();
 | 
			
		||||
 | 
			
		||||
#endif // __EVENTS_H
 | 
			
		||||
@ -75,12 +75,16 @@ void Error_Handler(void);
 | 
			
		||||
#define V_POT_GPIO_Port GPIOB
 | 
			
		||||
#define BTN0_Pin GPIO_PIN_12
 | 
			
		||||
#define BTN0_GPIO_Port GPIOB
 | 
			
		||||
#define BTN0_EXTI_IRQn EXTI15_10_IRQn
 | 
			
		||||
#define BTN1_Pin GPIO_PIN_13
 | 
			
		||||
#define BTN1_GPIO_Port GPIOB
 | 
			
		||||
#define BTN1_EXTI_IRQn EXTI15_10_IRQn
 | 
			
		||||
#define BTN2_Pin GPIO_PIN_14
 | 
			
		||||
#define BTN2_GPIO_Port GPIOB
 | 
			
		||||
#define BTN2_EXTI_IRQn EXTI15_10_IRQn
 | 
			
		||||
#define BTN3_Pin GPIO_PIN_15
 | 
			
		||||
#define BTN3_GPIO_Port GPIOB
 | 
			
		||||
#define BTN3_EXTI_IRQn EXTI15_10_IRQn
 | 
			
		||||
#define DISP_RESET_Pin GPIO_PIN_15
 | 
			
		||||
#define DISP_RESET_GPIO_Port GPIOA
 | 
			
		||||
#define ENC0A_Pin GPIO_PIN_4
 | 
			
		||||
 | 
			
		||||
@ -28,5 +28,6 @@ extern size_t rpi_num_polls;
 | 
			
		||||
void rpi_init(I2C_HandleTypeDef *handle);
 | 
			
		||||
 | 
			
		||||
void rpi_update_tx_buffer();
 | 
			
		||||
void rpi_update_tx_buffer_mission_select();
 | 
			
		||||
 | 
			
		||||
#endif // __RPI_H
 | 
			
		||||
 | 
			
		||||
@ -8,8 +8,33 @@ typedef enum {
 | 
			
		||||
  VIEW_TESTING = 3
 | 
			
		||||
} STWView;
 | 
			
		||||
 | 
			
		||||
typedef enum {
 | 
			
		||||
  MISSION_NONE,
 | 
			
		||||
  MISSION_ACCELERATION,
 | 
			
		||||
  MISSION_SKIDPAD,
 | 
			
		||||
  MISSION_AUTOCROSS,
 | 
			
		||||
  MISSION_TRACKDRIVE,
 | 
			
		||||
  MISSION_EBS_TEST,
 | 
			
		||||
  MISSION_INSPECTION,
 | 
			
		||||
  MISSION_MANUAL
 | 
			
		||||
} Mission;
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
  Mission selection;
 | 
			
		||||
} MissionSelectState;
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
  Mission current_mission;
 | 
			
		||||
} AMIState;
 | 
			
		||||
 | 
			
		||||
typedef union {
 | 
			
		||||
  MissionSelectState mission_select;
 | 
			
		||||
  AMIState ami;
 | 
			
		||||
} ViewState;
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
  STWView view;
 | 
			
		||||
  ViewState view_state;
 | 
			
		||||
} STWState;
 | 
			
		||||
 | 
			
		||||
extern STWState stw_state;
 | 
			
		||||
 | 
			
		||||
@ -56,6 +56,7 @@ void DebugMon_Handler(void);
 | 
			
		||||
void PendSV_Handler(void);
 | 
			
		||||
void SysTick_Handler(void);
 | 
			
		||||
void I2C2_EV_IRQHandler(void);
 | 
			
		||||
void EXTI15_10_IRQHandler(void);
 | 
			
		||||
/* USER CODE BEGIN EFP */
 | 
			
		||||
 | 
			
		||||
/* USER CODE END EFP */
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										11
									
								
								Core/Inc/user_inputs.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Core/Inc/user_inputs.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
#ifndef __FT_USER_INPUTS_H
 | 
			
		||||
#define __FT_USER_INPUTS_H
 | 
			
		||||
 | 
			
		||||
#include "events.h"
 | 
			
		||||
#include "stm32g4xx_hal.h"
 | 
			
		||||
 | 
			
		||||
void handle_button_press(const ButtonPressEvent *ev);
 | 
			
		||||
 | 
			
		||||
void handle_button_press_mission_select(const ButtonPressEvent *ev);
 | 
			
		||||
 | 
			
		||||
#endif // __FT_USER_INPUTS_H
 | 
			
		||||
		Reference in New Issue
	
	Block a user