mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Improve Key Names, Add Font drawing,Working on modes
This commit is contained in:
@@ -111,6 +111,10 @@ void RCC_Config(void) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3, ENABLE);
|
||||
|
||||
RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_Div1); // USBCLK = 48MHz
|
||||
|
||||
RCC_ClocksTypeDef RCC_Clocks;
|
||||
RCC_GetClocksFreq(&RCC_Clocks);
|
||||
SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);//Enable the systick timer
|
||||
}
|
||||
/*******************************************************************************
|
||||
Function: NVIC_Config
|
||||
@@ -204,7 +208,8 @@ void Adc_Init(void) {
|
||||
DMA_InitStructure.DMA_BufferSize = 2;
|
||||
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||||
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
||||
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
|
||||
DMA_InitStructure.DMA_PeripheralDataSize =
|
||||
DMA_PeripheralDataSize_HalfWord;
|
||||
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
|
||||
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
|
||||
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
|
||||
@@ -234,9 +239,12 @@ void Adc_Init(void) {
|
||||
ADC_Init(ADC2, &ADC_InitStructure);
|
||||
|
||||
// ADC1,2 regular channel7 channel9 and channel8 configuration ----------//
|
||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 2, ADC_SampleTime_239Cycles5); //28 or 55
|
||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 1, ADC_SampleTime_239Cycles5); //28 or 55
|
||||
ADC_RegularChannelConfig(ADC2, ADC_Channel_9, 1, ADC_SampleTime_55Cycles5); //28 or 55
|
||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 2,
|
||||
ADC_SampleTime_239Cycles5); //28 or 55
|
||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 1,
|
||||
ADC_SampleTime_239Cycles5); //28 or 55
|
||||
ADC_RegularChannelConfig(ADC2, ADC_Channel_9, 1,
|
||||
ADC_SampleTime_55Cycles5); //28 or 55
|
||||
|
||||
/* Enable ADC1 DMA */
|
||||
ADC_DMACmd(ADC1, ENABLE);
|
||||
@@ -269,8 +277,8 @@ void Init_Timer2(void) {
|
||||
|
||||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
|
||||
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = 48 - 1; // (48MHz)/48 = 1MHz
|
||||
TIM_TimeBaseStructure.TIM_Period = 10000 - 1; // Interrupt per 10mS
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = 48 - 1; // (48MHz)/48 = 1MHz
|
||||
TIM_TimeBaseStructure.TIM_Period = 10000 - 1; // Interrupt per 10mS
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
|
||||
@@ -296,8 +304,8 @@ void Init_Timer3(void) {
|
||||
|
||||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
|
||||
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = 48 - 1; //(48MHz)/48 = 1MHz
|
||||
TIM_TimeBaseStructure.TIM_Period = 50 - 1; // Interrupt per 50us
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = 48 - 1; //(48MHz)/48 = 1MHz
|
||||
TIM_TimeBaseStructure.TIM_Period = 50 - 1; // Interrupt per 50us
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV2;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
|
||||
@@ -320,7 +328,7 @@ void Init_Timer3(void) {
|
||||
void TIM2_ISR(void) {
|
||||
volatile static u8 buttonReadDivider;
|
||||
|
||||
TIM_ClearITPendingBit(TIM2, TIM_IT_Update); // Clear interrupt flag
|
||||
TIM_ClearITPendingBit(TIM2, TIM_IT_Update); // Clear interrupt flag
|
||||
for (u8 i = 0; i < 8; i++)
|
||||
if (gTime[i] > 0)
|
||||
gTime[i]--;
|
||||
@@ -336,7 +344,7 @@ void TIM2_ISR(void) {
|
||||
void TIM3_ISR(void) {
|
||||
volatile static u8 heat_flag = 0; //heat flag == used to make the pin toggle
|
||||
|
||||
TIM_ClearITPendingBit(TIM3, TIM_IT_Update); // Clear interrupt flag
|
||||
TIM_ClearITPendingBit(TIM3, TIM_IT_Update); // Clear interrupt flag
|
||||
|
||||
if (gTimeOut > 0)
|
||||
gTimeOut--;
|
||||
|
||||
@@ -212,7 +212,7 @@ void Status_Tran(void) //
|
||||
switch (Get_CtrlStatus()) {
|
||||
case IDLE:
|
||||
switch (Get_gKey()) { //Read current switch positions
|
||||
case KEY_V1: //If V1 key is pressed
|
||||
case KEY_A: //If V1 key is pressed
|
||||
if (gIs_restartkey != 1) { //check we are not in a soft restart situation
|
||||
if (Read_Vb(1) < 4) { //Read that the input voltage is acceptable??
|
||||
Set_CtrlStatus(SOLDERING_MODE); //Set to temperature controlled mode (Aka soldering mode)
|
||||
@@ -223,7 +223,7 @@ void Status_Tran(void) //
|
||||
}
|
||||
}
|
||||
break;
|
||||
case KEY_V2: //check if V2 key is pressed
|
||||
case KEY_B: //check if V2 key is pressed
|
||||
if(gIs_restartkey != 1) { //check this is not a soft restart situation
|
||||
Set_CtrlStatus(THERMOMETER);//Change system to Thermometer mode instead (ie reading temp only, no drive)
|
||||
UI_TIMER = 0;
|
||||
@@ -249,8 +249,8 @@ void Status_Tran(void) //
|
||||
break;
|
||||
case SOLDERING_MODE: //We are in soldering mode
|
||||
switch(Get_gKey()) { //switch on the pressed key
|
||||
case KEY_CN|KEY_V1:
|
||||
case KEY_CN|KEY_V2://if either key long pressed
|
||||
case KEY_CN|KEY_A:
|
||||
case KEY_CN|KEY_B://if either key long pressed
|
||||
Set_HeatingTime(0);//turn off heater
|
||||
Set_CtrlStatus(TEMP_SET);//Goto temperature set mode
|
||||
HEATING_TIMER = 0;//reset heating timer
|
||||
@@ -386,8 +386,8 @@ void Status_Tran(void) //
|
||||
}
|
||||
|
||||
switch(Get_gKey()) {
|
||||
case KEY_CN|KEY_V1:
|
||||
case KEY_CN|KEY_V2:
|
||||
case KEY_CN|KEY_A:
|
||||
case KEY_CN|KEY_B:
|
||||
back_prestatus = 1;
|
||||
break;
|
||||
case KEY_CN|KEY_V3:
|
||||
|
||||
@@ -107,9 +107,9 @@ void Scan_Key(void) {
|
||||
u32 key_state = 0;
|
||||
|
||||
if ((~GPIOA->IDR) & 0x0200)
|
||||
key_state |= KEY_V1; //KEY_V1
|
||||
key_state |= KEY_A; //KEY_V1
|
||||
if ((~GPIOA->IDR) & 0x0040)
|
||||
key_state |= KEY_V2; //KEY_V2
|
||||
key_state |= KEY_B; //KEY_V2
|
||||
|
||||
if (key_state == 0)
|
||||
return;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "Bios.h"
|
||||
#include "I2C.h"
|
||||
volatile uint32_t system_Ticks;
|
||||
|
||||
/******************************************************************************/
|
||||
/* Processor Exceptions Handlers */
|
||||
@@ -44,6 +45,7 @@ void PendSV_Handler(void) {
|
||||
}
|
||||
|
||||
void SysTick_Handler(void) {
|
||||
++system_Ticks;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
@@ -63,13 +65,66 @@ void TIM2_IRQHandler(void) {
|
||||
void TIM3_IRQHandler(void) {
|
||||
TIM3_ISR();
|
||||
}
|
||||
/*This loop is used for un assigned IRQ's so that the debugger can catch them*/
|
||||
static void forever()
|
||||
|
||||
{
|
||||
for (;;)
|
||||
;
|
||||
}
|
||||
|
||||
void WWDG_IRQHandler(void) {}
|
||||
void PVD_IRQHandler(void) {}
|
||||
|
||||
void TAMPER_IRQHandler(void) {}
|
||||
void RTC_IRQHandler(void){}
|
||||
void FLASH_IRQHandler(void){}
|
||||
void RCC_IRQHandler(void){}
|
||||
void EXTI0_IRQHandler(void){}
|
||||
void EXTI1_IRQHandler(void){}
|
||||
void EXTI2_IRQHandler(void){}
|
||||
void EXTI3_IRQHandler(void){}
|
||||
void EXTI4_IRQHandler(void){}
|
||||
void DMA1_Channel1_IRQHandler(void){}
|
||||
void DMA1_Channel2_IRQHandler(void){}
|
||||
void DMA1_Channel3_IRQHandler(void){}
|
||||
void DMA1_Channel4_IRQHandler(void){}
|
||||
void DMA1_Channel5_IRQHandler(void){}
|
||||
void DMA1_Channel6_IRQHandler(void){}
|
||||
void DMA1_Channel7_IRQHandler(void){}
|
||||
void ADC1_2_IRQHandler(void){}
|
||||
void USB_HP_CAN1_TX_IRQHandler(void){}
|
||||
void CAN1_RX1_IRQHandler(void){}
|
||||
void CAN1_SCE_IRQHandler(void){}
|
||||
void EXTI9_5_IRQHandler(void){}
|
||||
void TIM1_BRK_IRQHandler(void){}
|
||||
void TIM1_UP_IRQHandler(void){}
|
||||
void TIM1_TRG_COM_IRQHandler(void){}
|
||||
void TIM1_CC_IRQHandler(void){}
|
||||
void TIM4_IRQHandler(void){}
|
||||
void I2C1_EV_IRQHandler(void){}
|
||||
void I2C1_ER_IRQHandler(void){}
|
||||
void I2C2_EV_IRQHandler(void){}
|
||||
void I2C2_ER_IRQHandler(void){}
|
||||
void SPI1_IRQHandler(void){}
|
||||
void SPI2_IRQHandler(void){}
|
||||
void USART1_IRQHandler(void){}
|
||||
void USART2_IRQHandler(void){}
|
||||
void USART3_IRQHandler(void){}
|
||||
void EXTI15_10_IRQHandler(void){}
|
||||
void RTCAlarm_IRQHandler(void){}
|
||||
void USBWakeUp_IRQHandler(void){}
|
||||
void TIM8_BRK_IRQHandler(void){}
|
||||
void TIM8_UP_IRQHandler(void){}
|
||||
void TIM8_TRG_COM_IRQHandler(void){}
|
||||
void TIM8_CC_IRQHandler(void){}
|
||||
void ADC3_IRQHandler(void){}
|
||||
void FSMC_IRQHandler(void){}
|
||||
void SDIO_IRQHandler(void){}
|
||||
void TIM5_IRQHandler(void){}
|
||||
void SPI3_IRQHandler(void){}
|
||||
void UART4_IRQHandler(void){}
|
||||
void UART5_IRQHandler(void){}
|
||||
void TIM6_IRQHandler(void){}
|
||||
void TIM7_IRQHandler(void){}
|
||||
void DMA2_Channel1_IRQHandler(void){}
|
||||
void DMA2_Channel2_IRQHandler(void){}
|
||||
void DMA2_Channel3_IRQHandler(void) {}
|
||||
void DMA2_Channel4_5_IRQHandler(void){}
|
||||
|
||||
/********************************* END OF FILE ******************************/
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include "Oled.h"
|
||||
#include "CTRL.h"
|
||||
#include "Hardware.h"
|
||||
#include "Interrupt.h"
|
||||
|
||||
int main(void) {
|
||||
RCC_Config(); //setup system clock
|
||||
//NVIC_Config(0x4000);
|
||||
@@ -30,8 +32,7 @@ int main(void) {
|
||||
I2C_Configuration(); //init the i2c bus
|
||||
|
||||
Adc_Init(); //init adc and dma
|
||||
if (Get_CtrlStatus() != USB_POWER)
|
||||
StartUp_Accelerated(); //start the accelerometer if not in config mode
|
||||
StartUp_Accelerated(); //start the accelerometer
|
||||
|
||||
System_Init(); //load known safe values
|
||||
Init_Oled(); //init the OLED display
|
||||
@@ -41,6 +42,13 @@ int main(void) {
|
||||
|
||||
Pid_Init(); //init the pid to starting values
|
||||
Set_gKey(NO_KEY); //reset keys to all off
|
||||
//OLED_DrawString("TEST012",7);
|
||||
|
||||
for (;;) {
|
||||
|
||||
OLED_DrawTwoNumber((millis() / 100) % 100, 0);
|
||||
}
|
||||
|
||||
Start_Watchdog(3000); //start the system watchdog as 3 seconds
|
||||
|
||||
while (1) {
|
||||
|
||||
49
workspace/ts100/src/Modes.c
Normal file
49
workspace/ts100/src/Modes.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Modes.c
|
||||
*
|
||||
* Created on: 17 Sep 2016
|
||||
* Author: Ralim
|
||||
*/
|
||||
#include "Modes.h"
|
||||
//This does the required processing and state changes
|
||||
void ProcessUI() {
|
||||
uint8_t Buttons = Get_gKey(); //read the buttons status
|
||||
switch (operatingMode) {
|
||||
case STARTUP:
|
||||
if (Buttons & KEY_A) {
|
||||
//A key pressed so we are moving to soldering mode
|
||||
operatingMode = SOLDERING;
|
||||
} else if (Buttons & KEY_B) {
|
||||
//B Button was pressed so we are moving to the Settings menu
|
||||
operatingMode = SETTINGS;
|
||||
} else {
|
||||
//no buttons pressed so we sit tight
|
||||
}
|
||||
break;
|
||||
case SOLDERING:
|
||||
//We need to check the buttons if we need to jump out
|
||||
|
||||
break;
|
||||
case TEMP_ADJ:
|
||||
break;
|
||||
case SETTINGS:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DrawUI() {
|
||||
switch (operatingMode) {
|
||||
case STARTUP:
|
||||
break;
|
||||
case SOLDERING:
|
||||
break;
|
||||
case TEMP_ADJ:
|
||||
break;
|
||||
case SETTINGS:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -171,35 +171,36 @@ void Init_Oled(void) {
|
||||
*******************************************************************************/
|
||||
void Clear_Screen(void) {
|
||||
u8 tx_data[128];
|
||||
u8 i, wd;
|
||||
|
||||
#ifdef SSD1316
|
||||
wd = 32;
|
||||
#else
|
||||
wd = 16; //how many lines the display is
|
||||
#endif
|
||||
|
||||
memset(&tx_data[0], 0, 128);
|
||||
for (i = 0; i < wd / 8; i++) {
|
||||
for (u8 i = 0; i < 2; i++) {
|
||||
Oled_DrawArea(0, i * 8, 128, 8, tx_data);
|
||||
}
|
||||
}
|
||||
void OLED_DrawString(char* string, uint8_t length) {
|
||||
for (uint8_t i = 0; i < length; i++) {
|
||||
OLED_DrawChar(string[i], i * 16);
|
||||
OLED_DrawChar(string[i], i * 14);
|
||||
}
|
||||
}
|
||||
void OLED_DrawChar(char c, uint8_t x) {
|
||||
if ((x) > 112)
|
||||
if ((x) > (128 - 14))
|
||||
return; //Rudimentary clipping to not draw off screen
|
||||
u8* ptr;
|
||||
u8 temp;
|
||||
|
||||
ptr = (u8*) FONT;
|
||||
if (c >= 'A' && c <= 'Z') {
|
||||
ptr = (u8*) FONT;
|
||||
ptr += (c - 'A') * 32;
|
||||
Oled_DrawArea(x, 0, 16, 16, (u8*) ptr);
|
||||
}
|
||||
ptr += (c - 'A' + 10) * (14 * 2);
|
||||
} else if (c >= '0' && c <= '9')
|
||||
ptr += (c - '0') * (14 * 2);
|
||||
else if (c < 10)
|
||||
ptr += (c) * (14 * 2);
|
||||
Oled_DrawArea(x, 0, 14, 16, (u8*) ptr);
|
||||
}
|
||||
/*
|
||||
* Draw a 2 digit number to the display
|
||||
* */
|
||||
void OLED_DrawTwoNumber(uint8_t in, uint8_t x) {
|
||||
OLED_DrawChar(in / 10, x);
|
||||
OLED_DrawChar(in % 10, x + 14);
|
||||
|
||||
}
|
||||
/******************************** END OF FILE *********************************/
|
||||
|
||||
|
||||
@@ -794,7 +794,7 @@ void Temp_SetProc(void) {
|
||||
Show_Set();
|
||||
}
|
||||
switch(Get_gKey()) {
|
||||
case KEY_V1:
|
||||
case KEY_A:
|
||||
|
||||
if(device_info.t_work > gSet_table[1]) {
|
||||
gTempset_showctrl = 1;
|
||||
@@ -808,7 +808,7 @@ void Temp_SetProc(void) {
|
||||
}
|
||||
if(device_info.t_work == gSet_table[1]) Show_Triangle(0,1);
|
||||
break;
|
||||
case KEY_V2:
|
||||
case KEY_B:
|
||||
|
||||
if(device_info.t_work < gSet_table[0]) {
|
||||
gTempset_showctrl = 1;
|
||||
@@ -925,10 +925,10 @@ void OLed_Display(void) {
|
||||
Clear_Screen();
|
||||
}
|
||||
switch(Get_gKey()) {
|
||||
case KEY_CN|KEY_V1:
|
||||
case KEY_CN|KEY_A:
|
||||
config_show = 1;
|
||||
break;
|
||||
case KEY_CN|KEY_V2:
|
||||
case KEY_CN|KEY_B:
|
||||
config_show = 2;
|
||||
break;
|
||||
case KEY_CN|KEY_V3:
|
||||
|
||||
Reference in New Issue
Block a user