Comments to source code

This commit is contained in:
Andreas Mieke 2018-04-03 17:18:28 +02:00
parent d109bae8d7
commit 9a18bd88f0
22 changed files with 286 additions and 122 deletions

View file

@ -16,38 +16,49 @@ char colors[COLORS][7] = {
void init_display(void)
{
// Init GPIOB and USART3 clocks
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
// Create gpio struct and fill it with default values
GPIO_InitTypeDef gpio;
GPIO_StructInit(&gpio);
// Set PB10 to alternate function push pull
gpio.GPIO_Mode = GPIO_Mode_AF_PP;
gpio.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOB, &gpio);
// Set PB11 to input floating
gpio.GPIO_Mode = GPIO_Mode_IN_FLOATING;
gpio.GPIO_Pin = GPIO_Pin_11;
GPIO_Init(GPIOB, &gpio);
// Create usart struct and set USART3 to 9600 baud
USART_InitTypeDef usart;
USART_StructInit(&usart);
usart.USART_BaudRate = 9600;
USART_Init(USART3, &usart);
// Init USART clock
USART_ClockInitTypeDef usartclock;
USART_ClockStructInit(&usartclock);
USART_ClockInit(USART3, &usartclock);
// Enable USART3
USART_Cmd(USART3, ENABLE);
}
void run_display(void)
{
// String to store command
char cmd[16], *cptr;
cptr = cmd;
// Fill string with every color from colors[]
sprintf(cmd, "cls %s\xFF\xFF\xFF", colors[i++]);
// If the last color is reached, begin again
if (i == COLORS) i = 0;
// Send character for character to USART3 (the display)
while(*cptr) {
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, *cptr++);
@ -56,12 +67,16 @@ void run_display(void)
void deinit_display(void)
{
// Reset command
char *cmd = "rest\xFF\xFF\xFF";
// Reset the display after the test finishes
while(*cmd) {
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, *cmd++);
}
// Wait till the last character is sent
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
// Then disable USART3 again
USART_Cmd(USART3, DISABLE);
USART_DeInit(USART3);
}