fix i2c comms failures

This commit is contained in:
true 2024-08-02 17:33:02 -07:00
parent f8ce60d511
commit 70bf2c481f
3 changed files with 66 additions and 56 deletions

View File

@ -68,18 +68,14 @@ 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;
gpio.GPIO_Mode = GPIO_Mode_Out_OD; GPIOC->BSHR = GPIO_Pin_6;
gpio.GPIO_Pin = GPIO_Pin_3; gpio.GPIO_Mode = GPIO_Mode_Out_PP;
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

@ -122,7 +122,9 @@ 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) {
while(I2C_GetFlagStatus(I2C1, I2C_FLAG_TXE) != RESET) { // fixme: can get stuck here if address isn't found.
// 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

@ -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 = 0; // timeout until this program is done and switches static uint16_t rgb_prog_timer = 9; // 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,8 +424,7 @@ void ui_render()
is31fl3729_set_global_current(FL3729_ADDR, target_gc); is31fl3729_set_global_current(FL3729_ADDR, target_gc);
} }
led_rgbprog[rgb_prog_idx](LED_RGBPROG_NORMAL, tick); if (userconf.ledprog_ena_mask) {
// 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) {
@ -443,7 +442,13 @@ 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();
} }
@ -470,7 +475,14 @@ 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;
} }