1
0
forked from me/IronOS

Merge Dev into mainline (#1)

* Removing USB
Need to refine the drive to the iron tip

* Update README.md

* * Rewrite all code from scratch
* Only kept settings
* New font
* New PID
* New Menus
* Use Hardware I2C
* Faster System
* Better Heating Time
* No USB
* Full Menu System
This commit is contained in:
Ben V. Brown
2016-09-30 00:27:55 +10:00
committed by GitHub
parent 278d29bf4c
commit 0b26e669af
77 changed files with 3669 additions and 10430 deletions

View File

@@ -1,110 +1,17 @@
/********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. **********************
File Name : Bios.c
Version : S100 APP Ver 2.11
Description:
Author : Celery
Data: 2015/07/07
History:
2015/07/07 ͳһ<CDB3><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*******************************************************************************/
/*
* Setup all the basic hardware in the system and handle timer3 tick
*/
#include <Hardware.h>
#include <usb_lib.h>
#include "APP_Version.h"
#include "Bios.h"
#include "I2C.h"
#include "CTRL.h"
/******************************************************************************/
#define ADC1_DR_Address ((u32)0x4001244C)
volatile uint32_t gHeat_cnt = 0;
vu32 gTimeOut, gMs_timeout;
volatile u32 gTime[8]; //times for timer storage
//^-- gTime is automatically decremented on each firing of timer 2 if >0
vu16 ADC1ConvertedValue[2];
vu32 gHeat_cnt = 0;
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Get_AdcValue
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ȡADC ת<><D7AA><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><D7AA><EFBFBD><EFBFBD><EFBFBD>AD
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/
u16 Get_AdcValue(u8 i) {
return ADC1ConvertedValue[i];
}
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Set_HeatingTime
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD>ü<EFBFBD><C3BC><EFBFBD>ʱ<EFBFBD><CAB1>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:heating_time <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/
void Set_HeatingTime(u32 heating_time) {
gHeat_cnt = heating_time;
}
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Get_HeatingTime
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:<3A><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
*******************************************************************************/
u32 Get_HeatingTime(void) {
return gHeat_cnt;
}
/*******************************************************************************
Function:
Description: Init the global count down timers
*******************************************************************************/
void Init_Gtime(void) {
u8 i;
for (i = 0; i < 8; i++)
gTime[i] = 0;
}
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Delay_Ms
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ʱ<EFBFBD>ȴ<EFBFBD><C8B4>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD>ֵ
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/
void Delay_Ms(u32 ms) {
gMs_timeout = ms * 20;
while (gMs_timeout)
; // {if(Scan_key()!=0)break;}
}
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Delay_HalfMs
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:ÿ<><C3BF>λΪ0.5<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ʱ<EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>0.5<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/
void Delay_HalfMs(u32 ms) {
gMs_timeout = ms * 10;
while (gMs_timeout)
; // {if(Scan_key()!=0)break;}
}
/*******************************************************************************
Function: USB_Port
Description: Enables or disables the usb pins
Input: state == ENABLE or DISABLE
*******************************************************************************/
void USB_Port(u8 state) {
USB_DN_LOW();
USB_DP_LOW();
if (state == DISABLE) {
USB_DN_OUT();
USB_DP_OUT();
} else {
USB_DN_EN();
USB_DP_EN();
}
}
/*******************************************************************************
Function:RCC_Config
Description:Setup the system clocks to use internal HSE to run the system at 48Mhz
*******************************************************************************/
/*
* Setup system clocks to run off internal oscillator at 48Mhz
*/
void RCC_Config(void) {
RCC_DeInit();
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
@@ -123,90 +30,77 @@ void RCC_Config(void) {
RCC_AHBPeriphClockCmd(
RCC_AHBPeriph_SRAM | RCC_AHBPeriph_DMA1 | RCC_AHBPeriph_DMA2 |
RCC_AHBPeriph_FLITF, // Enable DMA1 clock ???
ENABLE);
RCC_AHBPeriph_FLITF, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2, //| RCC_APB2Periph_ADC3, //RCC_APB2Periph_TIM1,
ENABLE);
RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3, ENABLE);
RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_Div1); // USBCLK = 48MHz
}
/*******************************************************************************
Function: NVIC_Config
Description: Configures the NVIC table in the hardware
Input: (tab_offset) the table offset for the NVIC
*******************************************************************************/
void NVIC_Config(u16 tab_offset) {
NVIC_InitTypeDef NVIC_InitStructure;
RCC_ClocksTypeDef RCC_Clocks;
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000); //Enable the systick timer at 1ms
}
/*
* Shift the NVIC (Interrupt table) location relative to flash start
*/
void NVIC_Config(u16 tab_offset) {
NVIC_SetVectorTable(NVIC_VectTab_FLASH, tab_offset);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/*******************************************************************************
Function:GPIO_Config
Description: Configures all the GPIO into required states
*******************************************************************************/
/*
* Setup the GPIO
*/
void GPIO_Config(void) {
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); // GPIOB & AFIO
GPIOA_OUTPUT()
;
GPIOA_L_DEF()
;
GPIOA_H_DEF()
;
GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
GPIOB_OUTPUT()
;
GPIOB_L_DEF()
;
GPIOB_H_DEF()
;
//------ PA7 TMP36 Analog input ----------------------------------------//
//------ PA7 TMP36 Analog input ----------------------------------------//
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//------ OLED_RST_PIN(PB9) ------------------------------------------------------------//
//------ OLED_RST_PIN(PB9) ---------------------------------------------//
GPIO_InitStructure.GPIO_Pin = OLED_RST_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_Init(GPIOA, &GPIO_InitStructure);
//------- Heat_Pin - Iron enable output PB4--------------------------------------------------------//
GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST, ENABLE); //Disable PB4=JNTRST
//------- Heat_Pin - Iron enable output PB4-----------------------------//
GPIO_InitStructure.GPIO_Pin = HEAT_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//------ PB0 Iron temp input---------------------------------------//
//----------- PB0 Iron temp input---------------------------------------//
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//---------- INPUT Voltage Detection Pin VB PB1(Ai9) ---------------------------------------//
//---------- INPUT Voltage Detection Pin VB PB1(Ai9) -------------------//
GPIO_InitStructure.GPIO_Pin = VB_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//-------- K1 = PA9, K2 = PA6 ----------------------------------------------------------//
//-------- K1 = PA9, K2 = PA6 ------------------------------------------//
GPIO_InitStructure.GPIO_Pin = KEY1_PIN | KEY2_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//--------INT 1 == PB5 -------------------------------------------------//
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//pullup just in case something resets the accel
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
/*******************************************************************************
Function: Adc_Init
Description:Enable the ADC's and setup the DMA as well to automatically read them to system ram.
*******************************************************************************/
/*
* Init the ADC's
* Setup ADC1 to read via DMA to device ram automatically
*/
void Adc_Init(void) {
u32 timeout = 10 * 0x1000;
ADC_InitTypeDef ADC_InitStructure;
@@ -220,7 +114,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;
@@ -250,9 +145,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);
@@ -275,43 +173,19 @@ void Adc_Init(void) {
ADC_SoftwareStartConvCmd(ADC2, ENABLE);
}
/*******************************************************************************
Function:
Description: Setup Timer2 to fire every 10ms
*******************************************************************************/
void Init_Timer2(void) {
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
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_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_ARRPreloadConfig(TIM2, ENABLE);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM2, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/*******************************************************************************
Function:
Description: Init Timer3 to fire every 50us to be used to control the irons software PWM
*******************************************************************************/
/*
* Init Timer3 to fire every 50us to be used to control the irons software PWM
* This needs to be really fast as there is a cap used between this and the driver circuitry
* That prevents a stuck mcu heating the tip
*/
void Init_Timer3(void) {
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
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);
@@ -325,50 +199,74 @@ void Init_Timer3(void) {
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/*******************************************************************************
Function:TIM2_ISR
Description:Handles Timer 2 tick. (10mS)
Automatically decrements all >0 values in gTime.
Also reads the buttons every 4 ticks
*******************************************************************************/
void TIM2_ISR(void) {
static u8 buttonReadDivider;
//We want to enable the EXTI IRQ for the two buttons on PA6 and PA9
void Init_EXTI(void) {
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
TIM_ClearITPendingBit(TIM2, TIM_IT_Update); // Clear interrupt flag
for (u8 i = 0; i < 8; i++)
if (gTime[i] > 0)
gTime[i]--;
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,
GPIO_PinSource6 | GPIO_PinSource9);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,
GPIO_PinSource5); //PB5 == accelerometer
/* Configure EXTI5/6/9 line */
EXTI_InitStructure.EXTI_Line = EXTI_Line5 | EXTI_Line6 | EXTI_Line9;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; //trigger on up and down
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable and set EXTI9_5 Interrupt to the lowest priority */
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
if (++buttonReadDivider % 4 == 0)
Scan_Key();
}
/*******************************************************************************
Function: TIM3_ISR
Description:Sets the output pin as appropriate
If the Heat_cnt >0 then heater on, otherwise off.
*******************************************************************************/
//Start the system watchdog with a timeout specified
//Note you cannot turn this off once you turn it on
void Start_Watchdog(uint32_t ms) {
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
/* IWDG counter clock: 40KHz(LSI) / 32 = 1.25 KHz (min:0.8ms -- max:3276.8ms */
IWDG_SetPrescaler(IWDG_Prescaler_32);
/* Set counter reload value to XXms */
IWDG_SetReload(ms * 10 / 8);
/* Reload IWDG counter */
IWDG_ReloadCounter();
/* Enable IWDG (the LSI oscillator will be enabled by hardware) */
IWDG_Enable();
}
//Reset the system watchdog
void Clear_Watchdog(void) {
IWDG_ReloadCounter();
}
//TIM3_ISR handles the tick of the timer 3 IRQ
void TIM3_ISR(void) {
volatile static u8 heat_flag = 0;
//heat flag == used to make the pin toggle
//As the output is passed through a cap, the iron is on whilever we provide a square wave drive output
TIM_ClearITPendingBit(TIM3, TIM_IT_Update); // Clear interrupt flag
if (gTimeOut > 0)
gTimeOut--;
if (gMs_timeout > 0)
gMs_timeout--;
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
// Clear interrupt flag
if (gHeat_cnt > 0) {
gHeat_cnt--;
--gHeat_cnt;
if (heat_flag)
HEAT_OFF();
HEAT_OFF(); //write the pin off
else
HEAT_ON();
heat_flag = ~heat_flag;
}
if (gHeat_cnt == 0) {
HEAT_OFF();
HEAT_ON(); //write the pin on
heat_flag = !heat_flag;
} else {
HEAT_OFF(); //set the pin low for measurements
heat_flag = 0;
}
}
/******************************** END OF FILE *********************************/