/*
 * lcd_clock.c
 *
 *  Created on: Sep 29, 2023
 *      Author: user
 */

#include "lcd_clock.h"
#include "lcd.h"

void clear_first_digit()
{
	HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG6_BIT_SHIFT),
			0 << LCD_SEG6_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG6_BIT_SHIFT),
			0 << LCD_SEG6_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG6_BIT_SHIFT),
			0 << LCD_SEG6_BIT_SHIFT);
}

void draw_first_digit(uint8_t digit)
{
	clear_first_digit();
	if ((digit == 1) || (digit == 2))
	{
		switch (digit)
		{
		case 1:
			HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG6_BIT_SHIFT),
					1 << LCD_SEG6_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG6_BIT_SHIFT),
					1 << LCD_SEG6_BIT_SHIFT);
			break;
		case 2:
			HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG6_BIT_SHIFT),
					1 << LCD_SEG6_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG6_BIT_SHIFT),
					1 << LCD_SEG6_BIT_SHIFT);
			break;
		default:
			;
		}
	}
}

void clear_second_digit()
{
	HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
			0 << LCD_SEG4_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
			0 << LCD_SEG5_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
			0 << LCD_SEG4_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
			0 << LCD_SEG5_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
			0 << LCD_SEG4_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
			0 << LCD_SEG5_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM3_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
			0 << LCD_SEG4_BIT_SHIFT);
}

void draw_second_digit(uint8_t digit)
{
	clear_second_digit();
	if (digit < 10)
	{
		switch (digit)
		{
		case 0:
			HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
					1 << LCD_SEG5_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
					1 << LCD_SEG5_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM3_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			break;
		case 1:

			HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			break;
		case 2:
			HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
					1 << LCD_SEG5_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
					1 << LCD_SEG5_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM3_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			break;
		case 3:
			HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
					1 << LCD_SEG5_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM3_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			break;
		case 4:
			HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
					1 << LCD_SEG5_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
					1 << LCD_SEG5_BIT_SHIFT);
			break;
		case 5:
			HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
					1 << LCD_SEG5_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
					1 << LCD_SEG5_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM3_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			break;
		case 6:
			HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
					1 << LCD_SEG5_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
					1 << LCD_SEG5_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM3_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
					1 << LCD_SEG5_BIT_SHIFT);
			break;
		case 7:

			HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM3_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			break;
		case 8:
			HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
					1 << LCD_SEG5_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
					1 << LCD_SEG5_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
					1 << LCD_SEG5_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM3_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			break;
		case 9:
			HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
					1 << LCD_SEG5_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG5_BIT_SHIFT),
					1 << LCD_SEG5_BIT_SHIFT);
			HAL_LCD_Write(&hlcd, LCD_COM3_REGISTER, ~(1 << LCD_SEG4_BIT_SHIFT),
					1 << LCD_SEG4_BIT_SHIFT);
			break;
		default:
			;
		}
	}
}

void draw_bu(void)
{
	HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG0_BIT_SHIFT),
			1 << LCD_SEG0_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG0_BIT_SHIFT),
			1 << LCD_SEG0_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG1_BIT_SHIFT),
			1 << LCD_SEG1_BIT_SHIFT);

	HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG2_BIT_SHIFT),
			1 << LCD_SEG2_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG3_BIT_SHIFT),
			1 << LCD_SEG3_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG2_BIT_SHIFT),
			1 << LCD_SEG2_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG3_BIT_SHIFT),
			1 << LCD_SEG3_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG3_BIT_SHIFT),
			1 << LCD_SEG3_BIT_SHIFT);
}

void draw_deg_c(void)
{
	HAL_LCD_Write(&hlcd, LCD_COM3_REGISTER, ~(1 << LCD_SEG2_BIT_SHIFT),
			1 << LCD_SEG2_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG2_BIT_SHIFT),
			1 << LCD_SEG2_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG3_BIT_SHIFT),
			1 << LCD_SEG3_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM1_REGISTER, ~(1 << LCD_SEG3_BIT_SHIFT),
			1 << LCD_SEG3_BIT_SHIFT);

	HAL_LCD_Write(&hlcd, LCD_COM3_REGISTER, ~(1 << LCD_SEG0_BIT_SHIFT),
			1 << LCD_SEG0_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM2_REGISTER, ~(1 << LCD_SEG1_BIT_SHIFT),
			1 << LCD_SEG1_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG1_BIT_SHIFT),
			1 << LCD_SEG1_BIT_SHIFT);
	HAL_LCD_Write(&hlcd, LCD_COM0_REGISTER, ~(1 << LCD_SEG0_BIT_SHIFT),
			1 << LCD_SEG0_BIT_SHIFT);
}

void draw_colon(void)
{
	HAL_LCD_Write(&hlcd, LCD_COM3_REGISTER, ~(1 << LCD_SEG3_BIT_SHIFT),
			1 << LCD_SEG3_BIT_SHIFT);
}

void clear_colon(void)
{
	HAL_LCD_Write(&hlcd, LCD_COM3_REGISTER, ~(1 << LCD_SEG3_BIT_SHIFT),
			0 << LCD_SEG3_BIT_SHIFT);
}

void draw_pm(void)
{
	HAL_LCD_Write(&hlcd, LCD_COM3_REGISTER, ~(1 << LCD_SEG6_BIT_SHIFT),
			1 << LCD_SEG6_BIT_SHIFT);
}

void clear_pm(void)
{
	HAL_LCD_Write(&hlcd, LCD_COM3_REGISTER, ~(1 << LCD_SEG6_BIT_SHIFT),
			0 << LCD_SEG6_BIT_SHIFT);
}
