|
|
|
@@ -46,17 +46,6 @@
|
|
|
|
|
#define WAIT_UNTIL_CB_PRESSED while (!HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0) && HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_8))
|
|
|
|
|
#define WAIT_UNTIL_CB_RELEASED while (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0) || !HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_8))
|
|
|
|
|
|
|
|
|
|
#define UB (GPIOA->IDR & GPIO_PIN_0)
|
|
|
|
|
#define SWT1 !(GPIOC->IDR & GPIO_PIN_11)
|
|
|
|
|
#define SWT2 !(GPIOA->IDR & GPIO_PIN_15)
|
|
|
|
|
#define SWT3 !(GPIOC->IDR & GPIO_PIN_9)
|
|
|
|
|
#define SWT4 !(GPIOC->IDR & GPIO_PIN_6)
|
|
|
|
|
#define SWT5 !(GPIOC->IDR & GPIO_PIN_8)
|
|
|
|
|
|
|
|
|
|
#define WAIT_UNTIL_ALL_BUTTONS_RELEASED do {} while ( UB || SWT1 || SWT2 || SWT3 || SWT4 || SWT5 )
|
|
|
|
|
|
|
|
|
|
#define LEN(x) ( sizeof(x) / sizeof((x)[0]) )
|
|
|
|
|
|
|
|
|
|
/* USER CODE END PD */
|
|
|
|
|
|
|
|
|
|
/* Private macro -------------------------------------------------------------*/
|
|
|
|
@@ -79,19 +68,22 @@ extern size_t display_current_frame;
|
|
|
|
|
|
|
|
|
|
/* USER CODE BEGIN PV */
|
|
|
|
|
|
|
|
|
|
static const int ((*executors[])(void)) = {
|
|
|
|
|
int ((*executors[])(void)) = {
|
|
|
|
|
DNI_show_celsius,
|
|
|
|
|
DNI_show_fahrenheit,
|
|
|
|
|
PCA9685_run_test,
|
|
|
|
|
EEPROM_24AA02E48_run_test,
|
|
|
|
|
CS43L22_run_test,
|
|
|
|
|
SST25VF016B_run_test,
|
|
|
|
|
LIS302DL_run_test,
|
|
|
|
|
LIS302DL_run_test_dynamic,
|
|
|
|
|
MP45DT02_run_test,
|
|
|
|
|
LSM9DS1_test_accel,
|
|
|
|
|
LSM9DS1_test_magnet
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const void ((*cleanup_functions[])(void)) = {
|
|
|
|
|
void ((*cleanup_functions[])(void)) = {
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
PCA9685_cleanup,
|
|
|
|
|
NULL,
|
|
|
|
@@ -99,10 +91,29 @@ static const void ((*cleanup_functions[])(void)) = {
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
LSM9DS1_cleanup_accel,
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int delay_between_runs[] = {
|
|
|
|
|
250,
|
|
|
|
|
250,
|
|
|
|
|
-1,
|
|
|
|
|
-1,
|
|
|
|
|
-1,
|
|
|
|
|
-1,
|
|
|
|
|
-1,
|
|
|
|
|
200,
|
|
|
|
|
-1,
|
|
|
|
|
-1,
|
|
|
|
|
-1
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
size_t current_executor_id = 0;
|
|
|
|
|
|
|
|
|
|
size_t buttons_interrupt_enabled;
|
|
|
|
|
|
|
|
|
|
/* USER CODE END PV */
|
|
|
|
|
|
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
|
@@ -120,7 +131,67 @@ static void MX_I2S2_Init(void);
|
|
|
|
|
/* Private user code ---------------------------------------------------------*/
|
|
|
|
|
/* USER CODE BEGIN 0 */
|
|
|
|
|
|
|
|
|
|
static void button_init_and_test(void)
|
|
|
|
|
void switch_to_next_test(void)
|
|
|
|
|
{
|
|
|
|
|
current_executor_id += 1;
|
|
|
|
|
current_executor_id %= 11;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void buttons_switch_to_interrupt(void)
|
|
|
|
|
{
|
|
|
|
|
// save current executor ID
|
|
|
|
|
size_t tmp = current_executor_id;
|
|
|
|
|
|
|
|
|
|
// configure user button
|
|
|
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
|
|
|
|
|
|
HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
|
|
|
|
|
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
|
|
|
|
|
|
|
|
|
|
// configure SW5 (alternative advancing method)
|
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_8;
|
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
|
|
|
|
|
|
|
|
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
|
|
|
|
|
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
|
|
|
|
|
|
|
|
|
|
// restore current executor ID
|
|
|
|
|
current_executor_id = tmp;
|
|
|
|
|
|
|
|
|
|
// set interrupt mode flag
|
|
|
|
|
buttons_interrupt_enabled = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void buttons_switch_to_input(void)
|
|
|
|
|
{
|
|
|
|
|
// configure user button
|
|
|
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
|
|
|
|
|
|
HAL_NVIC_DisableIRQ(EXTI0_IRQn);
|
|
|
|
|
|
|
|
|
|
// configure SW5 (alternative input method)
|
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_8;
|
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
|
|
|
|
|
|
|
|
HAL_NVIC_DisableIRQ(EXTI9_5_IRQn);
|
|
|
|
|
|
|
|
|
|
// clear interrupt mode flag
|
|
|
|
|
buttons_interrupt_enabled = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void button_init_and_test(void)
|
|
|
|
|
{
|
|
|
|
|
// letting the buttons be tested
|
|
|
|
|
display_write_data_seq("Fill any bar:");
|
|
|
|
@@ -130,11 +201,11 @@ static void button_init_and_test(void)
|
|
|
|
|
size_t pressed_elements;
|
|
|
|
|
|
|
|
|
|
uint32_t sw_button_locations[5][2] = {
|
|
|
|
|
{(uint32_t) GPIOC, (uint32_t) GPIO_PIN_11},
|
|
|
|
|
{(uint32_t) GPIOA, (uint32_t) GPIO_PIN_15},
|
|
|
|
|
{(uint32_t) GPIOC, (uint32_t) GPIO_PIN_9},
|
|
|
|
|
{(uint32_t) GPIOC, (uint32_t) GPIO_PIN_6},
|
|
|
|
|
{(uint32_t) GPIOC, (uint32_t) GPIO_PIN_8}
|
|
|
|
|
{GPIOC, GPIO_PIN_11},
|
|
|
|
|
{GPIOA, GPIO_PIN_15},
|
|
|
|
|
{GPIOC, GPIO_PIN_9},
|
|
|
|
|
{GPIOC, GPIO_PIN_6},
|
|
|
|
|
{GPIOC, GPIO_PIN_8}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
@@ -172,16 +243,16 @@ static void button_init_and_test(void)
|
|
|
|
|
display_write_data_seq("Release buttons");
|
|
|
|
|
|
|
|
|
|
GPIOD->ODR = 0x1000;
|
|
|
|
|
HAL_Delay(300);
|
|
|
|
|
HAL_Delay(500);
|
|
|
|
|
GPIOD->ODR = 0x2000;
|
|
|
|
|
HAL_Delay(300);
|
|
|
|
|
HAL_Delay(500);
|
|
|
|
|
GPIOD->ODR = 0x4000;
|
|
|
|
|
HAL_Delay(300);
|
|
|
|
|
HAL_Delay(500);
|
|
|
|
|
GPIOD->ODR = 0x8000;
|
|
|
|
|
HAL_Delay(300);
|
|
|
|
|
HAL_Delay(500);
|
|
|
|
|
|
|
|
|
|
// waiting for all buttons to be released
|
|
|
|
|
WAIT_UNTIL_ALL_BUTTONS_RELEASED;
|
|
|
|
|
// waiting for control buttons to be released
|
|
|
|
|
WAIT_UNTIL_CB_RELEASED;
|
|
|
|
|
GPIOD->ODR = 0x0000;
|
|
|
|
|
HAL_Delay(200);
|
|
|
|
|
}
|
|
|
|
@@ -223,6 +294,7 @@ int main(void)
|
|
|
|
|
MX_TIM2_Init();
|
|
|
|
|
MX_I2S2_Init();
|
|
|
|
|
/* USER CODE BEGIN 2 */
|
|
|
|
|
buttons_interrupt_enabled = 0;
|
|
|
|
|
|
|
|
|
|
HAL_TIM_Base_Start(&htim2);
|
|
|
|
|
TIM2->CNT = 0;
|
|
|
|
@@ -238,7 +310,9 @@ int main(void)
|
|
|
|
|
size_t successful_tests = 0;
|
|
|
|
|
size_t failed_tests = 0;
|
|
|
|
|
|
|
|
|
|
for (display_current_frame = 1; display_current_frame < LEN(executors)+1; display_current_frame++)
|
|
|
|
|
//display_to_framebuffer();
|
|
|
|
|
|
|
|
|
|
for (display_current_frame = 1; display_current_frame < 12; display_current_frame++)
|
|
|
|
|
{
|
|
|
|
|
DISPLAY_CLEAR;
|
|
|
|
|
display_write_data_seq("Testing...");
|
|
|
|
@@ -287,43 +361,94 @@ int main(void)
|
|
|
|
|
|
|
|
|
|
display_to_direct();
|
|
|
|
|
|
|
|
|
|
/* USER CODE END 2 */
|
|
|
|
|
|
|
|
|
|
/* Infinite loop */
|
|
|
|
|
/* USER CODE BEGIN WHILE */
|
|
|
|
|
if (buttons_interrupt_enabled)
|
|
|
|
|
buttons_switch_to_input();
|
|
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
|
WAIT_UNTIL_ALL_BUTTONS_RELEASED;
|
|
|
|
|
// wait until all buttons are released
|
|
|
|
|
while (
|
|
|
|
|
(GPIOA->IDR & GPIO_PIN_0) ||
|
|
|
|
|
!(GPIOC->IDR & GPIO_PIN_11) ||
|
|
|
|
|
!(GPIOC->IDR & GPIO_PIN_8) ||
|
|
|
|
|
!(GPIOC->IDR & GPIO_PIN_9) ||
|
|
|
|
|
!(GPIOC->IDR & GPIO_PIN_6) ||
|
|
|
|
|
!(GPIOA->IDR & GPIO_PIN_15)
|
|
|
|
|
) { asm("nop"); }
|
|
|
|
|
|
|
|
|
|
display_load(display_current_frame);
|
|
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
|
// go to next report
|
|
|
|
|
if (UB || SWT1 || SWT5) {
|
|
|
|
|
if (
|
|
|
|
|
(GPIOA->IDR & GPIO_PIN_0) ||
|
|
|
|
|
!(GPIOC->IDR & GPIO_PIN_11) ||
|
|
|
|
|
!(GPIOC->IDR & GPIO_PIN_8)
|
|
|
|
|
) {
|
|
|
|
|
display_current_frame += 1;
|
|
|
|
|
display_current_frame %= LEN(executors)+1;
|
|
|
|
|
display_current_frame %= 12;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// go to previous report
|
|
|
|
|
else if (SWT3 || SWT4) {
|
|
|
|
|
else if (
|
|
|
|
|
!(GPIOC->IDR & GPIO_PIN_9) ||
|
|
|
|
|
!(GPIOC->IDR & GPIO_PIN_6)
|
|
|
|
|
) {
|
|
|
|
|
display_current_frame -= 1;
|
|
|
|
|
|
|
|
|
|
if ((int) display_current_frame == -1)
|
|
|
|
|
display_current_frame = LEN(executors);
|
|
|
|
|
if (display_current_frame == 0xFFFFFFFFU)
|
|
|
|
|
display_current_frame = 11;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// return to summary frame
|
|
|
|
|
else if (SWT2) {
|
|
|
|
|
else if (
|
|
|
|
|
!(GPIOA->IDR & GPIO_PIN_15)
|
|
|
|
|
) {
|
|
|
|
|
display_current_frame = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* USER CODE END 2 */
|
|
|
|
|
|
|
|
|
|
/* Infinite loop */
|
|
|
|
|
/* USER CODE BEGIN WHILE */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
if (delay_between_runs[current_executor_id] == -1 && buttons_interrupt_enabled)
|
|
|
|
|
buttons_switch_to_input();
|
|
|
|
|
else if (delay_between_runs[current_executor_id] != -1 && !buttons_interrupt_enabled)
|
|
|
|
|
buttons_switch_to_interrupt();
|
|
|
|
|
|
|
|
|
|
executors[current_executor_id]();
|
|
|
|
|
|
|
|
|
|
if (delay_between_runs[current_executor_id] == -1) {
|
|
|
|
|
WAIT_UNTIL_CB_PRESSED;
|
|
|
|
|
HAL_Delay(150);
|
|
|
|
|
GPIOD->BSRR = 0x1000;
|
|
|
|
|
|
|
|
|
|
WAIT_UNTIL_CB_RELEASED;
|
|
|
|
|
HAL_Delay(150);
|
|
|
|
|
GPIOD->BSRR = 0x1000 << 16;
|
|
|
|
|
|
|
|
|
|
if (cleanup_functions[current_executor_id])
|
|
|
|
|
cleanup_functions[current_executor_id]();
|
|
|
|
|
|
|
|
|
|
switch_to_next_test();
|
|
|
|
|
} else {
|
|
|
|
|
HAL_Delay(delay_between_runs[current_executor_id]);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
/* USER CODE END WHILE */
|
|
|
|
|
|
|
|
|
|
/* USER CODE BEGIN 3 */
|
|
|
|
|
}
|
|
|
|
|
//}
|
|
|
|
|
/* USER CODE END 3 */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|