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
// IS_SDB IS31FL3729 shutdown pin (active low)
// WP for EEPROM
GPIOC->BCR = GPIO_Pin_3;
gpio.GPIO_Mode = GPIO_Mode_Out_OD;
gpio.GPIO_Pin = GPIO_Pin_3;
GPIOC->BSHR = GPIO_Pin_6;
gpio.GPIO_Mode = GPIO_Mode_Out_PP;
gpio.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_6;
GPIO_Init(GPIOC, &gpio);
// 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)

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;
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++);
len--;
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 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 preview_idx = 0; // currently selected program preview index
@ -320,12 +320,12 @@ static void ui_cursor_flash()
if (cursor_flash < 4) {
level >>= (cursor_flash << 1);
}
}
// set the level on the cursor
if (cursor[color] != level) {
cursor[color] = level;
led_is_updated();
}
// set the level on the cursor
if (cursor[color] != level) {
cursor[color] = level;
led_is_updated();
}
if (!cursor_flash) {
@ -424,54 +424,66 @@ void ui_render()
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
rgb_prog_timer--;
if (rgb_prog_timer <= 17) {
if (rgb_prog_timer > 9) {
// fade out current program
w = (rgb_prog_timer & 0x1f) - 10;
for (i = 0; i < 9; i++) {
rgb[i][0] >>= w;
rgb[i][1] >>= w;
rgb[i][2] >>= w;
}
} else if (rgb_prog_timer > 7) {
// select a new random program
if (rgb_prog_timer == 8) {
w = prng_get8();
w &= 0x3;
if (w == rgb_prog_idx) w++;
// fade and change programs depending on the timer
rgb_prog_timer--;
if (rgb_prog_timer <= 17) {
if (rgb_prog_timer > 9) {
// fade out current program
w = (rgb_prog_timer & 0x1f) - 10;
for (i = 0; i < 9; i++) {
rgb[i][0] >>= w;
rgb[i][1] >>= w;
rgb[i][2] >>= w;
}
} else if (rgb_prog_timer > 7) {
// select a new random program
if (rgb_prog_timer == 8) {
w = prng_get8();
w &= 0x3;
if (w == rgb_prog_idx) w++;
rgb_prog_idx = w;
for (i = 0; i < 7; i++) {
if (userconf.ledprog_ena_mask & (1 << ((w + i) & 0x7))) {
rgb_prog_idx = w;
break;
}
}
led_rgb_firstrun();
}
led_rgb_firstrun();
}
// clear out for now, since new program hasn't actually been run
for (i = 0; i < 9; i++) {
rgb[i][0] = 0;
rgb[i][1] = 0;
rgb[i][2] = 0;
}
} else if (rgb_prog_timer >= 1) {
// fade in new program
w = 8 - (rgb_prog_timer & 0x1f);
for (i = 0; i < 9; i++) {
rgb[i][0] >>= w;
rgb[i][1] >>= w;
rgb[i][2] >>= w;
}
} else { // 0
// randomize next program timing
t = prng_get16();
t *= (UI_PROG_RUNTIME_MAX - UI_PROG_RUNTIME_MIN);
t >>= 16;
// clear out for now, since new program hasn't actually been run
for (i = 0; i < 9; i++) {
rgb[i][0] = 0;
rgb[i][1] = 0;
rgb[i][2] = 0;
}
} else if (rgb_prog_timer >= 1) {
// fade in new program
w = 8 - (rgb_prog_timer & 0x1f);
for (i = 0; i < 9; i++) {
rgb[i][0] >>= w;
rgb[i][1] >>= w;
rgb[i][2] >>= w;
}
} else { // 0
// randomize next program timing
t = prng_get16();
t *= (UI_PROG_RUNTIME_MAX - UI_PROG_RUNTIME_MIN);
t >>= 16;
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;
}