Compare commits
8 Commits
107a454051
...
20d3385b51
Author | SHA1 | Date | |
---|---|---|---|
20d3385b51 | |||
5554763ff4 | |||
c107fcd2d6 | |||
5015163522 | |||
00f3cb644d | |||
f2b92d6451 | |||
0807fb75ed | |||
3766ddfdc1 |
@ -150,7 +150,7 @@
|
||||
</toolChain>
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
|
||||
<entry excluding="Src/mock_lcd.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
|
@ -7,6 +7,8 @@
|
||||
#define DISPLAY_RW ((uint16_t) (0x1U << 10))
|
||||
#define DISPLAY_ENA ((uint16_t) (0x1U << 11))
|
||||
|
||||
#define DISPLAY_FRAMES_AVAILABLE 14
|
||||
|
||||
#define DISPLAY_POLL_UNTIL_READY do { while (display_read_status() & 0x80) {} } while (0)
|
||||
|
||||
#define DISPLAY_SET_INCREMENT do { display_write_instruction_byte(0x06); } while (0)
|
||||
@ -16,11 +18,17 @@
|
||||
|
||||
#define DISPLAY_CLEAR do { display_write_instruction_byte(0x01); } while (0)
|
||||
|
||||
struct Display_emu_state {
|
||||
size_t cursor_offset:5;
|
||||
size_t next:1;
|
||||
};
|
||||
|
||||
void display_init(void);
|
||||
uint8_t display_read_status(void);
|
||||
void display_write_instruction_byte(uint8_t code);
|
||||
void display_write_data_byte(uint8_t code);
|
||||
void display_write_data_seq(char *codes);
|
||||
void display_to_framebuffer(void);
|
||||
void display_to_direct(void);
|
||||
void display_load(uint32_t frame_no);
|
||||
|
||||
#endif
|
||||
|
@ -32,6 +32,8 @@ extern "C" {
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
@ -32,6 +32,8 @@ void EEPROM_24AA02E48_run_test(void)
|
||||
display_write_data_seq("/5 ");
|
||||
|
||||
switch (op_result) {
|
||||
case HAL_OK:
|
||||
break;
|
||||
case HAL_ERROR:
|
||||
display_write_data_seq("ERROR");
|
||||
break;
|
||||
@ -64,6 +66,8 @@ void EEPROM_24AA02E48_run_test(void)
|
||||
display_write_data_seq("/5 ");
|
||||
|
||||
switch (op_result) {
|
||||
case HAL_OK:
|
||||
break;
|
||||
case HAL_ERROR:
|
||||
display_write_data_seq("ERROR");
|
||||
break;
|
||||
@ -89,10 +93,10 @@ void EEPROM_24AA02E48_run_test(void)
|
||||
display_write_data_byte('0' + err_count / 10 % 10);
|
||||
display_write_data_byte('0' + err_count % 10);
|
||||
display_write_data_seq("E ");
|
||||
display_write_data_seq(data_buffer);
|
||||
display_write_data_seq((char *) data_buffer);
|
||||
} else {
|
||||
DISPLAY_SET_CURSOR(1, 1);
|
||||
display_write_data_seq("OK ");
|
||||
display_write_data_seq(data_buffer);
|
||||
display_write_data_seq((char *) data_buffer);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ void CS43L22_run_test(void)
|
||||
display_write_data_seq("/5 ");
|
||||
|
||||
switch (op_result) {
|
||||
case HAL_OK:
|
||||
break;
|
||||
case HAL_ERROR:
|
||||
display_write_data_seq("ERROR");
|
||||
break;
|
||||
|
@ -43,6 +43,8 @@ static void print_error_message(HAL_StatusTypeDef result, size_t *err_count, siz
|
||||
display_write_data_seq("/5 ");
|
||||
|
||||
switch (result) {
|
||||
case HAL_OK:
|
||||
break;
|
||||
case HAL_ERROR:
|
||||
display_write_data_seq("ERROR");
|
||||
break;
|
||||
|
@ -3,8 +3,8 @@
|
||||
#include "lcd.h"
|
||||
|
||||
#define FAILSAFE_PRE_OP for (size_t t = 0; t < 5; t++) {
|
||||
#define FAILSAFE_POST_OP_ACCEL(prefix) if (op_result) print_error_accel(op_result, err_count, t, prefix); else break; }
|
||||
#define FAILSAFE_POST_OP_MAGNET(prefix) if (op_result) print_error_magnet(op_result, err_count, t, prefix); else break; }
|
||||
#define FAILSAFE_POST_OP_ACCEL(prefix) if (op_result) print_error_accel(op_result, &err_count, t, prefix); else break; }
|
||||
#define FAILSAFE_POST_OP_MAGNET(prefix) if (op_result) print_error_magnet(op_result, &err_count, t, prefix); else break; }
|
||||
|
||||
extern I2C_HandleTypeDef hi2c1;
|
||||
|
||||
@ -20,6 +20,8 @@ static void print_error_message(HAL_StatusTypeDef result, size_t *err_count, siz
|
||||
display_write_data_seq("/5 ");
|
||||
|
||||
switch (result) {
|
||||
case HAL_OK:
|
||||
break;
|
||||
case HAL_ERROR:
|
||||
display_write_data_seq("ERROR");
|
||||
break;
|
||||
@ -110,12 +112,12 @@ void LSM9DS1_test_magnet(void)
|
||||
buffer[0] = 0x28;
|
||||
FAILSAFE_PRE_OP;
|
||||
op_result = HAL_I2C_Master_Transmit(&hi2c1, 0x3C, buffer, 1, 1000);
|
||||
FAILSAFE_POST_OP_ACCEL("A");
|
||||
FAILSAFE_POST_OP_MAGNET("A");
|
||||
|
||||
// read from registers sequentially
|
||||
FAILSAFE_PRE_OP;
|
||||
op_result = HAL_I2C_Master_Receive(&hi2c1, 0x3D, buffer, 6, 1000);
|
||||
FAILSAFE_POST_OP_ACCEL("R");
|
||||
FAILSAFE_POST_OP_MAGNET("R");
|
||||
|
||||
if (!err_count) {
|
||||
DISPLAY_SET_CURSOR(1, 1);
|
||||
|
108
Core/Src/lcd.c
108
Core/Src/lcd.c
@ -2,22 +2,45 @@
|
||||
#include "lcd.h"
|
||||
#include "generic_macros.h"
|
||||
|
||||
static char display_framebuffer[16*2*DISPLAY_FRAMES_AVAILABLE];
|
||||
size_t display_current_frame;
|
||||
static size_t display_framebuffer_mode;
|
||||
|
||||
static struct Display_emu_state des;
|
||||
|
||||
void display_init(void)
|
||||
{
|
||||
// prepare virtual framebuffer
|
||||
display_current_frame = 0;
|
||||
display_framebuffer_mode = 0;
|
||||
des.cursor_offset = 0;
|
||||
des.next = 0;
|
||||
memset(display_framebuffer, 0x20, 16*2*DISPLAY_FRAMES_AVAILABLE);
|
||||
|
||||
// switch to 4-bit 2-line mode
|
||||
display_write_instruction_byte(0x28);
|
||||
display_write_instruction_byte(0x28);
|
||||
|
||||
// clear display
|
||||
display_write_instruction_byte(0x01);
|
||||
// clear display
|
||||
display_write_instruction_byte(0x01);
|
||||
|
||||
// enable display
|
||||
display_write_instruction_byte(0x0C);
|
||||
// enable display
|
||||
display_write_instruction_byte(0x0C);
|
||||
|
||||
// move cursor to first line
|
||||
display_write_instruction_byte(0x80);
|
||||
// move cursor to first line
|
||||
display_write_instruction_byte(0x80);
|
||||
}
|
||||
|
||||
uint8_t display_read_status(void)
|
||||
void display_to_framebuffer(void)
|
||||
{
|
||||
display_framebuffer_mode = 1;
|
||||
}
|
||||
|
||||
void display_to_direct(void)
|
||||
{
|
||||
display_framebuffer_mode = 0;
|
||||
}
|
||||
|
||||
static uint8_t display_read_status(void)
|
||||
{
|
||||
// make sure GPIOE is in correct mode
|
||||
GPIOE->MODER = 0x00504000;
|
||||
@ -43,7 +66,7 @@ uint8_t display_read_status(void)
|
||||
return status;
|
||||
}
|
||||
|
||||
void display_write_instruction_byte(uint8_t code)
|
||||
static void display_write_instruction_byte_direct(uint8_t code)
|
||||
{
|
||||
DISPLAY_POLL_UNTIL_READY;
|
||||
|
||||
@ -62,7 +85,37 @@ void display_write_instruction_byte(uint8_t code)
|
||||
GPIOE->BSRR = (DISPLAY_ENA << 16);
|
||||
}
|
||||
|
||||
void display_write_data_byte(uint8_t code)
|
||||
static void display_write_instruction_byte_framebuffer(uint8_t code)
|
||||
{
|
||||
// emulate physical display behavior on receiving instructions
|
||||
if (code & 0x80) {
|
||||
// decode new cursor offset
|
||||
size_t offset = ((code & 0x40) >> 2) | (code & 0xF);
|
||||
des.cursor_offset = offset;
|
||||
} else if (code == 0x01) {
|
||||
// reset screen
|
||||
memset(&(display_framebuffer[16*2*display_current_frame]), 0x20, 16*2);
|
||||
des.cursor_offset = 0;
|
||||
des.next = 0;
|
||||
} else if (code == 0x06) {
|
||||
// set increment mode
|
||||
des.next = 0;
|
||||
} else if (code == 0x04) {
|
||||
// set decrement mode
|
||||
des.next = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void display_write_instruction_byte(uint8_t code)
|
||||
{
|
||||
if (display_framebuffer_mode) {
|
||||
display_write_instruction_byte_framebuffer(code);
|
||||
} else {
|
||||
display_write_instruction_byte_direct(code);
|
||||
}
|
||||
}
|
||||
|
||||
static void display_write_data_byte_direct(uint8_t code)
|
||||
{
|
||||
DISPLAY_POLL_UNTIL_READY;
|
||||
|
||||
@ -81,12 +134,45 @@ void display_write_data_byte(uint8_t code)
|
||||
GPIOE->BSRR = DISPLAY_ENA << 16;
|
||||
}
|
||||
|
||||
static void display_write_data_byte_framebuffer(uint8_t code)
|
||||
{
|
||||
display_framebuffer[16*2*display_current_frame + des.cursor_offset] = (char) code;
|
||||
des.cursor_offset += des.next ? -1 : 1;
|
||||
}
|
||||
|
||||
void display_write_data_byte(uint8_t code)
|
||||
{
|
||||
if (display_framebuffer_mode) {
|
||||
display_write_data_byte_framebuffer(code);
|
||||
} else {
|
||||
display_write_data_byte_direct(code);
|
||||
}
|
||||
}
|
||||
|
||||
void display_write_data_seq(char *codes)
|
||||
{
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
if (codes[i] != 0)
|
||||
if (codes[i])
|
||||
display_write_data_byte(codes[i]);
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void display_load(uint32_t frame_no)
|
||||
{
|
||||
if (display_framebuffer_mode)
|
||||
return;
|
||||
|
||||
DISPLAY_CLEAR;
|
||||
|
||||
for (uint32_t i = 0; i < 16; i++) {
|
||||
display_write_data_byte_direct(display_framebuffer[16*2*display_current_frame + i]);
|
||||
}
|
||||
|
||||
DISPLAY_SET_CURSOR(1, 0);
|
||||
|
||||
for (uint32_t i = 0; i < 16; i++) {
|
||||
display_write_data_byte_direct(display_framebuffer[16*2*display_current_frame + i + 16]);
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,6 @@
|
||||
#include "CS43L22.h"
|
||||
#include "SST25VF016B.h"
|
||||
#include "LIS302DL.h"
|
||||
#include "DHT11.h"
|
||||
#include "MP45DT02.h"
|
||||
#include "LSM9DS1.h"
|
||||
|
||||
@ -65,6 +64,8 @@ SPI_HandleTypeDef hspi1;
|
||||
|
||||
TIM_HandleTypeDef htim2;
|
||||
|
||||
extern size_t display_current_frame;
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
void ((*executors[])(void)) = {
|
||||
@ -305,10 +306,70 @@ int main(void)
|
||||
GPIOD->ODR = 0xF000;
|
||||
button_init_and_test();
|
||||
|
||||
// perform all tests
|
||||
display_to_framebuffer();
|
||||
|
||||
for (display_current_frame = 0; display_current_frame < 11; display_current_frame++)
|
||||
{
|
||||
executors[display_current_frame]();
|
||||
}
|
||||
|
||||
display_to_direct();
|
||||
|
||||
display_current_frame = 0;
|
||||
|
||||
if (buttons_interrupt_enabled)
|
||||
buttons_switch_to_input();
|
||||
|
||||
while (1) {
|
||||
// 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 (
|
||||
(GPIOA->IDR & GPIO_PIN_0) ||
|
||||
!(GPIOC->IDR & GPIO_PIN_11) ||
|
||||
!(GPIOC->IDR & GPIO_PIN_8)
|
||||
) {
|
||||
display_current_frame += 1;
|
||||
break;
|
||||
}
|
||||
|
||||
// go to previous report
|
||||
else if (
|
||||
!(GPIOC->IDR & GPIO_PIN_9) ||
|
||||
!(GPIOC->IDR & GPIO_PIN_6)
|
||||
) {
|
||||
display_current_frame -= 1;
|
||||
break;
|
||||
}
|
||||
|
||||
// execute this test live
|
||||
else if (
|
||||
!(GPIOA->IDR & GPIO_PIN_15)
|
||||
) {
|
||||
// not implemented
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
|
||||
/*
|
||||
while (1)
|
||||
{
|
||||
if (delay_between_runs[current_executor_id] == -1 && buttons_interrupt_enabled)
|
||||
@ -334,10 +395,11 @@ int main(void)
|
||||
} else {
|
||||
HAL_Delay(delay_between_runs[current_executor_id]);
|
||||
}
|
||||
*/
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
}
|
||||
//}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
C_SRCS += \
|
||||
../Core/Src/24AA02E48.c \
|
||||
../Core/Src/CS43L22.c \
|
||||
../Core/Src/DHT11.c \
|
||||
../Core/Src/DNI.c \
|
||||
../Core/Src/LIS302DL.c \
|
||||
../Core/Src/LSM9DS1.c \
|
||||
@ -25,7 +24,6 @@ C_SRCS += \
|
||||
OBJS += \
|
||||
./Core/Src/24AA02E48.o \
|
||||
./Core/Src/CS43L22.o \
|
||||
./Core/Src/DHT11.o \
|
||||
./Core/Src/DNI.o \
|
||||
./Core/Src/LIS302DL.o \
|
||||
./Core/Src/LSM9DS1.o \
|
||||
@ -43,7 +41,6 @@ OBJS += \
|
||||
C_DEPS += \
|
||||
./Core/Src/24AA02E48.d \
|
||||
./Core/Src/CS43L22.d \
|
||||
./Core/Src/DHT11.d \
|
||||
./Core/Src/DNI.d \
|
||||
./Core/Src/LIS302DL.d \
|
||||
./Core/Src/LSM9DS1.d \
|
||||
@ -66,7 +63,7 @@ Core/Src/%.o Core/Src/%.su Core/Src/%.cyclo: ../Core/Src/%.c Core/Src/subdir.mk
|
||||
clean: clean-Core-2f-Src
|
||||
|
||||
clean-Core-2f-Src:
|
||||
-$(RM) ./Core/Src/24AA02E48.cyclo ./Core/Src/24AA02E48.d ./Core/Src/24AA02E48.o ./Core/Src/24AA02E48.su ./Core/Src/CS43L22.cyclo ./Core/Src/CS43L22.d ./Core/Src/CS43L22.o ./Core/Src/CS43L22.su ./Core/Src/DHT11.cyclo ./Core/Src/DHT11.d ./Core/Src/DHT11.o ./Core/Src/DHT11.su ./Core/Src/DNI.cyclo ./Core/Src/DNI.d ./Core/Src/DNI.o ./Core/Src/DNI.su ./Core/Src/LIS302DL.cyclo ./Core/Src/LIS302DL.d ./Core/Src/LIS302DL.o ./Core/Src/LIS302DL.su ./Core/Src/LSM9DS1.cyclo ./Core/Src/LSM9DS1.d ./Core/Src/LSM9DS1.o ./Core/Src/LSM9DS1.su ./Core/Src/MP45DT02.cyclo ./Core/Src/MP45DT02.d ./Core/Src/MP45DT02.o ./Core/Src/MP45DT02.su ./Core/Src/PCA9685.cyclo ./Core/Src/PCA9685.d ./Core/Src/PCA9685.o ./Core/Src/PCA9685.su ./Core/Src/SST25VF016B.cyclo ./Core/Src/SST25VF016B.d ./Core/Src/SST25VF016B.o ./Core/Src/SST25VF016B.su ./Core/Src/lcd.cyclo ./Core/Src/lcd.d ./Core/Src/lcd.o ./Core/Src/lcd.su ./Core/Src/main.cyclo ./Core/Src/main.d ./Core/Src/main.o ./Core/Src/main.su ./Core/Src/stm32f4xx_hal_msp.cyclo ./Core/Src/stm32f4xx_hal_msp.d ./Core/Src/stm32f4xx_hal_msp.o ./Core/Src/stm32f4xx_hal_msp.su ./Core/Src/stm32f4xx_it.cyclo ./Core/Src/stm32f4xx_it.d ./Core/Src/stm32f4xx_it.o ./Core/Src/stm32f4xx_it.su ./Core/Src/syscalls.cyclo ./Core/Src/syscalls.d ./Core/Src/syscalls.o ./Core/Src/syscalls.su ./Core/Src/sysmem.cyclo ./Core/Src/sysmem.d ./Core/Src/sysmem.o ./Core/Src/sysmem.su ./Core/Src/system_stm32f4xx.cyclo ./Core/Src/system_stm32f4xx.d ./Core/Src/system_stm32f4xx.o ./Core/Src/system_stm32f4xx.su
|
||||
-$(RM) ./Core/Src/24AA02E48.cyclo ./Core/Src/24AA02E48.d ./Core/Src/24AA02E48.o ./Core/Src/24AA02E48.su ./Core/Src/CS43L22.cyclo ./Core/Src/CS43L22.d ./Core/Src/CS43L22.o ./Core/Src/CS43L22.su ./Core/Src/DNI.cyclo ./Core/Src/DNI.d ./Core/Src/DNI.o ./Core/Src/DNI.su ./Core/Src/LIS302DL.cyclo ./Core/Src/LIS302DL.d ./Core/Src/LIS302DL.o ./Core/Src/LIS302DL.su ./Core/Src/LSM9DS1.cyclo ./Core/Src/LSM9DS1.d ./Core/Src/LSM9DS1.o ./Core/Src/LSM9DS1.su ./Core/Src/MP45DT02.cyclo ./Core/Src/MP45DT02.d ./Core/Src/MP45DT02.o ./Core/Src/MP45DT02.su ./Core/Src/PCA9685.cyclo ./Core/Src/PCA9685.d ./Core/Src/PCA9685.o ./Core/Src/PCA9685.su ./Core/Src/SST25VF016B.cyclo ./Core/Src/SST25VF016B.d ./Core/Src/SST25VF016B.o ./Core/Src/SST25VF016B.su ./Core/Src/lcd.cyclo ./Core/Src/lcd.d ./Core/Src/lcd.o ./Core/Src/lcd.su ./Core/Src/main.cyclo ./Core/Src/main.d ./Core/Src/main.o ./Core/Src/main.su ./Core/Src/stm32f4xx_hal_msp.cyclo ./Core/Src/stm32f4xx_hal_msp.d ./Core/Src/stm32f4xx_hal_msp.o ./Core/Src/stm32f4xx_hal_msp.su ./Core/Src/stm32f4xx_it.cyclo ./Core/Src/stm32f4xx_it.d ./Core/Src/stm32f4xx_it.o ./Core/Src/stm32f4xx_it.su ./Core/Src/syscalls.cyclo ./Core/Src/syscalls.d ./Core/Src/syscalls.o ./Core/Src/syscalls.su ./Core/Src/sysmem.cyclo ./Core/Src/sysmem.d ./Core/Src/sysmem.o ./Core/Src/sysmem.su ./Core/Src/system_stm32f4xx.cyclo ./Core/Src/system_stm32f4xx.d ./Core/Src/system_stm32f4xx.o ./Core/Src/system_stm32f4xx.su
|
||||
|
||||
.PHONY: clean-Core-2f-Src
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
"./Core/Src/24AA02E48.o"
|
||||
"./Core/Src/CS43L22.o"
|
||||
"./Core/Src/DHT11.o"
|
||||
"./Core/Src/DNI.o"
|
||||
"./Core/Src/LIS302DL.o"
|
||||
"./Core/Src/LSM9DS1.o"
|
||||
|
Loading…
x
Reference in New Issue
Block a user