mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Move watchdog resets to only be in PID
This commit is contained in:
@@ -14,12 +14,14 @@ MMA8652FC::MMA8652FC(I2C_HandleTypeDef* i2cHandle) {
|
||||
|
||||
void MMA8652FC::I2C_RegisterWrite(uint8_t reg, uint8_t data) {
|
||||
|
||||
HAL_I2C_Mem_Write(i2c, MMA8652FC_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT, &data, 1, 0xFFFF);
|
||||
HAL_I2C_Mem_Write(i2c, MMA8652FC_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT,
|
||||
&data, 1, 500);
|
||||
}
|
||||
|
||||
uint8_t MMA8652FC::I2C_RegisterRead(uint8_t reg) {
|
||||
uint8_t tx_data[1];
|
||||
HAL_I2C_Mem_Read(i2c, MMA8652FC_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT, tx_data, 1, 0xFFFF);
|
||||
HAL_I2C_Mem_Read(i2c, MMA8652FC_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT,
|
||||
tx_data, 1, 500);
|
||||
|
||||
return tx_data[0];
|
||||
}
|
||||
@@ -28,30 +30,32 @@ void MMA8652FC::initalize() {
|
||||
I2C_RegisterWrite(CTRL_REG2, 0); //Normal mode
|
||||
I2C_RegisterWrite( CTRL_REG2, 0x40); // Reset all registers to POR values
|
||||
HAL_Delay(2); // ~1ms delay
|
||||
I2C_RegisterWrite(FF_MT_CFG_REG, 0x78); // Enable motion detection for X, Y, Z axis, latch disabled
|
||||
I2C_RegisterWrite(FF_MT_CFG_REG, 0x78); // Enable motion detection for X, Y, Z axis, latch disabled
|
||||
|
||||
I2C_RegisterWrite(PL_CFG_REG, 0x40); //Enable the orientation detection
|
||||
I2C_RegisterWrite(PL_COUNT_REG, 200); //200 count debounce
|
||||
I2C_RegisterWrite(PL_BF_ZCOMP_REG, 0b01000111); //Set the threshold to 42 degrees
|
||||
I2C_RegisterWrite(PL_BF_ZCOMP_REG, 0b01000111); //Set the threshold to 42 degrees
|
||||
I2C_RegisterWrite(P_L_THS_REG, 0b10011100); //Up the trip angles
|
||||
I2C_RegisterWrite( CTRL_REG4, 0x01 | (1 << 4)); // Enable dataready interrupt & orientation interrupt
|
||||
I2C_RegisterWrite( CTRL_REG5, 0x01); // Route data ready interrupts to INT1 ->PB5 ->EXTI5, leaving orientation routed to INT2
|
||||
I2C_RegisterWrite( CTRL_REG2, 0x12); //Set maximum resolution oversampling
|
||||
I2C_RegisterWrite( XYZ_DATA_CFG_REG, (1 << 4)); //select high pass filtered data
|
||||
I2C_RegisterWrite( HP_FILTER_CUTOFF_REG, 0x03); //select high pass filtered data
|
||||
I2C_RegisterWrite( CTRL_REG4, 0x01 | (1 << 4)); // Enable dataready interrupt & orientation interrupt
|
||||
I2C_RegisterWrite( CTRL_REG5, 0x01); // Route data ready interrupts to INT1 ->PB5 ->EXTI5, leaving orientation routed to INT2
|
||||
I2C_RegisterWrite( CTRL_REG2, 0x12); //Set maximum resolution oversampling
|
||||
I2C_RegisterWrite( XYZ_DATA_CFG_REG, (1 << 4)); //select high pass filtered data
|
||||
I2C_RegisterWrite( HP_FILTER_CUTOFF_REG, 0x03); //select high pass filtered data
|
||||
|
||||
I2C_RegisterWrite( CTRL_REG1, 0x19); // ODR=12 Hz, Active mode
|
||||
HAL_Delay(2); // ~1ms delay
|
||||
|
||||
}
|
||||
|
||||
void MMA8652FC::setSensitivity(uint8_t threshold, uint8_t filterTime) {
|
||||
uint8_t sens = 9 * 2 + 17;
|
||||
sens -= 2 * threshold;
|
||||
taskENTER_CRITICAL();
|
||||
I2C_RegisterWrite( CTRL_REG1, 0); // sleep mode
|
||||
I2C_RegisterWrite(FF_MT_THS_REG, (sens & 0x7F)); // Set accumulation threshold
|
||||
I2C_RegisterWrite(FF_MT_THS_REG, (sens & 0x7F));// Set accumulation threshold
|
||||
I2C_RegisterWrite(FF_MT_COUNT_REG, filterTime); // Set debounce threshold
|
||||
I2C_RegisterWrite( CTRL_REG1, 0x31); // ODR=12 Hz, Active mode
|
||||
|
||||
taskEXIT_CRITICAL();
|
||||
}
|
||||
|
||||
bool MMA8652FC::getOrientation() {
|
||||
@@ -69,8 +73,8 @@ bool MMA8652FC::getOrientation() {
|
||||
void MMA8652FC::getAxisReadings(int16_t *x, int16_t *y, int16_t *z) {
|
||||
uint8_t tempArr[6];
|
||||
taskENTER_CRITICAL();
|
||||
while (HAL_I2C_Mem_Read(i2c, MMA8652FC_I2C_ADDRESS, OUT_X_MSB_REG, I2C_MEMADD_SIZE_8BIT, (uint8_t*) tempArr, 6,
|
||||
0xFFFF) != HAL_OK) {
|
||||
while (HAL_I2C_Mem_Read(i2c, MMA8652FC_I2C_ADDRESS, OUT_X_MSB_REG,
|
||||
I2C_MEMADD_SIZE_8BIT, (uint8_t*) tempArr, 6, 0xFFFF) != HAL_OK) {
|
||||
HAL_Delay(5);
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
|
||||
@@ -90,7 +90,7 @@ void OLED::refresh() {
|
||||
//Because I2C is shared, we cant task switch in the middle of the xfer
|
||||
|
||||
HAL_I2C_Master_Transmit(i2c, DEVICEADDR_OLED, screenBuffer, 12 + 96 * 2 + 1,
|
||||
0xFFFF);
|
||||
500);
|
||||
taskEXIT_CRITICAL();
|
||||
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ static void MX_ADC1_Init(void) {
|
||||
static void MX_I2C1_Init(void) {
|
||||
|
||||
hi2c1.Instance = I2C1;
|
||||
hi2c1.Init.ClockSpeed = 100000;
|
||||
hi2c1.Init.ClockSpeed = 20000;
|
||||
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
||||
hi2c1.Init.OwnAddress1 = 0;
|
||||
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
|
||||
@@ -166,13 +166,11 @@ static void waitForButtonPress() {
|
||||
while (buttons) {
|
||||
buttons = getButtonState();
|
||||
GUIDelay();
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
lcd.refresh();
|
||||
lcd.refresh();
|
||||
}
|
||||
while (!buttons) {
|
||||
buttons = getButtonState();
|
||||
GUIDelay();
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
lcd.refresh();
|
||||
}
|
||||
}
|
||||
@@ -185,7 +183,6 @@ void waitForButtonPressOrTimeout(uint32_t timeout) {
|
||||
if (buttons) return;
|
||||
if (HAL_GetTick() > timeout) return;
|
||||
GUIDelay();
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,7 +369,6 @@ static void gui_settingsMenu() {
|
||||
|
||||
lcd.refresh(); // update the LCD
|
||||
osDelay(20);
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
}
|
||||
|
||||
saveSettings();
|
||||
@@ -410,7 +406,7 @@ static int gui_showTipTempWarning() {
|
||||
lcd.drawSymbol(1);
|
||||
}
|
||||
}
|
||||
if (systemSettings.coolingTempBlink && tipTemp > 50) {
|
||||
if (systemSettings.coolingTempBlink && tipTemp > 70) {
|
||||
if (HAL_GetTick() % 500 < 250) lcd.clearScreen();
|
||||
}
|
||||
lcd.refresh();
|
||||
@@ -420,9 +416,8 @@ static int gui_showTipTempWarning() {
|
||||
else if (buttons == BUTTON_B_SHORT || buttons == BUTTON_BOTH)
|
||||
return 0;
|
||||
|
||||
if (tipTemp < 30) return 0;
|
||||
if (tipTemp < 50) return 0;//Exit the warning screen
|
||||
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
GUIDelay();
|
||||
}
|
||||
}
|
||||
@@ -493,7 +488,6 @@ static int gui_SolderingSleepingMode() {
|
||||
}
|
||||
lcd.refresh();
|
||||
GUIDelay();
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
}
|
||||
}
|
||||
static void gui_solderingMode() {
|
||||
@@ -643,7 +637,6 @@ static void gui_solderingMode() {
|
||||
}
|
||||
}
|
||||
GUIDelay();
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
}
|
||||
}
|
||||
#define ACCELDEBUG 0
|
||||
@@ -798,7 +791,6 @@ void startGUITask(void const *argument) {
|
||||
|
||||
lcd.refresh();
|
||||
animationStep++;
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
GUIDelay();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user