forked from kkostyan/is31fl3733
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis31fl3733_abm.c
85 lines (81 loc) · 2.54 KB
/
is31fl3733_abm.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
#include "is31fl3733_abm.h"
void
IS31FL3733_SetLEDMode (IS31FL3733 *device, uint8_t cs, uint8_t sw, IS31FL3733_LED_MODE mode)
{
uint8_t offset;
// Check SW boundaries.
if (sw < IS31FL3733_SW)
{
// Check CS boundaries.
if (cs < IS31FL3733_CS)
{
// Set mode of individual LED.
// Calculate LED offset.
offset = sw * IS31FL3733_CS + cs;
// Write LED mode to device register.
IS31FL3733_WritePagedReg (device, IS31FL3733_LEDABM + offset, mode);
}
else
{
// Set mode of full row selected by SW.
for (cs = 0; cs < IS31FL3733_CS; cs++)
{
// Calculate LED offset.
offset = sw * IS31FL3733_CS + cs;
// Write LED mode to device register.
IS31FL3733_WritePagedReg (device, IS31FL3733_LEDABM + offset, mode);
}
}
}
else
{
// Check CS boundaries.
if (cs < IS31FL3733_CS)
{
// Set mode of full column selected by CS.
for (sw = 0; sw < IS31FL3733_SW; sw++)
{
// Calculate LED offset.
offset = sw * IS31FL3733_CS + cs;
// Write LED mode to device register.
IS31FL3733_WritePagedReg (device, IS31FL3733_LEDABM + offset, mode);
}
}
else
{
// Set mode of all LEDs.
for (sw = 0; sw < IS31FL3733_SW; sw++)
{
for (cs = 0; cs < IS31FL3733_CS; cs++)
{
// Calculate LED offset.
offset = sw * IS31FL3733_CS + cs;
// Write LED mode to device register.
IS31FL3733_WritePagedReg (device, IS31FL3733_LEDABM + offset, mode);
}
}
}
}
}
void
IS31FL3733_ConfigABM (IS31FL3733 *device, IS31FL3733_ABM_NUM n, IS31FL3733_ABM *config)
{
// Set fade in and fade out time.
IS31FL3733_WritePagedReg (device, n, config->T1 | config->T2);
// Set hold and off time.
IS31FL3733_WritePagedReg (device, n + 1, config->T3 | config->T4);
// Set loop begin/end time and high part of loop times.
IS31FL3733_WritePagedReg (device, n + 2, config->Tend | config->Tbegin | ((config->Times >> 8) & 0x0F));
// Set low part of loop times.
IS31FL3733_WritePagedReg (device, n + 3, config->Times & 0xFF);
}
void
IS31FL3733_StartABM (IS31FL3733 *device)
{
// Clear B_EN bit in configuration register.
IS31FL3733_WritePagedReg (device, IS31FL3733_CR, IS31FL3733_CR_SSD);
// Set B_EN bit in configuration register.
IS31FL3733_WritePagedReg (device, IS31FL3733_CR, IS31FL3733_CR_BEN | IS31FL3733_CR_SSD);
// Write 0x00 to Time Update Register to update ABM settings.
IS31FL3733_WritePagedReg (device, IS31FL3733_TUR, 0x00);
}