AMTS/Mieke/SW/MT/display.c

101 lines
2.7 KiB
C
Raw Normal View History

2018-04-03 15:32:24 +00:00
/*
Manufacturing tests for the new cortex minimal system
Copyright (C) 2018 Andreas Mieke
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2018-03-18 22:43:59 +00:00
#include "display.h"
#define COLORS 8
uint8_t i = 0;
char colors[COLORS][7] = {
"RED",
"BLUE",
"GRAY",
"BLACK",
"WHITE",
"GREEN",
"BROWN",
"YELLOW"
};
void init_display(void)
{
2018-04-03 15:18:28 +00:00
// Init GPIOB and USART3 clocks
2018-03-18 22:43:59 +00:00
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
2018-04-03 15:18:28 +00:00
// Create gpio struct and fill it with default values
2018-03-18 22:43:59 +00:00
GPIO_InitTypeDef gpio;
GPIO_StructInit(&gpio);
2018-04-03 15:18:28 +00:00
// Set PB10 to alternate function push pull
2018-03-18 22:43:59 +00:00
gpio.GPIO_Mode = GPIO_Mode_AF_PP;
gpio.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOB, &gpio);
2018-04-03 15:18:28 +00:00
// Set PB11 to input floating
2018-03-18 22:43:59 +00:00
gpio.GPIO_Mode = GPIO_Mode_IN_FLOATING;
gpio.GPIO_Pin = GPIO_Pin_11;
GPIO_Init(GPIOB, &gpio);
2018-04-03 15:18:28 +00:00
// Create usart struct and set USART3 to 9600 baud
2018-03-18 22:43:59 +00:00
USART_InitTypeDef usart;
USART_StructInit(&usart);
usart.USART_BaudRate = 9600;
USART_Init(USART3, &usart);
2018-04-03 15:18:28 +00:00
// Init USART clock
2018-03-18 22:43:59 +00:00
USART_ClockInitTypeDef usartclock;
USART_ClockStructInit(&usartclock);
USART_ClockInit(USART3, &usartclock);
2018-04-03 15:18:28 +00:00
// Enable USART3
2018-03-18 22:43:59 +00:00
USART_Cmd(USART3, ENABLE);
}
void run_display(void)
{
2018-04-03 15:18:28 +00:00
// String to store command
2018-03-18 22:43:59 +00:00
char cmd[16], *cptr;
cptr = cmd;
2018-04-03 15:18:28 +00:00
// Fill string with every color from colors[]
2018-03-18 22:43:59 +00:00
sprintf(cmd, "cls %s\xFF\xFF\xFF", colors[i++]);
2018-04-03 15:18:28 +00:00
// If the last color is reached, begin again
2018-03-18 22:43:59 +00:00
if (i == COLORS) i = 0;
2018-04-03 15:18:28 +00:00
// Send character for character to USART3 (the display)
2018-03-18 22:43:59 +00:00
while(*cptr) {
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, *cptr++);
}
}
void deinit_display(void)
{
2018-04-03 15:18:28 +00:00
// Reset command
2018-03-18 22:43:59 +00:00
char *cmd = "rest\xFF\xFF\xFF";
2018-04-03 15:18:28 +00:00
// Reset the display after the test finishes
2018-03-18 22:43:59 +00:00
while(*cmd) {
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, *cmd++);
}
2018-04-03 15:18:28 +00:00
// Wait till the last character is sent
2018-03-18 22:43:59 +00:00
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
2018-04-03 15:18:28 +00:00
// Then disable USART3 again
2018-03-18 22:43:59 +00:00
USART_Cmd(USART3, DISABLE);
USART_DeInit(USART3);
}