5,7 → 5,6 |
#include "SPI1.h" |
|
static CUBE_DATA *cube_data_ptr; |
static unsigned char current_layer; |
|
inline void Cube_Delay() { |
// Small delay to ensure that latch speeds are < 30Mhz |
16,7 → 15,7 |
|
void Cube_Init(CUBE_DATA *data, char BC) { |
cube_data_ptr = data; |
current_layer = 0; |
cube_data_ptr->current_layer = 0; |
|
SFT_D = 0; |
SFT_S = 0; |
50,7 → 49,7 |
|
void Cube_Timer_Interrupt(void) { |
// Write to the GCS register |
SPI1_Write(cube_data_ptr->GCS[current_layer], GCS_LAYER_SIZE, &Cube_GCS_Write_Callback); |
SPI1_Write(cube_data_ptr->GCS[cube_data_ptr->current_layer], GCS_LAYER_SIZE, &Cube_GCS_Write_Callback); |
} |
|
void Cube_DCS_Write_Callback(void) { |
72,7 → 71,7 |
int i; |
for (i = 0; i < CUBE_LAYER_COUNT; i++) { |
Cube_Delay(); |
SFT_D = (i == CUBE_LAYER_COUNT - current_layer - 1) ? 1 : 0; |
SFT_D = (i == CUBE_LAYER_COUNT - cube_data_ptr->current_layer - 1) ? 1 : 0; |
Cube_Delay(); |
SFT_K = 1; |
Cube_Delay(); |
88,10 → 87,12 |
Cube_Delay(); |
GSLAT = 0; |
|
current_layer = (current_layer == CUBE_LAYER_COUNT-1) ? 0 : current_layer + 1; |
cube_data_ptr->current_layer = (cube_data_ptr->current_layer == CUBE_LAYER_COUNT-1) |
? 0 : cube_data_ptr->current_layer + 1; |
} |
|
void Cube_Write_DCS(char BC) { |
// Ensure that the brightness isnt set too high |
if (BC > CUBE_MAX_BRIGHTNESS) |
BC = CUBE_MAX_BRIGHTNESS; |
|
117,7 → 118,7 |
|
GSLAT = 1; |
SPI1_Write(DCS, GCS_LAYER_SIZE, &Cube_DCS_Write_Callback); |
Delay_MS(8); // Delay until the entire DCS write is finished |
Delay_MS(10); // Delay until the entire DCS write is finished |
} |
|
void Cube_Clear(void) { |
128,6 → 129,7 |
} |
|
void Cube_Set_All(int R, int G, int B) { |
// Set all pixels in the cube to the given color |
R &= 0x0FFF; |
G &= 0x0FFF; |
B &= 0x0FFF; |
152,6 → 154,7 |
} |
|
void Cube_Set_Layer(int layer, int R, int G, int B) { |
// Set all pixels in the specified layer to the given color |
R &= 0x0FFF; |
G &= 0x0FFF; |
B &= 0x0FFF; |
174,6 → 177,7 |
} |
|
void Cube_Set_Pixel(int layer, int row, int column, int R, int G, int B) { |
// Set the specified pixel to the given color |
R &= 0x0FFF; |
G &= 0x0FFF; |
B &= 0x0FFF; |