88 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			88 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
/*
 | 
						|
 * Display.cpp
 | 
						|
 *
 | 
						|
 *  Created on: Jul 29, 2023
 | 
						|
 *      Author: Carst
 | 
						|
 */
 | 
						|
 | 
						|
#include <cstdint>
 | 
						|
#include <cstdio>
 | 
						|
#include <cinttypes>
 | 
						|
#include <stm32g0xx_ll_gpio.h>
 | 
						|
#include "Display.hpp"
 | 
						|
#include "lcd_1602.h"
 | 
						|
 | 
						|
extern "C" void LCD_RS_SetLow(void)
 | 
						|
{
 | 
						|
  LL_GPIO_ResetOutputPin(GPIOB, LL_GPIO_PIN_4);
 | 
						|
}
 | 
						|
extern "C" void LCD_RS_SetHigh(void)
 | 
						|
{
 | 
						|
  LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_4);
 | 
						|
}
 | 
						|
extern "C" void LCD_RW_SetLow(void)
 | 
						|
{
 | 
						|
  LL_GPIO_ResetOutputPin(GPIOB, LL_GPIO_PIN_5);
 | 
						|
}
 | 
						|
extern "C" void LCD_RW_SetHigh(void)
 | 
						|
{
 | 
						|
  LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_5);
 | 
						|
}
 | 
						|
extern "C" void LCD_E_SetLow(void)
 | 
						|
{
 | 
						|
  LL_GPIO_ResetOutputPin(GPIOB, LL_GPIO_PIN_6);
 | 
						|
}
 | 
						|
extern "C" void LCD_E_SetHigh(void)
 | 
						|
{
 | 
						|
  LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_6);
 | 
						|
}
 | 
						|
extern "C" void LCD_DB_Set(uint8_t data)
 | 
						|
{
 | 
						|
  LL_GPIO_SetOutputPin(GPIOB, data);
 | 
						|
  LL_GPIO_ResetOutputPin(GPIOB, ~data & 0x0FUL);
 | 
						|
}
 | 
						|
extern "C" uint8_t LCD_DB_Get(void)
 | 
						|
{
 | 
						|
  return LL_GPIO_ReadInputPort(GPIOB);
 | 
						|
}
 | 
						|
extern "C" void LCD_DB_ConfigInput(void)
 | 
						|
{
 | 
						|
  LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_0, LL_GPIO_MODE_INPUT);
 | 
						|
  LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_1, LL_GPIO_MODE_INPUT);
 | 
						|
  LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_2, LL_GPIO_MODE_INPUT);
 | 
						|
  LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_3, LL_GPIO_MODE_INPUT);
 | 
						|
}
 | 
						|
extern "C" void LCD_DB_ConfigOutput(void)
 | 
						|
{
 | 
						|
  LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_0, LL_GPIO_MODE_OUTPUT);
 | 
						|
  LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_1, LL_GPIO_MODE_OUTPUT);
 | 
						|
  LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_2, LL_GPIO_MODE_OUTPUT);
 | 
						|
  LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_3, LL_GPIO_MODE_OUTPUT);
 | 
						|
 | 
						|
}
 | 
						|
namespace ElektronischeLast
 | 
						|
{
 | 
						|
  Display::Display(void)
 | 
						|
  {
 | 
						|
    lcd_init();
 | 
						|
  }
 | 
						|
 | 
						|
  Display::~Display(void)
 | 
						|
  {
 | 
						|
 | 
						|
  }
 | 
						|
  void Display::NewData(uint32_t strom, uint32_t spannung, uint32_t temperatur)
 | 
						|
  {
 | 
						|
    char buf[17]; // 16 Zeichen pro Zeile + \0
 | 
						|
    snprintf(buf, 16, "U: %2" PRIu32 ".%" PRIu32 " T: %2" PRIu32 ".%1" PRIu32,
 | 
						|
             spannung / 1000UL, spannung %1000UL, temperatur, 0UL);
 | 
						|
    lcd_set_cursor(eLine1, 0U);
 | 
						|
    lcd_string(buf);
 | 
						|
 | 
						|
    snprintf(buf, 16, "I: %2" PRIu32 ".%" PRIu32 " P: %4" PRIu32,
 | 
						|
             strom / 1000UL, strom %1000UL, strom * spannung / 1000UL);
 | 
						|
    lcd_string(buf);
 | 
						|
    lcd_set_cursor(eLine2, 0U);
 | 
						|
  }
 | 
						|
}
 |