LibDriver APA102C
Loading...
Searching...
No Matches
driver_apa102c_write_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static apa102c_handle_t gs_handle;
41static uint8_t gs_buffer[1024];
42static uint32_t gs_rgb[21];
43
53uint8_t apa102c_write_test(uint32_t cnt, uint32_t times)
54{
55 uint8_t res;
56 uint32_t num;
57 uint32_t i, j;
58 apa102c_info_t info;
59 const uint32_t color[7] = {0xFF0000U, 0xFF7F00U, 0xFFFF00U, 0x00FF00U, 0x00FFFFU, 0x0000FFU, 0x8F00FFU};
60
61 /* link interface function */
68
69 /* get information */
70 res = apa102c_info(&info);
71 if (res != 0)
72 {
73 apa102c_interface_debug_print("apa102c: get info failed.\n");
74
75 return 1;
76 }
77 else
78 {
79 /* print chip info */
80 apa102c_interface_debug_print("apa102c: chip is %s.\n", info.chip_name);
81 apa102c_interface_debug_print("apa102c: manufacturer is %s.\n", info.manufacturer_name);
82 apa102c_interface_debug_print("apa102c: interface is %s.\n", info.interface);
83 apa102c_interface_debug_print("apa102c: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
84 apa102c_interface_debug_print("apa102c: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
85 apa102c_interface_debug_print("apa102c: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
86 apa102c_interface_debug_print("apa102c: max current is %0.2fmA.\n", info.max_current_ma);
87 apa102c_interface_debug_print("apa102c: max temperature is %0.1fC.\n", info.temperature_max);
88 apa102c_interface_debug_print("apa102c: min temperature is %0.1fC.\n", info.temperature_min);
89 }
90
91 /* check cnt */
92 if (cnt == 0)
93 {
94 apa102c_interface_debug_print("apa102c: cnt can't be 0.\n");
95
96 return 1;
97 }
98 if (cnt > 21)
99 {
100 apa102c_interface_debug_print("apa102c: cnt is over 21 and use 21.\n");
101 }
102
103 /* start write test */
104 apa102c_interface_debug_print("apa102c: start write test.\n");
105
106 /* apa102c initialization */
107 res = apa102c_init(&gs_handle);
108 if (res != 0)
109 {
110 apa102c_interface_debug_print("apa102c: init failed.\n");
111
112 return 1;
113 }
114
115 /* set number */
116 num = cnt > 21 ? 21 : cnt;
117
118 for (i = 0; i < times; i++)
119 {
120 for (j = 0; j < num; j++)
121 {
122 gs_rgb[j] = APA102C_COLOR(color[i % 7] >> 16, color[i % 7] >> 8, color[i % 7] >> 0, 16);
123 }
124 res = apa102c_write(&gs_handle, (uint32_t *)gs_rgb, num, gs_buffer, 1024);
125 if (res != 0)
126 {
127 apa102c_interface_debug_print("apa102c: write failed.\n");
128 (void)apa102c_deinit(&gs_handle);
129
130 return 1;
131 }
132
133 /* delay 1000 ms */
135
136 /* output */
137 apa102c_interface_debug_print("apa102c: %d/%d times.\n", i + 1, times);
138 }
139
140 /* close all leds */
141 res = apa102c_write_off(&gs_handle, num, gs_buffer, 1024);
142 if (res != 0)
143 {
144 apa102c_interface_debug_print("apa102c: write failed.\n");
145 (void)apa102c_deinit(&gs_handle);
146
147 return 1;
148 }
149
150 /* finish write test */
151 apa102c_interface_debug_print("apa102c: finish write test.\n");
152
153 /* close the chip */
154 (void)apa102c_deinit(&gs_handle);
155
156 return 0;
157}
driver apa102c write test header file
uint8_t apa102c_info(apa102c_info_t *info)
get chip's information
uint8_t apa102c_init(apa102c_handle_t *handle)
initialize the chip
uint8_t apa102c_deinit(apa102c_handle_t *handle)
close the chip
uint8_t apa102c_write(apa102c_handle_t *handle, uint32_t *color, uint32_t len, uint8_t *temp, uint32_t temp_len)
write color frame
uint8_t apa102c_write_off(apa102c_handle_t *handle, uint32_t len, uint8_t *temp, uint32_t temp_len)
write off frame
struct apa102c_info_s apa102c_info_t
apa102c information structure definition
struct apa102c_handle_s apa102c_handle_t
apa102c handle structure definition
#define APA102C_COLOR(RED, GREEN, BLUE, BRIGHTNESS)
make color
void apa102c_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t apa102c_interface_spi_deinit(void)
interface spi bus deinit
void apa102c_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t apa102c_interface_spi_write_cmd(uint8_t *buf, uint16_t len)
interface spi bus write command
uint8_t apa102c_interface_spi_init(void)
interface spi bus init
uint8_t apa102c_write_test(uint32_t cnt, uint32_t times)
write test
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v