13 Commits

Author SHA1 Message Date
hasslesstech c9b90a679e [lcd] forbid writing outside of current framebuffer memory 2025-04-19 15:54:14 +03:00
hasslesstech ee3249beca [lcd] forbid writing to non-existant framebuffers 2025-04-19 15:04:15 +03:00
hasslesstech cc32a3092a [main] add macros for checking specific buttons 2025-04-19 14:52:22 +03:00
hasslesstech e65c4d612c [main] large code cleanup 2025-04-19 14:52:22 +03:00
hasslesstech 7940c95b23 [main] fix: cast wrongly converted integer back into the pointer to remove warning 2025-04-19 14:52:22 +03:00
hasslesstech 5bbbc9fe44 [main] enhancement: remove delay between running tests 2025-04-19 14:52:22 +03:00
hasslesstech 4c9c1ff2c8 [PCA9685] remove OUT ENABLED label as it is no longer used in interactive tests 2025-04-19 14:52:22 +03:00
hasslesstech 0eb025d3d4 add new UI for testing phase, update modules to indicate success or failure in the return value 2025-04-19 14:52:22 +03:00
hasslesstech 87eb642adc record change in .cproject which seems impossible to revert 2025-04-19 14:52:22 +03:00
hasslesstech 5c9846fce3 [main] add simple navigation between test reports 2025-04-19 14:52:22 +03:00
hasslesstech 063ed8bb51 [lcd] fix: add display_load prototype 2025-04-19 14:52:22 +03:00
hasslesstech 3ccc0ca0f3 [lcd] add support for operating on virtual framebuffers
Current implementation contains full support for:
- transparent switching between direct and framebuffer rendering modes
- writing characters to framebuffers
- loading frame from memory to physical display

As well as partial support for instruction writes including:
- resetting the display (clears memory, sets cursor at 0:0, switches to increment mode)
- switching between increment/decrement modes
- setting cursor position
2025-04-19 14:52:22 +03:00
hasslesstech 9370ddbadd [PCA9685] fix: add HAL_OK case to remove warning 2025-04-14 20:24:29 +03:00
4 changed files with 49 additions and 168 deletions
+3 -1
View File
@@ -40,6 +40,8 @@ int PCA9685_run_test(void)
display_write_data_seq("/5 "); display_write_data_seq("/5 ");
switch (op_result) { switch (op_result) {
case HAL_OK:
break;
case HAL_ERROR: case HAL_ERROR:
display_write_data_seq("ERROR"); display_write_data_seq("ERROR");
break; break;
@@ -70,7 +72,7 @@ int PCA9685_run_test(void)
return 1; return 1;
} else { } else {
DISPLAY_SET_CURSOR(1, 1); DISPLAY_SET_CURSOR(1, 1);
display_write_data_seq("OK OUT ENABLED"); display_write_data_seq("OK");
return 0; return 0;
} }
+6
View File
@@ -136,6 +136,12 @@ static void display_write_data_byte_direct(uint8_t code)
static void display_write_data_byte_framebuffer(uint8_t code) static void display_write_data_byte_framebuffer(uint8_t code)
{ {
if (display_current_frame >= DISPLAY_FRAMES_AVAILABLE)
return;
if (((int) des.cursor_offset >= 32) || ((int) des.cursor_offset < 0))
return;
display_framebuffer[16*2*display_current_frame + des.cursor_offset] = (char) code; display_framebuffer[16*2*display_current_frame + des.cursor_offset] = (char) code;
des.cursor_offset += des.next ? -1 : 1; des.cursor_offset += des.next ? -1 : 1;
} }
+38 -165
View File
@@ -46,6 +46,17 @@
#define WAIT_UNTIL_CB_PRESSED while (!HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0) && HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_8)) #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 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 */ /* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/
@@ -68,22 +79,19 @@ extern size_t display_current_frame;
/* USER CODE BEGIN PV */ /* USER CODE BEGIN PV */
int ((*executors[])(void)) = { static const int ((*executors[])(void)) = {
DNI_show_celsius, DNI_show_celsius,
DNI_show_fahrenheit,
PCA9685_run_test, PCA9685_run_test,
EEPROM_24AA02E48_run_test, EEPROM_24AA02E48_run_test,
CS43L22_run_test, CS43L22_run_test,
SST25VF016B_run_test, SST25VF016B_run_test,
LIS302DL_run_test, LIS302DL_run_test,
LIS302DL_run_test_dynamic,
MP45DT02_run_test, MP45DT02_run_test,
LSM9DS1_test_accel, LSM9DS1_test_accel,
LSM9DS1_test_magnet LSM9DS1_test_magnet
}; };
void ((*cleanup_functions[])(void)) = { static const void ((*cleanup_functions[])(void)) = {
NULL,
NULL, NULL,
PCA9685_cleanup, PCA9685_cleanup,
NULL, NULL,
@@ -91,29 +99,10 @@ void ((*cleanup_functions[])(void)) = {
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL,
LSM9DS1_cleanup_accel, LSM9DS1_cleanup_accel,
NULL 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 */ /* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/
@@ -131,67 +120,7 @@ static void MX_I2S2_Init(void);
/* Private user code ---------------------------------------------------------*/ /* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */ /* USER CODE BEGIN 0 */
void switch_to_next_test(void) static void button_init_and_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 // letting the buttons be tested
display_write_data_seq("Fill any bar:"); display_write_data_seq("Fill any bar:");
@@ -201,11 +130,11 @@ void button_init_and_test(void)
size_t pressed_elements; size_t pressed_elements;
uint32_t sw_button_locations[5][2] = { uint32_t sw_button_locations[5][2] = {
{GPIOC, GPIO_PIN_11}, {(uint32_t) GPIOC, (uint32_t) GPIO_PIN_11},
{GPIOA, GPIO_PIN_15}, {(uint32_t) GPIOA, (uint32_t) GPIO_PIN_15},
{GPIOC, GPIO_PIN_9}, {(uint32_t) GPIOC, (uint32_t) GPIO_PIN_9},
{GPIOC, GPIO_PIN_6}, {(uint32_t) GPIOC, (uint32_t) GPIO_PIN_6},
{GPIOC, GPIO_PIN_8} {(uint32_t) GPIOC, (uint32_t) GPIO_PIN_8}
}; };
do { do {
@@ -226,7 +155,7 @@ void button_init_and_test(void)
for (size_t i = 0; i < 5; i++) { for (size_t i = 0; i < 5; i++) {
pressed_elements >>= 1; pressed_elements >>= 1;
size_t input = !HAL_GPIO_ReadPin(sw_button_locations[i][0], sw_button_locations[i][1]); size_t input = !HAL_GPIO_ReadPin((GPIO_TypeDef *) sw_button_locations[i][0], sw_button_locations[i][1]);
if (input) { if (input) {
pressed_elements |= 0x20; pressed_elements |= 0x20;
@@ -243,16 +172,16 @@ void button_init_and_test(void)
display_write_data_seq("Release buttons"); display_write_data_seq("Release buttons");
GPIOD->ODR = 0x1000; GPIOD->ODR = 0x1000;
HAL_Delay(500); HAL_Delay(300);
GPIOD->ODR = 0x2000; GPIOD->ODR = 0x2000;
HAL_Delay(500); HAL_Delay(300);
GPIOD->ODR = 0x4000; GPIOD->ODR = 0x4000;
HAL_Delay(500); HAL_Delay(300);
GPIOD->ODR = 0x8000; GPIOD->ODR = 0x8000;
HAL_Delay(500); HAL_Delay(300);
// waiting for control buttons to be released // waiting for all buttons to be released
WAIT_UNTIL_CB_RELEASED; WAIT_UNTIL_ALL_BUTTONS_RELEASED;
GPIOD->ODR = 0x0000; GPIOD->ODR = 0x0000;
HAL_Delay(200); HAL_Delay(200);
} }
@@ -294,7 +223,6 @@ int main(void)
MX_TIM2_Init(); MX_TIM2_Init();
MX_I2S2_Init(); MX_I2S2_Init();
/* USER CODE BEGIN 2 */ /* USER CODE BEGIN 2 */
buttons_interrupt_enabled = 0;
HAL_TIM_Base_Start(&htim2); HAL_TIM_Base_Start(&htim2);
TIM2->CNT = 0; TIM2->CNT = 0;
@@ -310,9 +238,7 @@ int main(void)
size_t successful_tests = 0; size_t successful_tests = 0;
size_t failed_tests = 0; size_t failed_tests = 0;
//display_to_framebuffer(); for (display_current_frame = 1; display_current_frame < LEN(executors)+1; display_current_frame++)
for (display_current_frame = 1; display_current_frame < 12; display_current_frame++)
{ {
DISPLAY_CLEAR; DISPLAY_CLEAR;
display_write_data_seq("Testing..."); display_write_data_seq("Testing...");
@@ -340,8 +266,6 @@ int main(void)
cleanup_functions[display_current_frame-1](); cleanup_functions[display_current_frame-1]();
display_to_direct(); display_to_direct();
HAL_Delay(150);
} }
// render final result to first framebuffer // render final result to first framebuffer
@@ -363,94 +287,43 @@ int main(void)
display_to_direct(); display_to_direct();
/* USER CODE END 2 */
if (buttons_interrupt_enabled) /* Infinite loop */
buttons_switch_to_input(); /* USER CODE BEGIN WHILE */
while (1) { while (1) {
// wait until all buttons are released WAIT_UNTIL_ALL_BUTTONS_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); display_load(display_current_frame);
while (1) { while (1) {
// go to next report // go to next report
if ( if (UB || SWT1 || SWT5) {
(GPIOA->IDR & GPIO_PIN_0) ||
!(GPIOC->IDR & GPIO_PIN_11) ||
!(GPIOC->IDR & GPIO_PIN_8)
) {
display_current_frame += 1; display_current_frame += 1;
display_current_frame %= 12; display_current_frame %= LEN(executors)+1;
break; break;
} }
// go to previous report // go to previous report
else if ( else if (SWT3 || SWT4) {
!(GPIOC->IDR & GPIO_PIN_9) ||
!(GPIOC->IDR & GPIO_PIN_6)
) {
display_current_frame -= 1; display_current_frame -= 1;
if (display_current_frame == 0xFFFFFFFFU) if ((int) display_current_frame == -1)
display_current_frame = 11; display_current_frame = LEN(executors);
break; break;
} }
// return to summary frame // return to summary frame
else if ( else if (SWT2) {
!(GPIOA->IDR & GPIO_PIN_15)
) {
display_current_frame = 0; display_current_frame = 0;
break; 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 END WHILE */
/* USER CODE BEGIN 3 */ /* USER CODE BEGIN 3 */
//} }
/* USER CODE END 3 */ /* USER CODE END 3 */
} }
+2 -2
View File
@@ -204,7 +204,7 @@ void EXTI0_IRQHandler(void)
{ {
GPIOD->ODR = 0x1000; GPIOD->ODR = 0x1000;
switch_to_next_test(); //switch_to_next_test();
for (int i = 300000; i > 0; i--) asm("nop"); for (int i = 300000; i > 0; i--) asm("nop");
@@ -217,7 +217,7 @@ void EXTI9_5_IRQHandler(void)
{ {
GPIOD->ODR = 0x1000; GPIOD->ODR = 0x1000;
switch_to_next_test(); //switch_to_next_test();
for (int i = 300000; i > 0; i--) asm("nop"); for (int i = 300000; i > 0; i--) asm("nop");