small cleanup and fixes
This commit is contained in:
parent
2eda3f2ebb
commit
25dc735560
|
@ -4,21 +4,19 @@
|
|||
* main MCU firmware
|
||||
* 2024 true
|
||||
*
|
||||
* much of this code is copied from true's DC29 Whiskey Pirates badge,
|
||||
* which was in turn copied from the original GAT Nametag.
|
||||
* Hastily designed and rushed to completion for Supercon 8 on Nov 1, 2024.
|
||||
*
|
||||
* The original GAT Nametag used an 8-bit 8051 core MCU.
|
||||
* Original code was hastily ported to the WP DC29 minibadge.
|
||||
* This code is again hastily ported, and is based on the DC29 minibadge codebase.
|
||||
* this is why things are so convoluted.
|
||||
*
|
||||
* The GAT Nametag used an 8-bit 8051 core MCU.
|
||||
* DC29 minibadge used a RISC-V core, and code was hastily ported.
|
||||
* this is why things like the menu system are so convoluted;
|
||||
*
|
||||
* the main MCU is responsible for the following:
|
||||
* - rendering OLED UI
|
||||
* - rendering LED programs
|
||||
* - storing fonts
|
||||
* - communicating with I2C devices, including:
|
||||
* - oled display, accelerometer
|
||||
* - eeprom, sub MCU, RGBLED controller
|
||||
* - implementing USB interface
|
||||
* - rendering OLED UI, LED programs
|
||||
* - storing fonts in flash
|
||||
* - communicating with I2C devices. includes oled, accelerometer, eeprom, sub MCU, RGBLED
|
||||
* - implementing USB interface (once I get time)
|
||||
* - implementing BLE (maybe)
|
||||
*
|
||||
*/
|
||||
|
@ -43,6 +41,7 @@
|
|||
#include "user_config.h"
|
||||
|
||||
|
||||
|
||||
// global settings
|
||||
#define OLED_UPDATE_RATE 13 // framerate of OLED; { (256*(8/8)) / OLED_UPDATE_RATE }; 13 = 19FPS, 15 = 17FPS
|
||||
|
||||
|
@ -57,7 +56,7 @@
|
|||
// this was checked with a stopwatch and is close enough
|
||||
// this value IS FRAMERATE DEPENDENT for some reason... figure it out later
|
||||
|
||||
const uint8_t vers[] = "241026a";
|
||||
const uint8_t vers[] = "241026b";
|
||||
|
||||
uint32_t cpu_use = 0;
|
||||
uint32_t cpu_max = 0;
|
||||
|
@ -91,10 +90,13 @@ void ch59x_xtal_conf()
|
|||
|
||||
/*
|
||||
* the CPU will change clockspeed depending on what it is doing.
|
||||
* all timers are tied to system clock and cannot be derived from the crystal directly,
|
||||
* except for RTC which can use the LSI. RTC also has a neat feature where it can
|
||||
* trigger an interrupt when bits match a mask. at this time we're not using the RTC
|
||||
* for anything else so putting RTC should suffice for our main tick interrupt.
|
||||
* all hardware timers are tied to system clock and cannot be derived from
|
||||
* the crystal directly. so we can't rely on timers or systick for timing.
|
||||
*
|
||||
* this leaves the RTC as the only periodic interrupt source which uses LSI clk.
|
||||
* RTC has the capability to trigger an interrupt when count bits match a mask.
|
||||
* we're not using the RTC for anything else, so RTC interrupt should suffice
|
||||
* for our main tick interrupt.
|
||||
*/
|
||||
__HIGH_CODE
|
||||
void rtc_reset_trig()
|
||||
|
@ -125,6 +127,9 @@ void rtcisr_init()
|
|||
PFIC_EnableIRQ(RTC_IRQn);
|
||||
}
|
||||
|
||||
/*
|
||||
* used only for rough cpu usage calculation stuff
|
||||
*/
|
||||
void systick_init(void)
|
||||
{
|
||||
SysTick->CNT = 0; // clear counter
|
||||
|
|
|
@ -170,13 +170,13 @@ void menu_1_name_edit()
|
|||
char txt[10];
|
||||
|
||||
ssd1306fb_set_cursor(10, 8);
|
||||
ssd1306fb_draw_str(font_table[1].font, uconf.name, 0);
|
||||
ssd1306fb_draw_str(font_DejaVu_Sans_Mono_Bold_11, uconf.name, 0);
|
||||
|
||||
ssd1306fb_draw_circle(oled.cursor_x + 4, oled.cursor_y + 7, (mtick & 0x04) ? 2 : 1);
|
||||
|
||||
// draw underline
|
||||
if (edit_mode == EDIT_MODE_IDLE || (edit_mode == EDIT_MODE_EDIT && (mtick & 0x08))) {
|
||||
x = font_table[1].font[FONT_WIDTH_POS];
|
||||
x = font_DejaVu_Sans_Mono_Bold_11[FONT_WIDTH_POS];
|
||||
w = x - 1;
|
||||
|
||||
x *= edit_pos;
|
||||
|
@ -316,10 +316,10 @@ MENU_0_FONT:
|
|||
}
|
||||
}
|
||||
|
||||
w = ssd1306fb_get_str_width(font_table[1].font, txt, strlen(txt), 1);
|
||||
w = ssd1306fb_get_str_width(font_DejaVu_Sans_Mono_Bold_11, txt, strlen(txt), 1);
|
||||
x = 68 - (w >> 1);
|
||||
ssd1306fb_set_cursor(x, 18);
|
||||
ssd1306fb_draw_str(font_table[1].font, txt, 1);
|
||||
ssd1306fb_draw_str(font_DejaVu_Sans_Mono_Bold_11, txt, 1);
|
||||
|
||||
// draw box
|
||||
ssd1306fb_draw_rect(x - 2, 18, x + w + 2, 31);
|
||||
|
|
|
@ -91,17 +91,17 @@ void menu_5_disp(uint8_t idx)
|
|||
break;
|
||||
}
|
||||
case LI_FACTORY_RESET: {
|
||||
// todo: implement manual button checking here
|
||||
// todo: implement manual button checking here after getting button orientation code working
|
||||
// yes, this means reset speed depends on framerate lol
|
||||
if (factory_reset >= 32) {
|
||||
// do the factory reset
|
||||
uconf_defaults();
|
||||
// todo: reboot?
|
||||
}
|
||||
|
||||
ssd1306fb_draw_str(font_table[0].font, "Hold Set to Factory Reset...", 0);
|
||||
//ssd1306fb_set_color(SSD1306_STATE_CLR_PIXEL);
|
||||
//ssd1306fb_draw_rect_fill(50, 18, 86, 31);
|
||||
//ssd1306fb_set_color(SSD1306_STATE_SET_PIXEL);
|
||||
txt[0] = 0;
|
||||
|
||||
ssd1306fb_draw_rect(50, 18, 86, 31);
|
||||
for (w = 0; w < (factory_reset >> 1); w++) {
|
||||
ssd1306fb_draw_vline(50 + w, 18, 31);
|
||||
|
|
|
@ -44,7 +44,7 @@ void uconf_defaults()
|
|||
if (uconf_flash_offset == 0xf0) {
|
||||
uconf.iter = 0;
|
||||
}
|
||||
uconf.font_idx = 4;
|
||||
uconf.font_idx = 5;
|
||||
uconf.char_spacing = 2;
|
||||
uconf.y_offset = 0;
|
||||
|
||||
|
|
Loading…
Reference in New Issue