Compare commits

..

No commits in common. "185578ad8d598e296d1a61367a5a412045b1caeb" and "f8ce60d511e3cf76b2fe5e6725dd1e2b3e46f236" have entirely different histories.

6 changed files with 93 additions and 101 deletions

View File

@ -68,14 +68,18 @@ void gpio_init()
// I2C will be handled by the driver // I2C will be handled by the driver
// IS_SDB IS31FL3729 shutdown pin (active low) // IS_SDB IS31FL3729 shutdown pin (active low)
// WP for EEPROM
GPIOC->BCR = GPIO_Pin_3; GPIOC->BCR = GPIO_Pin_3;
GPIOC->BSHR = GPIO_Pin_6; gpio.GPIO_Mode = GPIO_Mode_Out_OD;
gpio.GPIO_Mode = GPIO_Mode_Out_PP; gpio.GPIO_Pin = GPIO_Pin_3;
gpio.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_6;
GPIO_Init(GPIOC, &gpio); GPIO_Init(GPIOC, &gpio);
// BTN1, BTN2 will be handled by button handler // BTN1, BTN2 will be handled by button handler
// WP for EEPROM
GPIOC->BSHR = GPIO_Pin_6;
gpio.GPIO_Mode = GPIO_Mode_Out_OD;
gpio.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOC, &gpio);
} }
int main(void) int main(void)

View File

@ -81,20 +81,18 @@ void adc_convert()
void adc_read() void adc_read()
{ {
if (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)) { while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));
adc_val[adc_val_idx++] = ADC_GetConversionValue(ADC1); adc_val[adc_val_idx++] = ADC_GetConversionValue(ADC1);
adc_val_idx &= 0x0f; adc_val_idx &= 0x0f;
if (!adc_val_idx) adc_calc_avg(); if (!adc_val_idx) adc_calc_avg();
if (ADC1->CTLR1 & ADC_JAUTO) { if (ADC1->CTLR1 & ADC_JAUTO) {
if (ADC_GetFlagStatus(ADC1, ADC_FLAG_JEOC)) { while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_JEOC));
lsens_val = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_1); lsens_val = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_1);
// reset LSENS // reset LSENS
ADC_AutoInjectedConvCmd(ADC1, DISABLE); ADC_AutoInjectedConvCmd(ADC1, DISABLE);
} }
}
}
} }
void adc_use_lsens() void adc_use_lsens()

View File

@ -122,9 +122,7 @@ int8_t i2c_write_addr1b(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len)
if (!timeout) return -4; if (!timeout) return -4;
while (len) { while (len) {
// fixme: can get stuck here if address isn't found. while(I2C_GetFlagStatus(I2C1, I2C_FLAG_TXE) != RESET) {
// somehow all the above passes but this will fail
if (I2C_GetFlagStatus(I2C1, I2C_FLAG_TXE) != RESET) {
I2C_SendData(I2C1, *data++); I2C_SendData(I2C1, *data++);
len--; len--;
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));

View File

@ -12,8 +12,8 @@
static const uint8_t rgb_map[9] = {0x04, 0x14, 0x01, 0x11, 0x07, 0x0a, 0x1a, 0x0d, 0x1d}; const uint8_t rgb_map[9] = {0x04, 0x14, 0x01, 0x11, 0x07, 0x0a, 0x1a, 0x0d, 0x1d};
static const uint8_t cursor_map[3] = {0x17, 0x18, 0x19}; const uint8_t cursor_map[3] = {0x17, 0x18, 0x19};
@ -45,17 +45,15 @@ void led_is_updated()
void led_send() void led_send()
{ {
uint8_t i; uint8_t i;
uint8_t o;
uint8_t out[16*2]; uint8_t out[16*2];
// only render when there's something to render // only render when there's something to render
if (led_updated) { if (led_updated) {
// stuff RGB outputs // stuff RGB outputs
for (i = 0; i < 9; i++) { for (i = 0; i < 9; i++) {
o = (rgb_map[i] - 1) & 0x1f; out[rgb_map[i] + 0] = rgb[i][0];
out[o + 0] = rgb[i][0]; out[rgb_map[i] + 1] = rgb[i][1];
out[o + 1] = rgb[i][1]; out[rgb_map[i] + 2] = rgb[i][2];
out[o + 2] = rgb[i][2];
} }
// stuff cursor outputs // stuff cursor outputs

View File

@ -62,6 +62,22 @@ static const uint8_t rainbow_angles[8][5] = {
0x00, 0x00} // bottom to top 0x00, 0x00} // bottom to top
}; };
static void rainbow_letter_next()
{
uint16_t h;
// add to our hue
h = userconf.ledprog_setting[0][1];
h <<= 2;
rainbow_hue += h;
rainbow_hue++;
rainbow_hue %= 256*6;
// make a color out of it
hsv2rgb_8b(rainbow_hue, 255, 255, &prog_rgb[0], &prog_rgb[1], &prog_rgb[2]);
}
void led_rgb_0_rainbow(uint8_t preview, uint8_t tick) void led_rgb_0_rainbow(uint8_t preview, uint8_t tick)
{ {
uint8_t i, j; // iterator uint8_t i, j; // iterator
@ -70,8 +86,6 @@ void led_rgb_0_rainbow(uint8_t preview, uint8_t tick)
uint8_t max; // max number of iterations for this angle uint8_t max; // max number of iterations for this angle
uint8_t angle; // fill direction from LUT uint8_t angle; // fill direction from LUT
uint16_t hoff;
// run at half framerate // run at half framerate
if (tick & 1) { if (tick & 1) {
// no matter what, this puke is getting updated // no matter what, this puke is getting updated
@ -82,24 +96,22 @@ void led_rgb_0_rainbow(uint8_t preview, uint8_t tick)
angle &= 0x7; angle &= 0x7;
max = rainbow_angles[angle][2] & 0x7; max = rainbow_angles[angle][2] & 0x7;
hoff = userconf.ledprog_setting[0][1];
hoff <<= 2;
hoff = (256*6) - hoff;
// process outputs // process outputs
for (i = 0; i <= max; i++) { for (i = 0; i <= max; i++) {
// get the next puke // get the next puke
hsv2rgb_8b((rainbow_hue + (hoff * i)) % (256*6), 255, 255, rainbow_letter_next();
&prog_rgb[0], &prog_rgb[1], &prog_rgb[2]);
// apply to next set of LEDs // apply to next set of LEDs
n = 0; n = 0;
for (j = 0; j < 9; j++) { for (j = 0; j < 9; j++) {
n++;
if (j == 5) n++; // nybble index
idx = rainbow_angles[angle][n >> 1]; // get mask byte idx = rainbow_angles[angle][n >> 1]; // get mask byte
if (!(n & 1)) idx >>= 4; // shift even numbered LED index over if ((n & 1) == 0) idx >>= 4; // shift even values over
idx &= 0x7; // mask lowest 3 bits idx &= 0x7; // mask lowest 3 bits
if (i == idx) { // is this LED part of this pattern at this index? if (idx == i) { // is this LED part of this pattern?
if (preview) { // are we in preview mode? if (preview) { // are we in preview mode?
if (j != 0) { // is the first letter not the one selected? if (j != 0) { // is the first letter not the one selected?
if ((preview & 0x7f) == 0) {// is this preview selected? if ((preview & 0x7f) == 0) {// is this preview selected?
@ -111,14 +123,8 @@ void led_rgb_0_rainbow(uint8_t preview, uint8_t tick)
rgb[j][1] = prog_rgb[1]; rgb[j][1] = prog_rgb[1];
rgb[j][2] = prog_rgb[2]; rgb[j][2] = prog_rgb[2];
} }
n++; // nybble index
if (n == 5) n++; // skip the 6th nybble; this indicates the max
} }
} }
rainbow_hue += 2;
rainbow_hue %= (256*6);
} }
} }

View File

@ -50,7 +50,7 @@ static const uint16_t cursor_flash_rates[] = { // off-to-on flash rates in
}; };
static uint8_t rgb_prog_idx = 0; // currently running rgbled program index static uint8_t rgb_prog_idx = 0; // currently running rgbled program index
static uint16_t rgb_prog_timer = 9; // timeout until this program is done and switches static uint16_t rgb_prog_timer = 0; // timeout until this program is done and switches
static uint8_t rgb_prog_is_editing = 0; // currently editing a program's parameters static uint8_t rgb_prog_is_editing = 0; // currently editing a program's parameters
static uint8_t preview_idx = 0; // currently selected program preview index static uint8_t preview_idx = 0; // currently selected program preview index
@ -320,13 +320,13 @@ static void ui_cursor_flash()
if (cursor_flash < 4) { if (cursor_flash < 4) {
level >>= (cursor_flash << 1); level >>= (cursor_flash << 1);
} }
}
// set the level on the cursor // set the level on the cursor
if (cursor[color] != level) { if (cursor[color] != level) {
cursor[color] = level; cursor[color] = level;
led_is_updated(); led_is_updated();
} }
}
if (!cursor_flash) { if (!cursor_flash) {
// toggle on/off // toggle on/off
@ -424,7 +424,8 @@ void ui_render()
is31fl3729_set_global_current(FL3729_ADDR, target_gc); is31fl3729_set_global_current(FL3729_ADDR, target_gc);
} }
if (userconf.ledprog_ena_mask) { led_rgbprog[rgb_prog_idx](LED_RGBPROG_NORMAL, tick);
// fade and change programs depending on the timer // fade and change programs depending on the timer
rgb_prog_timer--; rgb_prog_timer--;
if (rgb_prog_timer <= 17) { if (rgb_prog_timer <= 17) {
@ -442,13 +443,7 @@ void ui_render()
w = prng_get8(); w = prng_get8();
w &= 0x3; w &= 0x3;
if (w == rgb_prog_idx) w++; if (w == rgb_prog_idx) w++;
for (i = 0; i < 7; i++) {
if (userconf.ledprog_ena_mask & (1 << ((w + i) & 0x7))) {
rgb_prog_idx = w; rgb_prog_idx = w;
break;
}
}
led_rgb_firstrun(); led_rgb_firstrun();
} }
@ -475,14 +470,7 @@ void ui_render()
rgb_prog_timer = t + UI_PROG_RUNTIME_MIN; rgb_prog_timer = t + UI_PROG_RUNTIME_MIN;
} }
// actually run the program
led_rgbprog[rgb_prog_idx - 1](LED_RGBPROG_NORMAL, tick);
} }
}
// temp: remove me once buttons are tested and working
led_rgbprog[0](LED_RGBPROG_NORMAL, tick);
break; break;
} }