moved state to global
This commit is contained in:
parent
32cd24b5c8
commit
440ef14ac1
@ -163,13 +163,13 @@ static uint8_t u8x8_byte_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *a
|
|||||||
|
|
||||||
u8g2_t* display_init(void)
|
u8g2_t* display_init(void)
|
||||||
{
|
{
|
||||||
#if defined(SSD1306_128X32) && SSD1306_128X32
|
#if SSD1306_128X32
|
||||||
u8g2_Setup_ssd1306_i2c_128x32_univision_f(&u8g2, U8G2_R0, u8x8_byte_i2c, u8x8_gpio_and_delay);
|
u8g2_Setup_ssd1306_i2c_128x32_univision_f(&u8g2, U8G2_R0, u8x8_byte_i2c, u8x8_gpio_and_delay);
|
||||||
#elif defined(SSD1312_96X16) && SSD1312_96X16
|
#elif SSD1312_96X16
|
||||||
// NOTE: display size is wrong, hardware is 96x16, but driver is configured for 120x28
|
// NOTE: display size is wrong, hardware is 96x16, but driver is configured for 120x28
|
||||||
u8g2_Setup_ssd1312_i2c_128x32_f(&u8g2, U8G2_R0, u8x8_byte_i2c, u8x8_gpio_and_delay);
|
u8g2_Setup_ssd1312_i2c_128x32_f(&u8g2, U8G2_R0, u8x8_byte_i2c, u8x8_gpio_and_delay);
|
||||||
#else
|
#else
|
||||||
static_assert(0, "unsupported display size");
|
static_assert(0, "unsupported display");
|
||||||
#endif
|
#endif
|
||||||
// TODO: log errors and return NULL on failure
|
// TODO: log errors and return NULL on failure
|
||||||
u8g2_InitDisplay(&u8g2);
|
u8g2_InitDisplay(&u8g2);
|
||||||
|
|||||||
30
fw/main.c
30
fw/main.c
@ -14,12 +14,20 @@
|
|||||||
#include "coroutine.h"
|
#include "coroutine.h"
|
||||||
|
|
||||||
|
|
||||||
// constants
|
/* ------------------------------ Global State ------------------------------ */
|
||||||
u8g2_t *u8g2;
|
u8g2_t *u8g2; // Display state
|
||||||
int16_t encoder = 0; // rotary encoder counter
|
int16_t encoder; // Rotary encoder counter
|
||||||
uint32_t last_interrupt = 0; // last time the encoder interrupt was triggered
|
struct pd_profile_t pd_profile; // USB Power Delivery profile
|
||||||
struct pd_profile_t pd_profile;
|
uint16_t vcc_mv = 3300; // Logic (and analog) voltage
|
||||||
uint16_t vcc_mv = 3300;
|
uint16_t tip_mv; // Tip amplifier reading in mV
|
||||||
|
uint16_t tip_temp_c; // Converted tip temperature in degrees C
|
||||||
|
int16_t temp_c; // Board temperature in degrees C
|
||||||
|
uint16_t vbus_mv; // USB bus voltage in mV
|
||||||
|
uint16_t current_ma; // USB bus current to the heater in mA
|
||||||
|
uint16_t power; // Current power provided to the heater
|
||||||
|
uint16_t duty; // Current mosfet driver duty cycle (0-100%)
|
||||||
|
bool pwm = false; // PWM status (on-off)
|
||||||
|
bool enabled = false; // Power electronics enabled
|
||||||
|
|
||||||
|
|
||||||
// convert the raw TPA191 adc reading to a current in milliamps
|
// convert the raw TPA191 adc reading to a current in milliamps
|
||||||
@ -449,10 +457,6 @@ __attribute__((noreturn)) int main(void)
|
|||||||
// No Power Delivery, maybe we are attached to a computer, so poll the input
|
// No Power Delivery, maybe we are attached to a computer, so poll the input
|
||||||
poll_input();
|
poll_input();
|
||||||
|
|
||||||
static uint16_t vcc_mv = 3300;
|
|
||||||
static u16 tip_mv, tip_temp_c;
|
|
||||||
static s16 temp_c;
|
|
||||||
|
|
||||||
adc_injection_conversion();
|
adc_injection_conversion();
|
||||||
|
|
||||||
temp_c = I16_FP_EMA_K4(temp_c, get_temp_c(adc_buffer[2]));
|
temp_c = I16_FP_EMA_K4(temp_c, get_temp_c(adc_buffer[2]));
|
||||||
@ -498,18 +502,12 @@ __attribute__((noreturn)) int main(void)
|
|||||||
u8g2_ClearBuffer(u8g2);
|
u8g2_ClearBuffer(u8g2);
|
||||||
u8g2_SetFont(u8g2, u8g2_font_5x8_tr);
|
u8g2_SetFont(u8g2, u8g2_font_5x8_tr);
|
||||||
|
|
||||||
static bool pwm = false; // PWM status
|
|
||||||
static bool enabled = false; // Power electronics enabled
|
|
||||||
static uint8_t count = 0; // Loop cycles with PWM on
|
static uint8_t count = 0; // Loop cycles with PWM on
|
||||||
static s32 elapsed = 0;
|
static s32 elapsed = 0;
|
||||||
static bool prev_btn = true;
|
static bool prev_btn = true;
|
||||||
bool btn = funDigitalRead(PIN_BTN);
|
bool btn = funDigitalRead(PIN_BTN);
|
||||||
|
|
||||||
if (has_pd) {
|
if (has_pd) {
|
||||||
static uint16_t vbus_mv, current_ma;
|
|
||||||
static int16_t temp_c, tip_temp_c;
|
|
||||||
static uint16_t power;
|
|
||||||
static uint16_t duty;
|
|
||||||
vbus_mv = U16_FP_EMA_K4(vbus_mv, ((u32)adc_buffer[0]*vcc_mv*11)/4096);
|
vbus_mv = U16_FP_EMA_K4(vbus_mv, ((u32)adc_buffer[0]*vcc_mv*11)/4096);
|
||||||
current_ma = U16_FP_EMA_K4(current_ma, get_current_ma(adc_buffer[1]));
|
current_ma = U16_FP_EMA_K4(current_ma, get_current_ma(adc_buffer[1]));
|
||||||
temp_c = I16_FP_EMA_K4(temp_c, get_temp_c(adc_buffer[2]));
|
temp_c = I16_FP_EMA_K4(temp_c, get_temp_c(adc_buffer[2]));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user