Stable enough ADC

This commit is contained in:
Ben V. Brown
2022-04-19 22:23:48 +10:00
parent f397e49533
commit 25283e434f
10 changed files with 404 additions and 382 deletions

View File

@@ -23,19 +23,15 @@ void resetWatchdog() {
uint16_t getHandleTemperature(uint8_t sample) {
// We return the current handle temperature in X10 C
// TMP36 in handle, 0.5V offset and then 10mV per deg C (0.75V @ 25C for
// example) STM32 = 4096 count @ 3.3V input -> But We oversample by 32/(2^2) =
// 8 times oversampling Therefore 32768 is the 3.3V input, so 0.1007080078125
// mV per count So we need to subtract an offset of 0.5V to center on 0C
// (4964.8 counts)
//
int32_t result = getADCHandleTemp(sample);
result -= 4965; // remove 0.5V offset
result -= 10240; // remove 0.5V offset
// 10mV per C
// 99.29 counts per Deg C above 0C
result *= 100;
result /= 993;
// 204.7 counts per Deg C above 0C
result *= 10;
result /= 205;
if (result < 0) {
result = 0;
}
return result;
}
@@ -47,7 +43,6 @@ uint16_t getInputVoltageX10(uint16_t divisor, uint8_t sample) {
}
void unstick_I2C() {
MSG((char *)"I2C Unstick\r\n");
/* configure SDA/SCL for GPIO */
// GPIO_BC(GPIOB) |= SDA_Pin | SCL_Pin;
// gpio_init(SDA_GPIO_Port, GPIO_MODE_OUT_OD, GPIO_OSPEED_50MHZ, SDA_Pin | SCL_Pin);

View File

@@ -8,7 +8,7 @@
#include "IRQ.h"
#include "Pins.h"
#include "configuration.h"
#include "expMovingAverage.h"
#include "history.hpp"
extern "C" {
#include "bflb_platform.h"
@@ -21,14 +21,15 @@ extern "C" {
#include "hal_timer.h"
}
#define ADC_Filter_Weight 32
expMovingAverage<uint16_t, ADC_Filter_Weight> ADC_Vin;
expMovingAverage<uint16_t, ADC_Filter_Weight> ADC_Temp;
expMovingAverage<uint16_t, ADC_Filter_Weight> ADC_Tip;
#define ADC_Filter_Smooth 4
history<uint16_t, ADC_Filter_Smooth> ADC_Vin;
history<uint16_t, ADC_Filter_Smooth> ADC_Temp;
history<uint16_t, ADC_Filter_Smooth> ADC_Tip;
void adc_fifo_irq(void) {
if (ADC_GetIntStatus(ADC_INT_FIFO_READY) == SET) {
ADC_IntClr(ADC_INT_FIFO_READY);
// Read out all entries in the fifo
const uint8_t cnt = ADC_Get_FIFO_Count();
@@ -47,41 +48,26 @@ void adc_fifo_irq(void) {
case VIN_ADC_CHANNEL:
ADC_Vin.update(sample);
break;
case 0: // 0 turns up when an invalid reading is taken
break;
default:
// MSG((char *)"ADC Invalid chan %d\r\n", source);
MSG((char *)"ADC Invalid chan %d\r\n", source);
break;
}
}
// MSG((char *)"ADC Reading %d %d %d\r\n", ADC_Temp.average(), ADC_Vin.average(), ADC_Tip.average());
MSG((char *)"ADC Reading %d %d %d\r\n", ADC_Temp.average(), ADC_Vin.average(), ADC_Tip.average());
// Clear IRQ
ADC_IntClr(ADC_INT_FIFO_READY);
}
}
const ADC_Chan_Type adc_tip_pos_chans[] = {TIP_TEMP_ADC_CHANNEL};
const ADC_Chan_Type adc_tip_neg_chans[] = {ADC_CHAN_GND};
static_assert(sizeof(adc_tip_pos_chans) == sizeof(adc_tip_neg_chans));
// TODO Do we need to do the stop+start here or can we hot-write the config
void start_adc_tip(void) {
// Reconfigure the ADC to measure the tip temp
// Single channel input mode
// The ADC has a 32 sample FiFo; we set this up to fire and interrupt at 16 samples
// Then using that IRQ to know that sampling is done and can be stored
ADC_Stop();
ADC_Scan_Channel_Config(adc_tip_pos_chans, adc_tip_neg_chans, 1, ENABLE);
ADC_Start();
}
const ADC_Chan_Type adc_misc_pos_chans[] = {TMP36_ADC_CHANNEL, VIN_ADC_CHANNEL};
const ADC_Chan_Type adc_misc_neg_chans[] = {ADC_CHAN_GND, ADC_CHAN_GND};
static_assert(sizeof(adc_misc_pos_chans) == sizeof(adc_misc_neg_chans));
void start_adc_misc(void) {
// Reconfigure the ADC to measure all other inputs in scan mode when we are not measuring the tip
ADC_Stop();
ADC_Scan_Channel_Config(adc_misc_pos_chans, adc_misc_neg_chans, 2, ENABLE);
ADC_Start();
}
void stop_adc(void) {}
static bool fastPWM;
static void switchToSlowPWM(void);
@@ -102,7 +88,6 @@ void timer0_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t
// Used to turn tip off at set point in cycle
PWM_Channel_Disable(PWM_Channel);
} else if (state == TIMER_EVENT_COMP2) {
start_adc_misc();
// This occurs at timer rollover, so if we want to turn on the output PWM; we do so
if (PWMSafetyTimer) {
PWMSafetyTimer--;
@@ -181,10 +166,8 @@ extern osThreadId POWTaskHandle;
void GPIO_IRQHandler(void) {
if (SET == GLB_Get_GPIO_IntStatus(FUSB302_IRQ_GLB_Pin)) {
GLB_GPIO_IntClear(FUSB302_IRQ_GLB_Pin, SET);
MSG((char *)"GPIO IRQ FUSB\r\n");
#if POW_PD
if (POWTaskHandle != nullptr) {
MSG((char *)"Wake FUSB\r\n");
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xTaskNotifyFromISR(POWTaskHandle, 1, eSetBits, &xHigherPriorityTaskWoken);
/* Force a context switch if xHigherPriorityTaskWoken is now set to pdTRUE.
@@ -215,13 +198,14 @@ bool getFUS302IRQLow() {
// return (RESET == gpio_input_bit_get(FUSB302_IRQ_GPIO_Port, FUSB302_IRQ_Pin));
}
uint16_t rescaleADC(const uint16_t value) {
// return value;
uint32_t temp = value * 33;
uint16_t res = temp / 32;
return res;
}
uint16_t getADCHandleTemp(uint8_t sample) { return rescaleADC(ADC_Temp.average() >> 1); }
uint16_t getADCHandleTemp(uint8_t sample) { return ADC_Temp.average(); }
uint16_t getADCVin(uint8_t sample) { return rescaleADC(ADC_Vin.average() >> 1); }
uint16_t getADCVin(uint8_t sample) { return ADC_Vin.average(); }
// Returns either average or instant value. When sample is set the samples from the injected ADC are copied to the filter and then the raw reading is returned
uint16_t getTipRawTemp(uint8_t sample) { return rescaleADC(ADC_Tip.average() >> 2); }
uint16_t getTipRawTemp(uint8_t sample) { return rescaleADC(ADC_Tip.average() >> 1); }

View File

@@ -12,7 +12,6 @@
#ifdef POW_QC
void QC_DPlusZero_Six() {
// pull down D+
// #TODO
gpio_write(QC_DP_LOW_Pin, 0);
}
void QC_DNegZero_Six() {

View File

@@ -26,6 +26,9 @@ void hardware_init() {
gpio_set_mode(OLED_RESET_Pin, GPIO_OUTPUT_MODE);
gpio_set_mode(KEY_A_Pin, GPIO_INPUT_PD_MODE);
gpio_set_mode(KEY_B_Pin, GPIO_INPUT_PD_MODE);
gpio_set_mode(TMP36_INPUT_Pin, GPIO_INPUT_MODE);
gpio_set_mode(TIP_TEMP_Pin, GPIO_INPUT_MODE);
gpio_set_mode(VIN_Pin, GPIO_INPUT_MODE);
setup_timer_scheduler();
setup_adc();
@@ -51,6 +54,12 @@ void setup_pwm(void) {
MSG((char *)"PWM Setup returns %d %d\r\n", err, pwm_clk);
PWM_Channel_Disable(PWM_Channel);
}
const ADC_Chan_Type adc_tip_pos_chans[]
= {TIP_TEMP_ADC_CHANNEL, TIP_TEMP_ADC_CHANNEL, TIP_TEMP_ADC_CHANNEL, TIP_TEMP_ADC_CHANNEL, TMP36_ADC_CHANNEL, VIN_ADC_CHANNEL, TMP36_ADC_CHANNEL, VIN_ADC_CHANNEL};
const ADC_Chan_Type adc_tip_neg_chans[] = {ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND};
static_assert(sizeof(adc_tip_pos_chans) == sizeof(adc_tip_neg_chans));
void setup_adc(void) {
MSG((char *)"Setting up ADC\r\n");
//
@@ -67,9 +76,9 @@ void setup_adc(void) {
adc_cfg.inputMode = ADC_INPUT_SINGLE_END;
adc_cfg.v18Sel = ADC_V18_SEL_1P82V;
adc_cfg.v11Sel = ADC_V11_SEL_1P1V;
adc_cfg.gain1 = ADC_PGA_GAIN_NONE;
adc_cfg.gain2 = ADC_PGA_GAIN_NONE;
adc_cfg.chopMode = ADC_CHOP_MOD_AZ_PGA_ON;
adc_cfg.gain1 = ADC_PGA_GAIN_1;
adc_cfg.gain2 = ADC_PGA_GAIN_1;
adc_cfg.chopMode = ADC_CHOP_MOD_AZ_PGA_RPC_ON;
adc_cfg.biasSel = ADC_BIAS_SEL_MAIN_BANDGAP;
adc_cfg.vcm = ADC_PGA_VCM_1V;
adc_cfg.offsetCalibEn = DISABLE;
@@ -80,16 +89,17 @@ void setup_adc(void) {
ADC_Reset();
ADC_Init(&adc_cfg);
adc_fifo_cfg.dmaEn = DISABLE;
adc_fifo_cfg.fifoThreshold = ADC_FIFO_THRESHOLD_16;
adc_fifo_cfg.fifoThreshold = ADC_FIFO_THRESHOLD_8;
ADC_FIFO_Cfg(&adc_fifo_cfg);
ADC_MIC_Bias_Disable();
// Enable FiFo IRQ
MSG((char *)"Int Enable\r\n");
Interrupt_Handler_Register(GPADC_DMA_IRQn, adc_fifo_irq);
ADC_IntMask(ADC_INT_FIFO_READY, UNMASK);
CPU_Interrupt_Enable(GPADC_DMA_IRQn);
MSG((char *)"Start\r\n");
start_adc_misc();
MSG((char *)"Started\r\n");
ADC_Stop();
ADC_Scan_Channel_Config(adc_tip_pos_chans, adc_tip_neg_chans, sizeof(adc_tip_pos_chans) / sizeof(ADC_Chan_Type), DISABLE);
ADC_FIFO_Clear();
}
struct device *timer0;

View File

@@ -105,14 +105,15 @@ static ADC_Gain_Coeff_Type adcGainCoeffCal = {
* @{
*/
/****************************************************************************/ /**
* @brief Software reset the whole ADC
*
* @param None
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief Software reset the whole ADC
*
* @param None
*
* @return None
*
*******************************************************************************/
void ADC_Reset(void) {
uint32_t regCmd;
@@ -123,14 +124,15 @@ void ADC_Reset(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, BL_CLR_REG_BIT(regCmd, AON_GPADC_SOFT_RST));
}
/****************************************************************************/ /**
* @brief ADC glable enable
*
* @param None
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC glable enable
*
* @param None
*
* @return None
*
*******************************************************************************/
void ADC_Enable(void) {
uint32_t tmpVal;
@@ -139,14 +141,15 @@ void ADC_Enable(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, tmpVal);
}
/****************************************************************************/ /**
* @brief ADC glable disable
*
* @param None
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC glable disable
*
* @param None
*
* @return None
*
*******************************************************************************/
void ADC_Disable(void) {
uint32_t tmpVal;
@@ -155,14 +158,15 @@ void ADC_Disable(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, tmpVal);
}
/****************************************************************************/ /**
* @brief ADC normal mode init
*
* @param cfg: ADC normal mode configuration
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC normal mode init
*
* @param cfg: ADC normal mode configuration
*
* @return None
*
*******************************************************************************/
void ADC_Init(ADC_CFG_Type *cfg) {
uint32_t regCfg1;
uint32_t regCfg2;
@@ -230,16 +234,17 @@ void ADC_Init(ADC_CFG_Type *cfg) {
ADC_Gain_Trim();
}
/****************************************************************************/ /**
* @brief ADC normal mode channel config
*
* @param posCh: ADC pos channel type
* @param negCh: ADC neg channel type
* @param contEn: ENABLE or DISABLE continuous mode
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC normal mode channel config
*
* @param posCh: ADC pos channel type
* @param negCh: ADC neg channel type
* @param contEn: ENABLE or DISABLE continuous mode
*
* @return None
*
*******************************************************************************/
void ADC_Channel_Config(ADC_Chan_Type posCh, ADC_Chan_Type negCh, BL_Fun_Type contEn) {
uint32_t regCmd;
uint32_t regCfg1;
@@ -260,17 +265,18 @@ void ADC_Channel_Config(ADC_Chan_Type posCh, ADC_Chan_Type negCh, BL_Fun_Type co
BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG1, regCfg1);
}
/****************************************************************************/ /**
* @brief ADC scan mode channel config
*
* @param posChList[]: ADC pos channel list type
* @param negChList[]: ADC neg channel list type
* @param scanLength: ADC scan length
* @param contEn: ENABLE or DISABLE continuous mode
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC scan mode channel config
*
* @param posChList[]: ADC pos channel list type
* @param negChList[]: ADC neg channel list type
* @param scanLength: ADC scan length
* @param contEn: ENABLE or DISABLE continuous mode
*
* @return None
*
*******************************************************************************/
void ADC_Scan_Channel_Config(const ADC_Chan_Type posChList[], const ADC_Chan_Type negChList[], uint8_t scanLength, BL_Fun_Type contEn) {
uint32_t tmpVal, i;
uint32_t dealLen;
@@ -333,14 +339,15 @@ void ADC_Scan_Channel_Config(const ADC_Chan_Type posChList[], const ADC_Chan_Typ
BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG1, tmpVal);
}
/****************************************************************************/ /**
* @brief ADC normal mode convert start
*
* @param None
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC normal mode convert start
*
* @param None
*
* @return None
*
*******************************************************************************/
void ADC_Start(void) {
uint32_t regCmd;
@@ -357,14 +364,15 @@ void ADC_Start(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, regCmd);
}
/****************************************************************************/ /**
* @brief ADC normal mode convert stop
*
* @param None
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC normal mode convert stop
*
* @param None
*
* @return None
*
*******************************************************************************/
void ADC_Stop(void) {
uint32_t regCmd;
@@ -374,14 +382,15 @@ void ADC_Stop(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, regCmd);
}
/****************************************************************************/ /**
* @brief ADC FIFO configuration
*
* @param fifoCfg: ADC FIFO confifuration pointer
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC FIFO configuration
*
* @param fifoCfg: ADC FIFO confifuration pointer
*
* @return None
*
*******************************************************************************/
void ADC_FIFO_Cfg(ADC_FIFO_Cfg_Type *fifoCfg) {
uint32_t tmpVal;
@@ -407,14 +416,15 @@ void ADC_FIFO_Cfg(ADC_FIFO_Cfg_Type *fifoCfg) {
BL_WR_REG(GPIP_BASE, GPIP_GPADC_CONFIG, tmpVal);
}
/****************************************************************************/ /**
* @brief ADC get DMA FIFO data count
*
* @param None
*
* @return data count in FIFO
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC get DMA FIFO data count
*
* @param None
*
* @return data count in FIFO
*
*******************************************************************************/
uint8_t ADC_Get_FIFO_Count(void) {
uint32_t tmpVal;
@@ -423,14 +433,15 @@ uint8_t ADC_Get_FIFO_Count(void) {
return BL_GET_REG_BITS_VAL(tmpVal, GPIP_GPADC_FIFO_DATA_COUNT);
}
/****************************************************************************/ /**
* @brief ADC get DMA FIFO full status
*
* @param None
*
* @return SET or RESET
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC get DMA FIFO full status
*
* @param None
*
* @return SET or RESET
*
*******************************************************************************/
BL_Sts_Type ADC_FIFO_Is_Full(void) {
uint32_t tmpVal;
@@ -443,14 +454,15 @@ BL_Sts_Type ADC_FIFO_Is_Full(void) {
}
}
/****************************************************************************/ /**
* @brief ADC get DMA FIFO empty status
*
* @param None
*
* @return SET or RESET
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC get DMA FIFO empty status
*
* @param None
*
* @return SET or RESET
*
*******************************************************************************/
BL_Sts_Type ADC_FIFO_Is_Empty(void) {
uint32_t tmpVal;
@@ -463,14 +475,15 @@ BL_Sts_Type ADC_FIFO_Is_Empty(void) {
}
}
/****************************************************************************/ /**
* @brief ADC read DMA FIFO data
*
* @param None
*
* @return ADC result if return 0 that means this is error data,user should ignore this data.
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC read DMA FIFO data
*
* @param None
*
* @return ADC result if return 0 that means this is error data,user should ignore this data.
*
*******************************************************************************/
uint32_t ADC_Read_FIFO(void) {
uint32_t tmpVal;
@@ -479,16 +492,17 @@ uint32_t ADC_Read_FIFO(void) {
return (tmpVal);
}
/****************************************************************************/ /**
* @brief ADC parse result
*
* @param orgVal: Original A to D value
* @param len: Original AD vaule count
* @param result: Final Result array pointer
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC parse result
*
* @param orgVal: Original A to D value
* @param len: Original AD vaule count
* @param result: Final Result array pointer
*
* @return None
*
*******************************************************************************/
void ADC_Parse_Result(uint32_t *orgVal, uint32_t len, ADC_Result_Type *result) {
uint8_t neg = 0;
uint32_t tmpVal1 = 0, tmpVal2 = 0;
@@ -558,15 +572,16 @@ void ADC_Parse_Result(uint32_t *orgVal, uint32_t len, ADC_Result_Type *result) {
}
}
/****************************************************************************/ /**
* @brief ADC mask or unmask certain or all interrupt
*
* @param intType: interrupt type
* @param intMask: mask or unmask
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC mask or unmask certain or all interrupt
*
* @param intType: interrupt type
* @param intMask: mask or unmask
*
* @return None
*
*******************************************************************************/
BL_Mask_Type ADC_IntGetMask(ADC_INT_Type intType) {
uint32_t tmpVal;
@@ -610,15 +625,16 @@ BL_Mask_Type ADC_IntGetMask(ADC_INT_Type intType) {
return 0;
}
/****************************************************************************/ /**
* @brief ADC mask or unmask certain or all interrupt
*
* @param intType: interrupt type
* @param intMask: mask or unmask
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC mask or unmask certain or all interrupt
*
* @param intType: interrupt type
* @param intMask: mask or unmask
*
* @return None
*
*******************************************************************************/
void ADC_IntMask(ADC_INT_Type intType, BL_Mask_Type intMask) {
uint32_t tmpVal;
@@ -745,14 +761,15 @@ void ADC_IntMask(ADC_INT_Type intType, BL_Mask_Type intMask) {
}
}
/****************************************************************************/ /**
* @brief ADC clear certain or all interrupt
*
* @param intType: interrupt type
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC clear certain or all interrupt
*
* @param intType: interrupt type
*
* @return None
*
*******************************************************************************/
void ADC_IntClr(ADC_INT_Type intType) {
uint32_t tmpVal;
@@ -891,14 +908,15 @@ void ADC_IntClr(ADC_INT_Type intType) {
}
}
/****************************************************************************/ /**
* @brief ADC get interrupt status
*
* @param intType: interrupt type
*
* @return SET or RESET
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC get interrupt status
*
* @param intType: interrupt type
*
* @return SET or RESET
*
*******************************************************************************/
BL_Sts_Type ADC_GetIntStatus(ADC_INT_Type intType) {
uint32_t tmpVal;
BL_Sts_Type bitStatus = RESET;
@@ -947,15 +965,16 @@ BL_Sts_Type ADC_GetIntStatus(ADC_INT_Type intType) {
return bitStatus;
}
/****************************************************************************/ /**
* @brief ADC install interrupt callback
*
* @param intType: ADC interrupt type
* @param cbFun: ADC interrupt callback
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC install interrupt callback
*
* @param intType: ADC interrupt type
* @param cbFun: ADC interrupt callback
*
* @return None
*
*******************************************************************************/
void ADC_Int_Callback_Install(ADC_INT_Type intType, intCallback_Type *cbFun) {
/* Check the parameters */
CHECK_PARAM(IS_GPIP_ADC_INT_TYPE(intType));
@@ -963,14 +982,15 @@ void ADC_Int_Callback_Install(ADC_INT_Type intType, intCallback_Type *cbFun) {
adcIntCbfArra[intType] = cbFun;
}
/****************************************************************************/ /**
* @brief ADC DMA interrupt handler
*
* @param None
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC DMA interrupt handler
*
* @param None
*
* @return None
*
*******************************************************************************/
#ifndef BFLB_USE_HAL_DRIVER
void GPADC_DMA_IRQHandler(void) {
if (ADC_GetIntStatus(ADC_INT_POS_SATURATION) == SET) {
@@ -1023,14 +1043,15 @@ void GPADC_DMA_IRQHandler(void) {
}
#endif
/****************************************************************************/ /**
* @brief ADC VBAT enable
*
* @param None
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC VBAT enable
*
* @param None
*
* @return None
*
*******************************************************************************/
void ADC_Vbat_Enable(void) {
uint32_t tmpVal;
@@ -1039,14 +1060,15 @@ void ADC_Vbat_Enable(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal);
}
/****************************************************************************/ /**
* @brief ADC VBAT disable
*
* @param None
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC VBAT disable
*
* @param None
*
* @return None
*
*******************************************************************************/
void ADC_Vbat_Disable(void) {
uint32_t tmpVal;
@@ -1055,14 +1077,15 @@ void ADC_Vbat_Disable(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal);
}
/****************************************************************************/ /**
* @brief ADC TSEN Config
*
* @param tsenMod: None
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC TSEN Config
*
* @param tsenMod: None
*
* @return None
*
*******************************************************************************/
void ADC_Tsen_Init(ADC_TSEN_MOD_Type tsenMod) {
uint32_t tmpVal;
@@ -1118,12 +1141,13 @@ void ADC_Tsen_Init(ADC_TSEN_MOD_Type tsenMod) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, tmpVal);
}
/****************************************************************************/ /**
* @brief ADC TSEN Enable
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC TSEN Enable
*
* @return None
*
*******************************************************************************/
void ADC_Tsen_Enable(void) {
uint32_t tmpVal;
@@ -1132,12 +1156,13 @@ void ADC_Tsen_Enable(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal);
}
/****************************************************************************/ /**
* @brief ADC TSEN Disable
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC TSEN Disable
*
* @return None
*
*******************************************************************************/
void ADC_Tsen_Disable(void) {
uint32_t tmpVal;
@@ -1146,12 +1171,13 @@ void ADC_Tsen_Disable(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal);
}
/****************************************************************************/ /**
* @brief ADC Clear fifo
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC Clear fifo
*
* @return None
*
*******************************************************************************/
void ADC_FIFO_Clear(void) {
uint32_t tmpVal;
@@ -1161,14 +1187,15 @@ void ADC_FIFO_Clear(void) {
BL_WR_REG(GPIP_BASE, GPIP_GPADC_CONFIG, tmpVal);
}
/****************************************************************************/ /**
* @brief config pga
*
* @param pga_vcmi_enable: enable or not vcmi
* @param pga_os_cal: pga os cal value
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief config pga
*
* @param pga_vcmi_enable: enable or not vcmi
* @param pga_os_cal: pga os cal value
* @return None
*
*******************************************************************************/
void ADC_PGA_Config(uint8_t pga_vcmi_enable, uint8_t pga_os_cal) {
uint32_t tmpVal;
@@ -1184,14 +1211,15 @@ void ADC_PGA_Config(uint8_t pga_vcmi_enable, uint8_t pga_os_cal) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal);
}
/****************************************************************************/ /**
* @brief TSEN_Get_V_Error
*
* @param None
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief TSEN_Get_V_Error
*
* @param None
*
* @return None
*
*******************************************************************************/
uint32_t TSEN_Get_V_Error(void) {
uint32_t v0 = 0, v1 = 0;
uint32_t v_error = 0;
@@ -1243,14 +1271,15 @@ uint32_t TSEN_Get_V_Error(void) {
return v_error;
}
/****************************************************************************/ /**
* @brief Trim TSEN
*
* @param tsen_offset: None
*
* @return SUCCESS or ERROR
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief Trim TSEN
*
* @param tsen_offset: None
*
* @return SUCCESS or ERROR
*
*******************************************************************************/
BL_Err_Type ATTR_CLOCK_SECTION ADC_Trim_TSEN(uint16_t *tsen_offset) {
Efuse_TSEN_Refcode_Corner_Type trim;
@@ -1266,14 +1295,15 @@ BL_Err_Type ATTR_CLOCK_SECTION ADC_Trim_TSEN(uint16_t *tsen_offset) {
return ERROR;
}
/****************************************************************************/ /**
* @brief SET ADC TSEN TSVBE LOW/HIGH
*
* @param None
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief SET ADC TSEN TSVBE LOW/HIGH
*
* @param None
*
* @return None
*
*******************************************************************************/
void ADC_SET_TSVBE_LOW(void) {
uint32_t tmpVal;
tmpVal = BL_RD_REG(AON_BASE, AON_GPADC_REG_CONFIG2);
@@ -1281,14 +1311,15 @@ void ADC_SET_TSVBE_LOW(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal);
}
/****************************************************************************/ /**
* @brief SET ADC TSEN TSVBE LOW/HIGH
*
* @param None
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief SET ADC TSEN TSVBE LOW/HIGH
*
* @param None
*
* @return None
*
*******************************************************************************/
void ADC_SET_TSVBE_HIGH(void) {
uint32_t tmpVal;
tmpVal = BL_RD_REG(AON_BASE, AON_GPADC_REG_CONFIG2);
@@ -1296,14 +1327,15 @@ void ADC_SET_TSVBE_HIGH(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal);
}
/****************************************************************************/ /**
* @brief SET ADC TSEN TSVBE LOW/HIGH
*
* @param tsen_offset: tsen_offset form efuse trim data
*
* @return tempture
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief SET ADC TSEN TSVBE LOW/HIGH
*
* @param tsen_offset: tsen_offset form efuse trim data
*
* @return tempture
*
*******************************************************************************/
float TSEN_Get_Temp(uint32_t tsen_offset) {
uint32_t v0 = 0, v1 = 0;
float temp = 0;
@@ -1360,14 +1392,15 @@ float TSEN_Get_Temp(uint32_t tsen_offset) {
return temp;
}
/****************************************************************************/ /**
* @brief ADC MIC Config
*
* @param adc_mic_config: adc_mic_config
*
* @return success or not
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC MIC Config
*
* @param adc_mic_config: adc_mic_config
*
* @return success or not
*
*******************************************************************************/
BL_Err_Type ADC_Mic_Init(ADC_MIC_Type *adc_mic_config) {
uint32_t tmpVal1 = 0, tmpVal2 = 0;
@@ -1404,14 +1437,15 @@ BL_Err_Type ADC_Mic_Init(ADC_MIC_Type *adc_mic_config) {
return SUCCESS;
}
/****************************************************************************/ /**
* @brief ADC MIC bias control
*
* @param None
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC MIC bias control
*
* @param None
*
* @return None
*
*******************************************************************************/
void ADC_MIC_Bias_Enable(void) {
uint32_t tmpVal;
@@ -1420,14 +1454,15 @@ void ADC_MIC_Bias_Enable(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, tmpVal);
}
/****************************************************************************/ /**
* @brief ADC MIC bias control
*
* @param None
*
* @return None
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief ADC MIC bias control
*
* @param None
*
* @return None
*
*******************************************************************************/
void ADC_MIC_Bias_Disable(void) {
uint32_t tmpVal;
@@ -1436,14 +1471,15 @@ void ADC_MIC_Bias_Disable(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, tmpVal);
}
/****************************************************************************/ /**
* @brief Trim ADC Gain
*
* @param None
*
* @return SUCCESS or ERROR
*
*******************************************************************************/
/****************************************************************************/
/**
* @brief Trim ADC Gain
*
* @param None
*
* @return SUCCESS or ERROR
*
*******************************************************************************/
BL_Err_Type ATTR_CLOCK_SECTION ADC_Gain_Trim(void) {
Efuse_ADC_Gain_Coeff_Type trim;
uint32_t tmp;

View File

@@ -268,22 +268,22 @@ void bl_show_info(void) {
MSG("Build:%s,%s\r\n", __TIME__, __DATE__);
MSG("Copyright (c) 2021 Bouffalolab team\r\n");
#if 0
MSG("root clock:%dM\r\n", system_clock_get(SYSTEM_CLOCK_ROOT_CLOCK) / 1000000); /*root clock before f_div*/
#if 1
MSG("root clock:%dM\r\n", system_clock_get(SYSTEM_CLOCK_ROOT_CLOCK) / 1000000); /*root clock before f_div*/
MSG("fclk clock:%dM\r\n", system_clock_get(SYSTEM_CLOCK_FCLK) / 1000000); /*after f_div,this is system core clock*/
MSG("bclk clock:%dM\r\n", system_clock_get(SYSTEM_CLOCK_BCLK) / 1000000);
MSG("fclk clock:%dM\r\n", system_clock_get(SYSTEM_CLOCK_FCLK) / 1000000); /*after f_div,this is system core clock*/
MSG("bclk clock:%dM\r\n", system_clock_get(SYSTEM_CLOCK_BCLK) / 1000000);
MSG("uart clock:%dM\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_UART) / 1000000);
MSG("spi clock:%dM\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_SPI) / 1000000);
MSG("i2c clock:%dM\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_I2C) / 1000000);
MSG("adc clock:%dM\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_ADC) / 1000000);
MSG("dac clock:%dM\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_DAC) / 1000000);
MSG("i2s clock:%dM\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_I2S) / 1000000);
MSG("pwm clock:%dhz\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_PWM));
MSG("cam clock:%dM\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_CAM) / 1000000);
MSG("timer0 clock:%dM\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_TIMER0) / 1000000);
MSG("timer1 clock:%dM\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_TIMER1) / 1000000);
MSG("uart clock:%dM\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_UART) / 1000000);
MSG("spi clock:%dM\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_SPI) / 1000000);
MSG("i2c clock:%dM\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_I2C) / 1000000);
MSG("adc clock:%dM\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_ADC) / 1000000);
MSG("dac clock:%dM\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_DAC) / 1000000);
MSG("i2s clock:%dM\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_I2S) / 1000000);
MSG("pwm clock:%dhz\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_PWM));
MSG("cam clock:%dM\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_CAM) / 1000000);
MSG("timer0 clock:%dM\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_TIMER0) / 1000000);
MSG("timer1 clock:%dM\r\n", peripheral_clock_get(PERIPHERAL_CLOCK_TIMER1) / 1000000);
#endif
}

View File

@@ -49,7 +49,7 @@
#define BSP_IR_CLOCK_SOURCE ROOT_CLOCK_SOURCE_XCLK
#define BSP_IR_CLOCK_DIV 0
#define BSP_ADC_CLOCK_SOURCE ROOT_CLOCK_SOURCE_XCLK
#define BSP_ADC_CLOCK_DIV 128
#define BSP_ADC_CLOCK_DIV 255
#define BSP_DAC_CLOCK_SOURCE ROOT_CLOCK_SOURCE_AUPLL_24000000_HZ
#define BSP_DAC_CLOCK_DIV 2
#define BSP_CAM_CLOCK_SOURCE ROOT_CLOCK_SOURCE_PLL_96M

View File

@@ -115,7 +115,7 @@
#ifdef MODEL_Magic
#define SOLDERING_TEMP 320 // Default soldering temp is 320.0 °C
#define VOLTAGE_DIV 467 // 467 - Default divider from schematic
#define VOLTAGE_DIV 600 // 290 - Default divider from schematic
#define CALIBRATION_OFFSET 900 // 900 - Default adc offset in uV
#define MIN_CALIBRATION_OFFSET 100 // Min value for calibration
#define PID_POWER_LIMIT 70 // Sets the max pwm power limit

View File

@@ -64,7 +64,7 @@
#define ADC0_CONFIG \
{ \
.clk_div = ADC_CLOCK_DIV_32, .vref = ADC_VREF_3V2, .continuous_conv_mode = DISABLE, .differential_mode = DISABLE, .data_width = ADC_DATA_WIDTH_16B_WITH_256_AVERAGE, \
.fifo_threshold = ADC_FIFO_THRESHOLD_1BYTE, .gain = ADC_GAIN_1 \
.fifo_threshold = ADC_FIFO_THRESHOLD_8BYTE, .gain = ADC_GAIN_1 \
}
#endif
#endif

View File

@@ -665,8 +665,6 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
// If we have tripped thermal runaway, turn off heater and show warning
if (heaterThermalRunaway) {
currentTempTargetDegC = 0; // heater control off
// TODO WARNING
warnUser(translatedString(Tr->WarningThermalRunaway), 10 * TICKS_SECOND);
heaterThermalRunaway = false;
return;
@@ -800,15 +798,15 @@ void showDebugMenu(void) {
}
void showWarnings() {
MSG((char *)"showWarningsshowWarnings\r\n");
return;
// MSG((char *)"showWarningsshowWarnings\r\n");
return; // TODO remove this patch
// Display alert if settings were reset
if (settingsWereReset) {
MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr);
MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr);
MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr);
MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr);
MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr);
// MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr);
// MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr);
// MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr);
// MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr);
// MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr);
warnUser(translatedString(Tr->SettingsResetMessage), 10 * TICKS_SECOND);
}
@@ -817,7 +815,7 @@ void showWarnings() {
// In this case though, we dont want to nag the user _too_ much
// So only show first 2 times
while (DetectedAccelerometerVersion == AccelType::Scanning) {
MSG((char *)"Accel Detect");
// MSG((char *)"Accel Detect");
osDelay(5);
}
// Display alert if accelerometer is not detected
@@ -847,14 +845,14 @@ uint8_t disconnectedTipF[sizeof(disconnectedTip)];
/* StartGUITask function */
void startGUITask(void const *argument) {
(void)argument;
MSG((char *)"startGUITask\r\n");
// MSG((char *)"startGUITask\r\n");
prepareTranslations();
MSG((char *)"OLEDInit\r\n");
// MSG((char *)"OLEDInit\r\n");
OLED::initialize(); // start up the LCD
MSG((char *)"setBrightness\r\n");
// MSG((char *)"setBrightness\r\n");
OLED::setBrightness(getSettingValue(SettingsOptions::OLEDBrightness));
MSG((char *)"setInverseDisplay\r\n");
// MSG((char *)"setInverseDisplay\r\n");
OLED::setInverseDisplay(getSettingValue(SettingsOptions::OLEDInversion));
uint8_t tempWarningState = 0;
@@ -862,7 +860,7 @@ void startGUITask(void const *argument) {
bool tempOnDisplay = false;
bool tipDisconnectedDisplay = false;
bool showExitMenuTransition = false;
MSG((char *)"flip\r\n");
// MSG((char *)"flip\r\n");
{
// Generate the flipped screen into ram for later use
@@ -875,24 +873,24 @@ void startGUITask(void const *argument) {
}
}
}
MSG((char *)"tipTemp\r\n");
// MSG((char *)"tipTemp\r\n");
getTipRawTemp(1); // reset filter
MSG((char *)"setRotation\r\n");
// MSG((char *)"setRotation\r\n");
OLED::setRotation(getSettingValue(SettingsOptions::OrientationMode) & 1);
MSG((char *)"Bootlogo\r\n");
// MSG((char *)"Bootlogo\r\n");
// BootLogo::handleShowingLogo((uint8_t *)FLASH_LOGOADDR);
MSG((char *)"showWarnings\r\n");
// MSG((char *)"showWarnings\r\n");
showWarnings();
MSG((char *)"AutoStartMode\r\n");
// MSG((char *)"AutoStartMode\r\n");
if (getSettingValue(SettingsOptions::AutoStartMode)) {
// jump directly to the autostart mode
gui_solderingMode(getSettingValue(SettingsOptions::AutoStartMode) - 1);
buttonLockout = true;
}
MSG((char *)"GUI Thread Start\r\n");
// MSG((char *)"GUI Thread Start\r\n");
for (;;) {
ButtonState buttons = getButtonState();