Compare commits

..

6 Commits

Author SHA1 Message Date
true 56fed44f7a Fix program 4 affecting more LEDs than it should in program mode 2024-08-08 04:44:22 -07:00
true 218819f75f fixed led flashing in programming mode being fucked
don't write code when sleep deprived you make stupid mistakes
2024-08-08 03:51:24 -07:00
true 3eb211fb54 finally fixed bug in i2c address scan check routine
was checking if set instead of negated. oops.
2024-08-08 03:35:03 -07:00
true d32442da9a non-white cursor no longer stays on in programming modes 2024-08-08 03:33:23 -07:00
true 3a48cd8f06 change button gpio init to be like other programs, as part of gpio_init() 2024-08-08 03:32:59 -07:00
true 340cdcad89 initialize memory for led programs at startup 2024-08-07 13:22:24 -07:00
6 changed files with 49 additions and 35 deletions

View File

@ -3,7 +3,8 @@
* GAT Addon Firmware
* by true
*
* version 0.0.2
* version 0.0.3
* Last Update 20240808
*
* code was made for different random addons I designed for dc32,
* then adapted to each one. so things might be a mess.
@ -26,6 +27,7 @@
#include "src/config.h"
#include "src/i2c.h"
#include "src/led.h"
#include "src/led_rgbprog.h"
#include "src/rand.h"
#include "src/ui.h"
@ -57,10 +59,12 @@ void gpio_init()
// lightsense LED cathode
gpio.GPIO_Mode = GPIO_Mode_Out_PP;
gpio.GPIO_Pin = GPIO_Pin_2;
GPIOA->OUTDR = ~GPIO_Pin_2;
GPIO_Init(GPIOA, &gpio);
// lightsense LED anode
gpio.GPIO_Pin = GPIO_Pin_0;
GPIOD->OUTDR = ~GPIO_Pin_0;
GPIO_Init(GPIOD, &gpio);
// unused pins
@ -84,7 +88,14 @@ void gpio_init()
gpio.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_6;
GPIO_Init(GPIOC, &gpio);
// BTN1, BTN2 will be handled by button handler
// BTN1 (PC5) pull up, BTN2 (PC4) pull down
gpio.GPIO_Pin = GPIO_Pin_4;
gpio.GPIO_Mode = GPIO_Mode_IPD;
GPIO_Init(GPIOC, &gpio);
gpio.GPIO_Pin = GPIO_Pin_5;
gpio.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOC, &gpio);
}
int main(void)
@ -101,7 +112,6 @@ int main(void)
// configure gpio pins, hard buttons (used for settings reset)
gpio_init();
btn_init();
// get saved settings, or reset if BTN1 is pushed
i2c_init();
@ -109,6 +119,7 @@ int main(void)
// configure hardware
adc_init();
btn_init();
led_init();
// configure random
@ -120,6 +131,9 @@ int main(void)
// configure systick interrupt
systick_init();
// set up LEDs initially
led_rgb_firstrun();
// do system shit
while(1) {
__WFI();

View File

@ -18,10 +18,10 @@ void btn_init()
{
uint8_t i;
// configure GPIO
BTN_PORT->BSHR = (BTN1_PUPD << BTN1_PIN) | (BTN2_PUPD << BTN2_PIN);
BTN_PORT->CFGLR &= ~((0xf << (BTN1_PIN*4)) | ((0xf << (BTN2_PIN*4))));
BTN_PORT->CFGLR |= (0x8 << (BTN1_PIN*4)) | (0x8 << (BTN2_PIN*4));
// configure GPIO (now handled as part of main GPIO init function)
// BTN_PORT->BSHR = (BTN1_PUPD << BTN1_PIN) | (BTN2_PUPD << BTN2_PIN);
// BTN_PORT->CFGLR &= ~((0xf << (BTN1_PIN*4)) | ((0xf << (BTN2_PIN*4))));
// BTN_PORT->CFGLR |= (0x8 << (BTN1_PIN*4)) | (0x8 << (BTN2_PIN*4));
// configure default setup
for (i = 0; i < BTN_COUNT; i++) {

View File

@ -80,12 +80,10 @@ int8_t i2c_read_addr1b(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len)
*data++ = I2C_ReceiveData(I2C1);
len--;
if (!len) {
I2C_GenerateSTOP(I2C1, ENABLE);
}
}
I2C_GenerateSTOP(I2C1, ENABLE);
return 0;
}
@ -145,7 +143,7 @@ void i2c_write_reg_8b(uint8_t addr, uint8_t reg, const uint8_t dat)
i2c_write_addr1b(addr, reg, &dat, 1);
}
uint8_t i2c_addr_scan(uint8_t addr)
int8_t i2c_addr_scan(uint8_t addr)
{
uint8_t found = 1;
uint32_t event;
@ -164,30 +162,28 @@ uint8_t i2c_addr_scan(uint8_t addr)
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT) && timeout--);
if (!timeout) return -2;
I2C_Send7bitAddress(I2C1, addr, (addr & 1));
I2C_Send7bitAddress(I2C1, (addr & 0xfe), (addr & 0x01));
timeout = I2C_TIMEOUT_ACK_POLL;
if (addr & 1) event = I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED;
else event = I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED;
while (I2C_CheckEvent(I2C1, event) && timeout--) {
while ((I2C_CheckEvent(I2C1, event) == NoREADY) && timeout--) {
if (I2C_GetFlagStatus(I2C1, I2C_FLAG_AF)) {
found = 0;
break;
}
}
if (!timeout) {
found = 0;
}
// reset flags; it might be in a fucked state
I2C1->STAR1 = 0;
// send a stop to make sure anything listening knows to stfu
I2C_GenerateSTOP(I2C1, ENABLE);
// reset flags; it might be in a fucked state
if (!found) {
I2C1->STAR1 = 0;
return 0;
}

View File

@ -19,7 +19,7 @@ int8_t i2c_write_addr1b(uint8_t addr, uint8_t reg, const uint8_t *data, uint8_t
uint8_t i2c_read_reg_8b(uint8_t addr, uint8_t reg);
void i2c_write_reg_8b(uint8_t addr, uint8_t reg, const uint8_t dat);
uint8_t i2c_addr_scan(uint8_t addr);
int8_t i2c_addr_scan(uint8_t addr);

View File

@ -520,23 +520,23 @@ void led_rgb_4_typing(uint8_t preview, uint8_t tick)
if (typing_fadeout >= 3) typing_fadeout--;
else typing_fadeout = 0;
if (!preview || (i == 4) || (((preview & 0xf) == 4) && i >= 5)) {
for (j = 0; j < 3; j++) {
s = rgb[8][j];
s *= typing_fadeout;
rgb[8][j] = s >> 8;
}
}
w = ((preview & 0xf) == 4) ? 5 : 0;
for (i = w; i < 8; i++) {
rgb[i][0] = rgb[8][0];
rgb[i][1] = rgb[8][1];
rgb[i][2] = rgb[8][2];
// always do O character
for (j = 0; j < 3; j++) {
s = rgb[4][j];
s *= typing_fadeout;
rgb[8][j] = s >> 8;
}
if (!preview) {
w = ((preview & 0xf) == 4) ? 5 : 0;
for (i = w; i < 9; i++) {
rgb[i][0] = rgb[4][0];
rgb[i][1] = rgb[4][1];
rgb[i][2] = rgb[4][2];
}
// cursor
s = cursor[color];
s *= typing_fadeout;
cursor[color] = s >> 8;

View File

@ -324,12 +324,16 @@ static void ui_cursor_flash()
case MODE_PROGRAM: {
// cursor is on if this program is flagged as on
cursor[0] = (userconf.ledprog_ena_mask & (1 << preview_idx)) ? 127 : 0;
cursor[1] = 0;
cursor[2] = 0;
break;
}
case MODE_PARAMETER: {
// cursor is on when program is being edited
cursor[0] = rgb_prog_is_editing ? 127 : 0;
cursor[1] = 0;
cursor[2] = 0;
break;
}
@ -525,7 +529,7 @@ void ui_render()
config_save_timer = UI_CONF_SAVE_TIMEOUT;
// rapidly flash lsens
if ((tick >> 3) & 1) {
if ((tick & 0x7) == 0) {
GPIOD->OUTDR ^= GPIO_Pin_0;
}
@ -569,7 +573,7 @@ void ui_render()
config_save_timer = UI_CONF_SAVE_TIMEOUT;
// slowly flash lsnes
if ((tick >> 5) & 1) {
if ((tick & 0x20) == 0) {
GPIOD->OUTDR ^= GPIO_Pin_0;
}