-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_peripherals.c
97 lines (89 loc) · 2.43 KB
/
update_peripherals.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* @file update_peripherals.c
* @author Lukas Nejezchleb (nejezluk@fel.cvut.cz)
* @brief Module for setting the peripherals
* @version 0.1
* @date 2021-05-04
*
* @copyright Copyright (c) 2021
*
*/
#include "update_peripherals.h"
#include "mzapo_parlcd.h"
#include "mzapo_regs.h"
#include <stdio.h>
#include <stdbool.h>
void lcd_from_fb(const fb_data *frame_buff, unsigned char *parlcd_mem_base)
{
if (parlcd_mem_base == NULL)
{
return;
}
parlcd_write_cmd(parlcd_mem_base, 0x2c);
for (int i = 0; i < frame_buff->width * frame_buff->height; ++i)
{
parlcd_write_data(parlcd_mem_base, frame_buff->fb[i]);
}
}
void led_strip_number(unsigned char *led_mem_base, int max_nr, int nr)
{
if (max_nr <= 0 || nr < 0 || led_mem_base == NULL)
{
return;
}
int divisions = max_nr * 2 - 1;
uint32_t output = 0;
float width = 32 / (float)divisions;
int displayed = 1;
bool active = true; // indicates if it is just space or if the led can light up
float current_limit = width;
for (int i = 0; i < 32; ++i)
{
if (current_limit < i)
{
current_limit += width;
if (active)
{
active = false;
}
else
{
displayed++;
active = true;
}
}
if (active && (displayed <= nr))
{
output = output | 1;
}
output = output << 1;
}
*(volatile uint32_t *)(led_mem_base + SPILED_REG_LED_LINE_o) = output;
}
void set_left_RGB(unsigned char *led_mem_base, uint8_t r, uint8_t g, uint8_t b)
{
if (led_mem_base == NULL)
{
return;
}
uint32_t color = (r << 16) | (g << 8) | b;
*(volatile uint32_t *)(led_mem_base + SPILED_REG_LED_RGB1_o) = color;
}
void set_right_RGB(unsigned char *led_mem_base, uint8_t r, uint8_t g, uint8_t b)
{
if (led_mem_base == NULL)
{
return;
}
uint32_t color = (r << 16) | (g << 8) | b;
*(volatile uint32_t *)(led_mem_base + SPILED_REG_LED_RGB2_o) = color;
}
void sel_leds_color(unsigned char *led_mem_base, uint32_t color)
{
if (led_mem_base == NULL)
{
return;
}
*(volatile uint32_t *)(led_mem_base + SPILED_REG_LED_RGB1_o) = color;
*(volatile uint32_t *)(led_mem_base + SPILED_REG_LED_RGB2_o) = color;
}