Convert IMU to IRQ for rotation
This moves the rotation detection to use the IRQ2 line. Fixes #44
This commit is contained in:
@@ -25,6 +25,10 @@ inline uint16_t getRawButtons() {
|
|||||||
return rawKeys;
|
return rawKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern volatile uint8_t RotationChangedFlag;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*IRQ prototypes*/
|
/*IRQ prototypes*/
|
||||||
void NMI_Handler(void);
|
void NMI_Handler(void);
|
||||||
void HardFault_Handler(void);
|
void HardFault_Handler(void);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include "Bios.h"
|
#include "Bios.h"
|
||||||
#include "I2C.h"
|
#include "I2C.h"
|
||||||
|
|
||||||
|
|
||||||
#define ADC1_DR_Address ((u32)0x4001244C)
|
#define ADC1_DR_Address ((u32)0x4001244C)
|
||||||
volatile uint32_t gHeat_cnt = 0;
|
volatile uint32_t gHeat_cnt = 0;
|
||||||
|
|
||||||
@@ -92,8 +91,13 @@ void GPIO_Config(void) {
|
|||||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||||
|
|
||||||
//--------INT 1 == PB5 -------------------------------------------------//
|
//--------INT 1 == PB5 -------------------------------------------------//
|
||||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
|
GPIO_InitStructure.GPIO_Pin = INT1_PIN;
|
||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//pullup just in case something resets the accel
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //pullup just in case something resets the accel
|
||||||
|
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||||
|
|
||||||
|
//--------INT 2 == PB3 -------------------------------------------------//
|
||||||
|
GPIO_InitStructure.GPIO_Pin = INT2_PIN;
|
||||||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //pullup just in case something resets the accel
|
||||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -211,7 +215,8 @@ void Init_EXTI(void) {
|
|||||||
GPIO_PinSource5); //PB5 == accelerometer
|
GPIO_PinSource5); //PB5 == accelerometer
|
||||||
|
|
||||||
/* Configure EXTI5/6/9 line */
|
/* Configure EXTI5/6/9 line */
|
||||||
EXTI_InitStructure.EXTI_Line = EXTI_Line5 | EXTI_Line6 | EXTI_Line9;
|
EXTI_InitStructure.EXTI_Line = EXTI_Line5 | EXTI_Line6 | EXTI_Line9
|
||||||
|
| EXTI_Line3;
|
||||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; //trigger on up and down
|
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; //trigger on up and down
|
||||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||||
@@ -224,6 +229,13 @@ void Init_EXTI(void) {
|
|||||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||||
NVIC_Init(&NVIC_InitStructure);
|
NVIC_Init(&NVIC_InitStructure);
|
||||||
|
|
||||||
|
/* Enable and set EXTI9_5 Interrupt to the lowest priority */
|
||||||
|
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;
|
||||||
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
|
||||||
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
|
||||||
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||||
|
NVIC_Init(&NVIC_InitStructure);
|
||||||
|
|
||||||
}
|
}
|
||||||
//Start the system watchdog with a timeout specified
|
//Start the system watchdog with a timeout specified
|
||||||
//Note you cannot turn this off once you turn it on
|
//Note you cannot turn this off once you turn it on
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ volatile uint32_t AkeyChange;
|
|||||||
volatile uint8_t rawKeys;
|
volatile uint8_t rawKeys;
|
||||||
volatile uint8_t LongKeys;
|
volatile uint8_t LongKeys;
|
||||||
volatile uint32_t lastMovement; //millis() at last movement event
|
volatile uint32_t lastMovement; //millis() at last movement event
|
||||||
|
volatile uint8_t RotationChangedFlag;
|
||||||
|
|
||||||
//Delay in milliseconds using systemTick
|
//Delay in milliseconds using systemTick
|
||||||
void delayMs(uint32_t ticks) {
|
void delayMs(uint32_t ticks) {
|
||||||
@@ -161,6 +162,12 @@ void EXTI9_5_IRQHandler(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
void EXTI3_IRQHandler(void) {
|
||||||
|
if (EXTI_GetITStatus(EXTI_Line3) != RESET) { //Orientation Change
|
||||||
|
RotationChangedFlag = 1;
|
||||||
|
EXTI_ClearITPendingBit(EXTI_Line3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*********************** UNUSED IRQ *****************************************/
|
/*********************** UNUSED IRQ *****************************************/
|
||||||
void WWDG_IRQHandler(void) {
|
void WWDG_IRQHandler(void) {
|
||||||
@@ -181,8 +188,7 @@ void EXTI1_IRQHandler(void) {
|
|||||||
}
|
}
|
||||||
void EXTI2_IRQHandler(void) {
|
void EXTI2_IRQHandler(void) {
|
||||||
}
|
}
|
||||||
void EXTI3_IRQHandler(void) {
|
|
||||||
}
|
|
||||||
void EXTI4_IRQHandler(void) {
|
void EXTI4_IRQHandler(void) {
|
||||||
}
|
}
|
||||||
void DMA1_Channel1_IRQHandler(void) {
|
void DMA1_Channel1_IRQHandler(void) {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ void StartUp_Accelerometer(uint8_t sensitivity) {
|
|||||||
I2C_RegisterWrite( CTRL_REG2, 0x40); // Reset all registers to POR values
|
I2C_RegisterWrite( CTRL_REG2, 0x40); // Reset all registers to POR values
|
||||||
delayMs(2); // ~1ms delay
|
delayMs(2); // ~1ms delay
|
||||||
I2C_RegisterWrite(FF_MT_CFG_REG, 0x78); // Enable motion detection for X and Y axis, latch enabled
|
I2C_RegisterWrite(FF_MT_CFG_REG, 0x78); // Enable motion detection for X and Y axis, latch enabled
|
||||||
uint8_t sens = 9 * 6 + 5;
|
uint8_t sens = 9 * 6 + 3;
|
||||||
sens -= 6 * sensitivity;
|
sens -= 6 * sensitivity;
|
||||||
|
|
||||||
I2C_RegisterWrite(FF_MT_THS_REG, 0x80 | sens); // Set threshold
|
I2C_RegisterWrite(FF_MT_THS_REG, 0x80 | sens); // Set threshold
|
||||||
@@ -52,9 +52,9 @@ void StartUp_Accelerometer(uint8_t sensitivity) {
|
|||||||
I2C_RegisterWrite(PL_CFG_REG, 0x40); //Enable the orientation detection
|
I2C_RegisterWrite(PL_CFG_REG, 0x40); //Enable the orientation detection
|
||||||
I2C_RegisterWrite(PL_COUNT_REG, 200); //200 count debounce
|
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(P_L_THS_REG, 0b10011100); //Up the trip angles
|
||||||
I2C_RegisterWrite( CTRL_REG4, 0x04); // Enable motion interrupt
|
I2C_RegisterWrite( CTRL_REG4, 0x04 | (1<<4)); // Enable motion interrupt & orientation interrupt
|
||||||
I2C_RegisterWrite( CTRL_REG5, 0x04);// Route motion interrupts to INT1 ->PB5 ->EXTI5
|
I2C_RegisterWrite( CTRL_REG5, 0x04);// Route motion interrupts to INT1 ->PB5 ->EXTI5, leaving orientation routed to INT2
|
||||||
I2C_RegisterWrite( CTRL_REG1, 0x11); // ODR=800 Hz, Active mode
|
I2C_RegisterWrite( CTRL_REG1, 0x11); // ODR=800 Hz, Active mode
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,17 +14,33 @@ void setup();
|
|||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
setup();/*Setup the system*/
|
setup();/*Setup the system*/
|
||||||
if(systemSettings.autoStart)
|
if (systemSettings.autoStart)
|
||||||
operatingMode = SOLDERING;
|
operatingMode = SOLDERING;
|
||||||
while (1) {
|
while (1) {
|
||||||
Clear_Watchdog(); //reset the Watch dog timer
|
Clear_Watchdog(); //reset the Watch dog timer
|
||||||
ProcessUI();
|
ProcessUI();
|
||||||
DrawUI();
|
DrawUI();
|
||||||
delayMs(30); //Slow the system down a little bit
|
delayMs(15); //Slow the system down waiting for the iron.
|
||||||
|
|
||||||
|
if (systemSettings.OrientationMode == 2) {
|
||||||
|
//Automatic mode
|
||||||
|
if (RotationChangedFlag) {
|
||||||
|
OLED_SetOrientation(!getOrientation());
|
||||||
|
RotationChangedFlag = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_3) == Bit_RESET) {
|
||||||
|
OLED_SetOrientation(!getOrientation());
|
||||||
|
RotationChangedFlag = 0;
|
||||||
|
//^ This is a workaround for the IRQ being set off before we have the handler setup and enabled.
|
||||||
|
}
|
||||||
|
}
|
||||||
if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_5) == Bit_RESET) {
|
if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_5) == Bit_RESET) {
|
||||||
lastMovement = millis();
|
lastMovement = millis();
|
||||||
//This is a workaround for the line staying low as the user is still moving. (ie sensitivity is too high for their amount of movement)
|
//This is a workaround for the line staying low as the user is still moving. (ie sensitivity is too high for their amount of movement)
|
||||||
}
|
}
|
||||||
|
delayMs(15); //Slow the system down waiting for the iron.
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void setup() {
|
void setup() {
|
||||||
@@ -41,7 +57,7 @@ void setup() {
|
|||||||
setupPID(); //Init the PID values
|
setupPID(); //Init the PID values
|
||||||
readIronTemp(systemSettings.tempCalibration, 0, 0); //load the default calibration value
|
readIronTemp(systemSettings.tempCalibration, 0, 0); //load the default calibration value
|
||||||
if (systemSettings.OrientationMode == 2)
|
if (systemSettings.OrientationMode == 2)
|
||||||
Init_Oled(0); //Init the OLED display in RH mode, since accel wont have started up yet
|
Init_Oled(0); //Init the OLED display in RH mode, since accel wont have started up yet
|
||||||
else
|
else
|
||||||
Init_Oled(systemSettings.OrientationMode); //Init the OLED display
|
Init_Oled(systemSettings.OrientationMode); //Init the OLED display
|
||||||
|
|
||||||
|
|||||||
@@ -414,10 +414,7 @@ void DrawUI() {
|
|||||||
static uint16_t lastSolderingDrawnTemp2 = 0;
|
static uint16_t lastSolderingDrawnTemp2 = 0;
|
||||||
static uint8_t settingsLongTestScrollPos = 0;
|
static uint8_t settingsLongTestScrollPos = 0;
|
||||||
uint16_t temp = readIronTemp(0, 0, 0xFFFF);
|
uint16_t temp = readIronTemp(0, 0, 0xFFFF);
|
||||||
if (systemSettings.OrientationMode == 2) {
|
|
||||||
//Automatic mode
|
|
||||||
OLED_SetOrientation(!getOrientation());
|
|
||||||
}
|
|
||||||
switch (operatingMode) {
|
switch (operatingMode) {
|
||||||
case STARTUP:
|
case STARTUP:
|
||||||
//We are chilling in the idle mode
|
//We are chilling in the idle mode
|
||||||
|
|||||||
Reference in New Issue
Block a user