1515
1616#include "../src/light/light_matrix.h"
1717#include "../drv/clock/clock_test.h"
18+ #include "../drv/pwm/pwm.h"
19+ #include "../drv/led/led_array.h"
1820
1921#define MATRIX_SIZE 3
2022#define INTERVAL 10
@@ -32,60 +34,55 @@ static const uint8_t test_animation[] = {
3234 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 ,
3335};
3436
35- static uint8_t test_light_matrix_set_pixel_last_brightness [MATRIX_SIZE ][MATRIX_SIZE ];
37+ // Buffer in the led_array pwm driver.
38+ extern uint8_t test_light_matrix_set_pixel_last_brightness [MATRIX_SIZE ][MATRIX_SIZE ];
3639
3740static void test_light_matrix_reset (void ) {
3841 memset (test_light_matrix_set_pixel_last_brightness , 0 , DATA_SIZE );
3942}
4043
41- static pbio_error_t test_light_matrix_set_pixel (pbio_light_matrix_t * light_matrix , uint8_t row , uint8_t col , uint8_t brightness ) {
42- test_light_matrix_set_pixel_last_brightness [row ][col ] = brightness ;
43- return PBIO_SUCCESS ;
44- }
45-
46- static const pbio_light_matrix_funcs_t test_light_matrix_funcs = {
47- .set_pixel = test_light_matrix_set_pixel ,
48- };
49-
5044static PT_THREAD (test_light_matrix (struct pt * pt )) {
5145 PT_BEGIN (pt );
5246
53- static pbio_light_matrix_t test_light_matrix ;
54- pbio_light_matrix_init (& test_light_matrix , MATRIX_SIZE , & test_light_matrix_funcs );
47+ pbdrv_pwm_init ();
48+ pbdrv_led_array_init ();
49+
50+ static pbio_light_matrix_t * test_light_matrix ;
51+ pbio_light_matrix_get_dev (0 , MATRIX_SIZE , & test_light_matrix );
5552
5653 // ensure get size works
57- tt_want_uint_op (pbio_light_matrix_get_size (& test_light_matrix ), = = , MATRIX_SIZE );
54+ tt_want_uint_op (pbio_light_matrix_get_size (test_light_matrix ), = = , MATRIX_SIZE );
5855
5956 // set pixel should only set one pixel
6057 test_light_matrix_reset ();
61- tt_want_uint_op (pbio_light_matrix_set_pixel (& test_light_matrix , 0 , 0 , 100 , true), = = , PBIO_SUCCESS );
58+ tt_want_uint_op (pbio_light_matrix_set_pixel (test_light_matrix , 0 , 0 , 100 , true), = = , PBIO_SUCCESS );
6259 tt_want_light_matrix_data (100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 );
6360
64- tt_want_uint_op (pbio_light_matrix_set_pixel (& test_light_matrix ,
61+ tt_want_uint_op (pbio_light_matrix_set_pixel (test_light_matrix ,
6562 MATRIX_SIZE - 1 , MATRIX_SIZE - 1 , 100 , true), = = , PBIO_SUCCESS );
6663 tt_want_light_matrix_data (100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 100 );
6764
6865 // out of bounds checking
69- tt_want_uint_op (pbio_light_matrix_set_pixel (& test_light_matrix , MATRIX_SIZE , 0 , 100 , true), = = , PBIO_SUCCESS );
66+ tt_want_uint_op (pbio_light_matrix_set_pixel (test_light_matrix , MATRIX_SIZE , 0 , 100 , true), = = , PBIO_SUCCESS );
7067 tt_want_light_matrix_data (100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 100 );
71- tt_want_uint_op (pbio_light_matrix_set_pixel (& test_light_matrix , 0 , MATRIX_SIZE , 100 , true), = = , PBIO_SUCCESS );
68+ tt_want_uint_op (pbio_light_matrix_set_pixel (test_light_matrix , 0 , MATRIX_SIZE , 100 , true), = = , PBIO_SUCCESS );
7269 tt_want_light_matrix_data (100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 100 );
7370
7471 // bitwise mapping
7572 test_light_matrix_reset ();
76- tt_want_uint_op (pbio_light_matrix_set_rows (& test_light_matrix , ROW_DATA (0b100 , 0b010 , 0b001 )), = = , PBIO_SUCCESS );
73+ tt_want_uint_op (pbio_light_matrix_set_rows (test_light_matrix , ROW_DATA (0b100 , 0b010 , 0b001 )), = = , PBIO_SUCCESS );
7774 tt_want_light_matrix_data (100 , 0 , 0 , 0 , 100 , 0 , 0 , 0 , 100 );
7875
7976 // bytewise mapping
8077 test_light_matrix_reset ();
81- tt_want_uint_op (pbio_light_matrix_set_image (& test_light_matrix ,
78+ tt_want_uint_op (pbio_light_matrix_set_image (test_light_matrix ,
8279 IMAGE_DATA (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 )), = = , PBIO_SUCCESS );
8380 tt_want_light_matrix_data (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 );
8481
8582 // starting animation should schedule timer event at 0 ms to call
8683 // set_pixel() after handling pending events.
8784 test_light_matrix_reset ();
88- pbio_light_matrix_start_animation (& test_light_matrix , test_animation , 2 , INTERVAL );
85+ pbio_light_matrix_start_animation (test_light_matrix , test_animation , 2 , INTERVAL );
8986 pbio_handle_pending_events ();
9087 tt_want_light_matrix_data (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 );
9188
@@ -110,7 +107,7 @@ static PT_THREAD(test_light_matrix(struct pt *pt)) {
110107
111108 // stopping the animation should not change any pixels
112109 test_light_matrix_reset ();
113- pbio_light_matrix_stop_animation (& test_light_matrix );
110+ pbio_light_matrix_stop_animation (test_light_matrix );
114111 pbio_test_clock_tick (INTERVAL * 2 );
115112 PT_YIELD (pt );
116113 tt_want_light_matrix_data (0 );
@@ -119,12 +116,16 @@ static PT_THREAD(test_light_matrix(struct pt *pt)) {
119116}
120117
121118static void test_light_matrix_rotation (void * env ) {
122- static pbio_light_matrix_t test_light_matrix ;
123- pbio_light_matrix_init (& test_light_matrix , MATRIX_SIZE , & test_light_matrix_funcs );
119+
120+ pbdrv_pwm_init ();
121+ pbdrv_led_array_init ();
122+
123+ static pbio_light_matrix_t * test_light_matrix ;
124+ pbio_light_matrix_get_dev (0 , MATRIX_SIZE , & test_light_matrix );
124125
125126 // Default orientation has pixels in same order as underlying light array
126127 test_light_matrix_reset ();
127- tt_want_uint_op (pbio_light_matrix_set_image (& test_light_matrix ,
128+ tt_want_uint_op (pbio_light_matrix_set_image (test_light_matrix ,
128129 IMAGE_DATA (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 )), = = , PBIO_SUCCESS );
129130 tt_want_light_matrix_data (
130131 1 , 2 , 3 ,
@@ -134,26 +135,26 @@ static void test_light_matrix_rotation(void *env) {
134135 // Check that other orientations work
135136
136137 test_light_matrix_reset ();
137- pbio_light_matrix_set_orientation (& test_light_matrix , PBIO_GEOMETRY_SIDE_LEFT );
138- tt_want_uint_op (pbio_light_matrix_set_image (& test_light_matrix ,
138+ pbio_light_matrix_set_orientation (test_light_matrix , PBIO_GEOMETRY_SIDE_LEFT );
139+ tt_want_uint_op (pbio_light_matrix_set_image (test_light_matrix ,
139140 IMAGE_DATA (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 )), = = , PBIO_SUCCESS );
140141 tt_want_light_matrix_data (
141142 3 , 6 , 9 ,
142143 2 , 5 , 8 ,
143144 1 , 4 , 7 );
144145
145146 test_light_matrix_reset ();
146- pbio_light_matrix_set_orientation (& test_light_matrix , PBIO_GEOMETRY_SIDE_BOTTOM );
147- tt_want_uint_op (pbio_light_matrix_set_image (& test_light_matrix ,
147+ pbio_light_matrix_set_orientation (test_light_matrix , PBIO_GEOMETRY_SIDE_BOTTOM );
148+ tt_want_uint_op (pbio_light_matrix_set_image (test_light_matrix ,
148149 IMAGE_DATA (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 )), = = , PBIO_SUCCESS );
149150 tt_want_light_matrix_data (
150151 9 , 8 , 7 ,
151152 6 , 5 , 4 ,
152153 3 , 2 , 1 );
153154
154155 test_light_matrix_reset ();
155- pbio_light_matrix_set_orientation (& test_light_matrix , PBIO_GEOMETRY_SIDE_RIGHT );
156- tt_want_uint_op (pbio_light_matrix_set_image (& test_light_matrix ,
156+ pbio_light_matrix_set_orientation (test_light_matrix , PBIO_GEOMETRY_SIDE_RIGHT );
157+ tt_want_uint_op (pbio_light_matrix_set_image (test_light_matrix ,
157158 IMAGE_DATA (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 )), = = , PBIO_SUCCESS );
158159 tt_want_light_matrix_data (
159160 7 , 4 , 1 ,
@@ -162,8 +163,8 @@ static void test_light_matrix_rotation(void *env) {
162163
163164 // front is same as top
164165 test_light_matrix_reset ();
165- pbio_light_matrix_set_orientation (& test_light_matrix , PBIO_GEOMETRY_SIDE_FRONT );
166- tt_want_uint_op (pbio_light_matrix_set_image (& test_light_matrix ,
166+ pbio_light_matrix_set_orientation (test_light_matrix , PBIO_GEOMETRY_SIDE_FRONT );
167+ tt_want_uint_op (pbio_light_matrix_set_image (test_light_matrix ,
167168 IMAGE_DATA (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 )), = = , PBIO_SUCCESS );
168169 tt_want_light_matrix_data (
169170 1 , 2 , 3 ,
@@ -172,8 +173,8 @@ static void test_light_matrix_rotation(void *env) {
172173
173174 // back is same as bottom
174175 test_light_matrix_reset ();
175- pbio_light_matrix_set_orientation (& test_light_matrix , PBIO_GEOMETRY_SIDE_BACK );
176- tt_want_uint_op (pbio_light_matrix_set_image (& test_light_matrix ,
176+ pbio_light_matrix_set_orientation (test_light_matrix , PBIO_GEOMETRY_SIDE_BACK );
177+ tt_want_uint_op (pbio_light_matrix_set_image (test_light_matrix ,
177178 IMAGE_DATA (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 )), = = , PBIO_SUCCESS );
178179 tt_want_light_matrix_data (
179180 9 , 8 , 7 ,
0 commit comments