diff --git a/README.md b/README.md index 5e105c9..5db2eae 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ individual MCU core bugs, quirks and omission are in each MCU's code directory. - when removing from a badge, pulling on the nametag from the non-soldered-pin side can damage the addon. this was a known issue going into this project. with the help of tape and passing on knowledge I hope people don't destroy their addons. - to fix this would be to design my own oled board that is attached at both sides strongly. - ...but the intent was to have a kit to solder. - - ...but with how complicated this is, I am not sure it should be a kit. I dunno.f + - ...but with how complicated this is, I am not sure it should be a kit. I dunno. - the GAT header was accidentally implemented mirrored. I always quadruple-check things like this but being rushed not only on this project but on several others means this still got missed. - to fix this, future runs would have this redesigned. - BLE may or may not ever work. it was a longshot dream when starting the project. if you want to get it working, solder a wire to the pad next to the "SUPERCON" text and give it a try... by writing the code to make it work, lol. \ No newline at end of file diff --git a/nametag8_CH592/user/hw/ch32sub.c b/nametag8_CH592/user/hw/ch32sub.c index c0b7c95..f8b281a 100644 --- a/nametag8_CH592/user/hw/ch32sub.c +++ b/nametag8_CH592/user/hw/ch32sub.c @@ -118,10 +118,6 @@ void ch32sub_init() ch32sub_write_1b(REG_INTR_FLAGS_CLEAR, 0xff); } -void ch32sub_rgb_hwen(uint8_t en) -{ - ch32sub_write_1b(REG_RGB_HWEN, en); -} void ch32sub_intr_defaults() { @@ -140,3 +136,18 @@ void ch32sub_intr_defaults() dat[0] = INT_BTN | INT_UTX_DONE | INT_UTX_TIMEOUT | INT_UTX_ERROR | INT_URX_RCVD; ch32sub_write_1b(REG_INTR_ENABLE, dat[0]); } + + +void ch32sub_set_rgb_hwen(uint8_t en) +{ + ch32sub_write_1b(REG_RGB_HWEN, en); +} + +uint16_t ch32sub_get_ver() +{ + uint8_t dat[2]; + + ch32sub_read(REG_VER_HI, dat, 2); + + return dat[0] << 8 | dat[1]; +} diff --git a/nametag8_CH592/user/hw/ch32sub.h b/nametag8_CH592/user/hw/ch32sub.h index da532d2..11b4f3e 100644 --- a/nametag8_CH592/user/hw/ch32sub.h +++ b/nametag8_CH592/user/hw/ch32sub.h @@ -39,7 +39,8 @@ enum ch32sub_regmap { // read-only REG_INTR_FLAGS = 0x00, - REG_RSVD_01, + REG_VER_HI, + REG_VER_LO, REG_BTN_PUSHED_LATCHED, // buttons currently pushed. REG_BTN_PUSHED, // buttons pushed. reading will clear this value. REG_BTN_HELD, // buttons currently being held. reading will clear this value. @@ -49,7 +50,6 @@ enum ch32sub_regmap { REG_BTN3_MASK, REG_BTN4_MASK, REG_BTN5_MASK, - REG_WERR_HI = 0x0c, // write error count, high byte REG_WERR_LO, // write error count, low byte REG_IRDA_READ_HI, // IrDA read packet length, hi byte (currently always 0) @@ -113,7 +113,11 @@ void ch32sub_write(uint16_t reg, uint8_t *dat, uint8_t len); void ch32sub_write_1b(uint16_t reg, uint8_t dat); void ch32sub_intr_defaults(); -void ch32sub_rgb_hwen(uint8_t en); + +void ch32sub_set_rgb_hwen(uint8_t en); +uint16_t ch32sub_get_ver(); + + diff --git a/nametag8_CH592/user/main.c b/nametag8_CH592/user/main.c index 464a623..ce25a60 100644 --- a/nametag8_CH592/user/main.c +++ b/nametag8_CH592/user/main.c @@ -67,7 +67,7 @@ -const uint8_t vers[] = "241026b"; +const uint8_t vers[] = "241028a"; uint32_t cpu_use = 0; uint32_t cpu_max = 0; @@ -296,7 +296,7 @@ void lowprio_task() { flags_lo &= ~FLAG_CH32V_RESEND_CONF; ch32sub_intr_defaults(); btn_commit_hold(); - ch32sub_rgb_hwen(1); + ch32sub_set_rgb_hwen(1); } else { // send button holds any time the orientation of the OLED changes if (sysflags & SYS_OLED_ROTATE_CHANGED) { @@ -377,7 +377,7 @@ int main() uconf_load(); // read the user config ch32sub_init(); // initialize aux MCU - ch32sub_rgb_hwen(1); // and enable RGBLED controller hardware pin so the controller can wake up + ch32sub_set_rgb_hwen(1); // and enable RGBLED controller hardware pin so the controller can wake up tinymt32_init(&tinymt32_s, 1337); // let's get random diff --git a/nametag8_CH592/user/ui/menu6_about.c b/nametag8_CH592/user/ui/menu6_about.c index 49be0f3..c10a93a 100644 --- a/nametag8_CH592/user/ui/menu6_about.c +++ b/nametag8_CH592/user/ui/menu6_about.c @@ -35,7 +35,7 @@ #define LI_ACCELEROMETER 5 #define LI_CPU_USAGE 6 #define LI_MISC_STATS 7 -#define LI_ERROR_COUNTERS 8 +#define LI_OTHER_INFO 8 #define LI_FONT_GLYPH_TEST 9 @@ -116,6 +116,7 @@ __HIGH_CODE void menu_6_disp(uint8_t idx) { uint8_t i; + uint16_t ver; char txt[30]; const uint8_t led_pos[4][2] = { @@ -289,9 +290,9 @@ void menu_6_disp(uint8_t idx) break; } - case LI_ERROR_COUNTERS: { // error counters + case LI_OTHER_INFO: { // was error counters ssd1306fb_set_cursor(10, -1); - ssd1306fb_draw_str(font_DejaVu_Sans_Mono_Bold_11, "Error Counters", 1); + ssd1306fb_draw_str(font_DejaVu_Sans_Mono_Bold_11, "Other Info", 1); /* ssd1306fb_set_cursor(10, 10); @@ -311,6 +312,16 @@ void menu_6_disp(uint8_t idx) ssd1306fb_draw_str(font_Dialog_plain_8, txt, 0); */ + ver = ch32sub_get_ver(); + + ssd1306fb_set_cursor(10, 24); + ssd1306fb_draw_str(font_Dialog_plain_8, "sub MCU fw v", 0); + sprintf(txt, "%d", ver >> 8); + ssd1306fb_draw_str(font_Dialog_plain_8, txt, 0); + ssd1306fb_draw_str(font_Dialog_plain_8, ".", 0); + sprintf(txt, "%d", ver & 0xff); + ssd1306fb_draw_str(font_Dialog_plain_8, txt, 0); + break; } case LI_FONT_GLYPH_TEST: { diff --git a/nametag8_V003/README.md b/nametag8_V003/README.md new file mode 100644 index 0000000..cd29a32 --- /dev/null +++ b/nametag8_V003/README.md @@ -0,0 +1,27 @@ +# GAT Nametag SC8 CH32V003 Firmware + +sub mcu firmware for the GAT Nametag originally shown at Supercon 8. + +responsible for doing things the main micro can't due to layout or other reasons, such as user button I/O, accelerometer interrupt, and hardware enable for the RGBLED controller. + +the sub MCU is on the bottom board. to use a debugger to debug or program, connect to the SWO pin. with the nametag upright, this pin is the top left pad near the side button. + +there is no workable bootloader yet present so a WCH-LinkE is required to update firmware. I hope to have time to work on i2c slave bootloader at or after Supercon 8. + + +## building + +This is a MounRiver Studio project. Build in MRS. + + +## bugs, quirks, omissions + +- this really isn't an appropriate MCU for this. it can't wakeup on i2c from a low power / oscillator off state, so no matter what this thing pisses away at least 1mA. + - for i2c to work at the speeds we're running, 8MHz clock is minimum. ~1-2mA. + - this MCU was chosen due to it being available and using the same toolchain as the main MCU. + - if proper sleep mode is implemented then power could be saved, with this MCU being the first to wake up then telling master to wake up. but it doesn't help active mode consumption. + - this MCU model is a "popular" thing right now, being called the 10 cent MCU even though it's never available for that price. but people love popularity and cheap shit so meh. + +- i2c slave code was mostly lifted from ch32v003fun I think, but adapted for my use + +- things mostly just worked OK on this board. \ No newline at end of file diff --git a/nametag8_V003/user/i2c_slave.c b/nametag8_V003/user/i2c_slave.c index b719cc3..2e4fcca 100644 --- a/nametag8_V003/user/i2c_slave.c +++ b/nametag8_V003/user/i2c_slave.c @@ -147,7 +147,7 @@ void i2cs_read_cb(uint16_t reg) } } -void i2cs_init(uint8_t address, uint8_t read_only_mode) +void i2cs_init(uint8_t address, uint8_t read_only_mode, uint16_t ver) { I2C_InitTypeDef i2c = {0}; @@ -158,6 +158,9 @@ void i2cs_init(uint8_t address, uint8_t read_only_mode) i2cs_state.read_callback = i2cs_read_cb; i2cs_state.read_only = read_only_mode; + i2cs_reg[REG_VER_HI] = ver >> 8; + i2cs_reg[REG_VER_LO] = ver & 0xff; + i2c.I2C_ClockSpeed = 600000; i2c.I2C_Mode = I2C_Mode_I2C; i2c.I2C_DutyCycle = I2C_DutyCycle_2; diff --git a/nametag8_V003/user/i2c_slave.h b/nametag8_V003/user/i2c_slave.h index 4e8816c..d88ecae 100644 --- a/nametag8_V003/user/i2c_slave.h +++ b/nametag8_V003/user/i2c_slave.h @@ -23,7 +23,8 @@ enum i2cs_werr { enum ch32sub_regmap { // read-only REG_INTR_FLAGS = 0x00, - REG_RSVD_01, + REG_VER_HI, + REG_VER_LO, REG_BTN_PUSHED_LATCHED, // buttons currently pushed. REG_BTN_PUSHED, // buttons pushed. reading will clear this value. REG_BTN_HELD, // buttons currently being held. reading will clear this value. @@ -33,7 +34,6 @@ enum ch32sub_regmap { REG_BTN3_MASK, REG_BTN4_MASK, REG_BTN5_MASK, - REG_WERR_HI = 0x0c, // write error count, high byte REG_WERR_LO, // write error count, low byte REG_IRDA_READ_HI, // IrDA read packet length, hi byte (currently always 0) @@ -105,7 +105,7 @@ extern volatile uint8_t i2cs_reg[256*3]; -void i2cs_init(uint8_t address, uint8_t read_only_mode); +void i2cs_init(uint8_t address, uint8_t read_only_mode, uint16_t ver); void i2cs_append_flag(uint8_t flag); diff --git a/nametag8_V003/user/main.c b/nametag8_V003/user/main.c index 13aabc6..f5ecd25 100644 --- a/nametag8_V003/user/main.c +++ b/nametag8_V003/user/main.c @@ -26,6 +26,11 @@ +#define VER_HI 0 +#define VER_LO 1 + + + static inline void gpio_init() { GPIO_InitTypeDef gpio = {0}; @@ -132,7 +137,7 @@ int main(void) gpio_init(); // get i2c up and running - i2cs_init(INT_I2C_ADDR, 0); + i2cs_init(INT_I2C_ADDR, 0, ((VER_HI << 8) | (VER_LO & 0xff))); // configure various external peripherals btn_init();