1 Commits

3 changed files with 109 additions and 57 deletions
+35 -48
View File
@@ -3,23 +3,25 @@
#include "lcd.h"
#include "DNI.h"
static int DNI_read(void)
static uint32_t DNI_read(void)
{
HAL_ADC_Start(&hadc1);
if (HAL_ADC_PollForConversion(&hadc1, 100) != HAL_OK)
PANIC(0x4000);
HAL_StatusTypeDef s = HAL_ADC_PollForConversion(&hadc1, 100);
if (HAL_OK != s)
return -s;
else
return HAL_ADC_GetValue(&hadc1);
return HAL_ADC_GetValue(&hadc1);
}
static int DNI_convert_to_celsius(int value)
static int DNI_convert_to_celsius(uint32_t value)
{
return (2512 - value) << 2;
}
static int DNI_convert_to_fahrenheit(uint32_t value)
{
return (2953 - value) * 50 / 7;
}
static void DNI_print(int temperature)
{
int add_sign = temperature < 0;
@@ -48,48 +50,27 @@ static void DNI_print(int temperature)
}
if (add_sign) {
DISPLAY_SET_CURSOR(1, 9);
DISPLAY_SET_CURSOR(1, 4);
display_write_data_byte('-');
}
}
static void DNI_print_celsius(int temperature)
{
DISPLAY_SET_CURSOR(1, 15);
DISPLAY_SET_CURSOR(1, 10);
DISPLAY_SET_DECREMENT;
display_write_data_seq("C ");
DNI_print(temperature);
}
static void print_ok(void)
static void DNI_print_fahrenheit(int temperature)
{
DISPLAY_SET_CURSOR(1, 4);
DISPLAY_SET_INCREMENT;
display_write_data_seq("OK");
}
DISPLAY_SET_CURSOR(1, 10);
DISPLAY_SET_DECREMENT;
display_write_data_seq("F ");
static void print_error(int err_code)
{
DISPLAY_SET_CURSOR(1, 4);
DISPLAY_SET_INCREMENT;
switch (err_code) {
case HAL_OK:
break;
case HAL_ERROR:
display_write_data_seq("HAL_ERROR");
break;
case HAL_BUSY:
display_write_data_seq("HAL_BUSY");
break;
case HAL_TIMEOUT:
display_write_data_seq("HAL_TIMEOUT");
break;
default:
display_write_data_seq("WRONG ERROR");
break;
}
DNI_print(temperature);
}
int DNI_show_celsius(void)
@@ -99,17 +80,23 @@ int DNI_show_celsius(void)
display_write_data_seq("DNI Temperature");
int value = DNI_read();
uint32_t value = DNI_read();
int temp = DNI_convert_to_celsius(value);
DNI_print_celsius(temp);
if (value < 0) {
print_error(-value);
return 1;
} else {
int temp = DNI_convert_to_celsius(value);
DNI_print_celsius(temp);
print_ok();
return 0;
}
return 0;
}
int DNI_show_fahrenheit(void)
{
DISPLAY_CLEAR;
DISPLAY_SET_INCREMENT;
display_write_data_seq("DNI Temperature");
uint32_t value = DNI_read();
int temp = DNI_convert_to_fahrenheit(value);
DNI_print_fahrenheit(temp);
return 0;
}
-3
View File
@@ -139,9 +139,6 @@ static void display_write_data_byte_framebuffer(uint8_t code)
if (display_current_frame >= DISPLAY_FRAMES_AVAILABLE)
return;
if (((int) des.cursor_offset >= 32) || ((int) des.cursor_offset < 0))
return;
display_framebuffer[16*2*display_current_frame + des.cursor_offset] = (char) code;
des.cursor_offset += des.next ? -1 : 1;
}
+74 -6
View File
@@ -120,6 +120,72 @@ static void MX_I2S2_Init(void);
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
static void button_init_and_test(void)
{
// letting the buttons be tested
display_write_data_seq("Fill any bar:");
DISPLAY_SET_CURSOR(1, 5);
display_write_data_seq("[-] [-----]");
size_t pressed_elements;
uint32_t sw_button_locations[5][2] = {
{(uint32_t) GPIOC, (uint32_t) GPIO_PIN_11},
{(uint32_t) GPIOA, (uint32_t) GPIO_PIN_15},
{(uint32_t) GPIOC, (uint32_t) GPIO_PIN_9},
{(uint32_t) GPIOC, (uint32_t) GPIO_PIN_6},
{(uint32_t) GPIOC, (uint32_t) GPIO_PIN_8}
};
do {
HAL_Delay(100);
pressed_elements = 0;
DISPLAY_SET_CURSOR(1, 6);
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0)) {
pressed_elements |= 0x20;
display_write_data_byte('*');
} else {
display_write_data_byte('-');
}
DISPLAY_SET_CURSOR(1, 10);
for (size_t i = 0; i < 5; i++) {
pressed_elements >>= 1;
size_t input = !HAL_GPIO_ReadPin((GPIO_TypeDef *) sw_button_locations[i][0], sw_button_locations[i][1]);
if (input) {
pressed_elements |= 0x20;
display_write_data_byte('*');
} else {
display_write_data_byte('-');
}
}
} while (!(((pressed_elements & 0x1) == 0x1) || ((pressed_elements & 0x3E) == 0x3E)));
// visual reaction to bar fill
DISPLAY_SET_CURSOR(0, 0);
display_write_data_seq("Release buttons");
GPIOD->ODR = 0x1000;
HAL_Delay(300);
GPIOD->ODR = 0x2000;
HAL_Delay(300);
GPIOD->ODR = 0x4000;
HAL_Delay(300);
GPIOD->ODR = 0x8000;
HAL_Delay(300);
// waiting for all buttons to be released
WAIT_UNTIL_ALL_BUTTONS_RELEASED;
GPIOD->ODR = 0x0000;
HAL_Delay(200);
}
/* USER CODE END 0 */
/**
@@ -158,10 +224,15 @@ int main(void)
MX_I2S2_Init();
/* USER CODE BEGIN 2 */
GPIOD->BSRR = 0x1000;
HAL_TIM_Base_Start(&htim2);
TIM2->CNT = 0;
HAL_TIM_Base_Stop(&htim2);
GPIOD->ODR = 0x1000;
display_init();
GPIOD->BSRR = 0xF000;
GPIOD->ODR = 0xF000;
button_init_and_test();
// perform all tests
size_t successful_tests = 0;
@@ -209,10 +280,7 @@ int main(void)
display_current_frame = 0;
DISPLAY_CLEAR;
if (successful_tests == LEN(executors))
display_write_data_seq("All tests done!");
else
display_write_data_seq("Failures found!");
display_write_data_seq("All tests done!");
DISPLAY_SET_CURSOR(1, 2);
display_write_data_seq("P:");