From 343f950add6f5d0b52f8425e117c5a4f64ae2e23 Mon Sep 17 00:00:00 2001 From: RichardBarry Date: Mon, 26 Nov 2007 15:43:24 +0000 Subject: [PATCH] Add STM32 Primer demo. Remove the .lock file from the Eclipse demos. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@118 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- .../ARM7_AT91SAM7X256_Eclipse/.metadata/.lock | 0 Demo/ARM7_LPC2368_Eclipse/.metadata/.lock | 0 Demo/CORTEX_LM3Sxxxx_Eclipse/.metadata/.lock | 0 .../FreeRTOSConfig.h | 93 + .../ParTest/ParTest.c | 121 + .../RTOSDemo-globals.Standard.xml | 577 +++ .../RTOSDemo.Standard.xml | 2278 +++++++++++ .../CORTEX_STM32F103_Primer_GCC/RTOSDemo.rapp | 108 + .../CORTEX_STM32F103_Primer_GCC/RTOSDemo.rprj | 4 + .../ST_Code/Util.c | 528 +++ .../CORTEX_STM32F103_Primer_GCC/ST_Code/adc.h | 18 + .../ST_Code/buzzer.c | 554 +++ .../ST_Code/circle.h | 431 +++ .../ST_Code/circle_api.h | 679 ++++ .../ST_Code/crt0_STM32x.c | 217 ++ .../ST_Code/draw.c | 545 +++ .../CORTEX_STM32F103_Primer_GCC/ST_Code/lcd.c | 1189 ++++++ .../CORTEX_STM32F103_Primer_GCC/ST_Code/lcd.h | 154 + .../CORTEX_STM32F103_Primer_GCC/ST_Code/led.c | 210 + .../ST_Code/mems.c | 605 +++ .../ST_Code/pointer.c | 901 +++++ .../ST_Code/scheduler.h | 81 + .../ST_Code/stm32f10x_circle_it.c | 217 ++ .../ST_Code/stm32f10x_conf.h | 119 + .../ST_Code/stm32f10x_it.h | 70 + .../ST_Code/stm32f10x_tim.c | 2348 ++++++++++++ Demo/CORTEX_STM32F103_Primer_GCC/bitmap.h | 3361 +++++++++++++++++ Demo/CORTEX_STM32F103_Primer_GCC/main.c | 465 +++ .../printf-stdarg.c | 280 ++ Demo/CORTEX_STM32F103_Primer_GCC/timertest.c | 170 + Source/include/portable.h | 4 + 31 files changed, 16327 insertions(+) delete mode 100644 Demo/ARM7_AT91SAM7X256_Eclipse/.metadata/.lock delete mode 100644 Demo/ARM7_LPC2368_Eclipse/.metadata/.lock delete mode 100644 Demo/CORTEX_LM3Sxxxx_Eclipse/.metadata/.lock create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/FreeRTOSConfig.h create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/ParTest/ParTest.c create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/RTOSDemo-globals.Standard.xml create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/RTOSDemo.Standard.xml create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/RTOSDemo.rapp create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/RTOSDemo.rprj create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/Util.c create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/adc.h create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/buzzer.c create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/circle.h create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/circle_api.h create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/crt0_STM32x.c create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/draw.c create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/lcd.c create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/lcd.h create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/led.c create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/mems.c create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/pointer.c create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/scheduler.h create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/stm32f10x_circle_it.c create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/stm32f10x_conf.h create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/stm32f10x_it.h create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/stm32f10x_tim.c create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/bitmap.h create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/main.c create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/printf-stdarg.c create mode 100644 Demo/CORTEX_STM32F103_Primer_GCC/timertest.c diff --git a/Demo/ARM7_AT91SAM7X256_Eclipse/.metadata/.lock b/Demo/ARM7_AT91SAM7X256_Eclipse/.metadata/.lock deleted file mode 100644 index e69de29bb..000000000 diff --git a/Demo/ARM7_LPC2368_Eclipse/.metadata/.lock b/Demo/ARM7_LPC2368_Eclipse/.metadata/.lock deleted file mode 100644 index e69de29bb..000000000 diff --git a/Demo/CORTEX_LM3Sxxxx_Eclipse/.metadata/.lock b/Demo/CORTEX_LM3Sxxxx_Eclipse/.metadata/.lock deleted file mode 100644 index e69de29bb..000000000 diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/FreeRTOSConfig.h b/Demo/CORTEX_STM32F103_Primer_GCC/FreeRTOSConfig.h new file mode 100644 index 000000000..1f708f011 --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/FreeRTOSConfig.h @@ -0,0 +1,93 @@ +/* + FreeRTOS.org V4.6.1 - Copyright (C) 2003-2007 Richard Barry. + + This file is part of the FreeRTOS.org distribution. + + FreeRTOS.org is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FreeRTOS.org is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FreeRTOS.org; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + A special exception to the GPL can be applied should you wish to distribute + a combined work that includes FreeRTOS.org, without being obliged to provide + the source code for any proprietary components. See the licensing section + of http://www.FreeRTOS.org for full details of how and when the exception + can be applied. + + *************************************************************************** + See http://www.FreeRTOS.org for documentation, latest information, license + and contact details. Please ensure to read the configuration and relevant + port sections of the online documentation. + + Also see http://www.SafeRTOS.com a version that has been certified for use + in safety critical systems, plus commercial licensing, development and + support options. + *************************************************************************** +*/ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/* Library includes. */ +#include "stm32f10x_lib.h" + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + *----------------------------------------------------------*/ + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 1 +#define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 72000000 ) +#define configTICK_RATE_HZ ( ( portTickType ) 1000 ) +#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 5 ) +#define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 128 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 17 * 1024 ) ) +#define configMAX_TASK_NAME_LEN ( 16 ) +#define configUSE_TRACE_FACILITY 0 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ + +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 + +/* This is the raw value as per the Cortex-M3 NVIC. Values can be 255 +(lowest) to 0 (1?) (highest). */ +#define configKERNEL_INTERRUPT_PRIORITY 255 + +/* This is the value being used as per the ST library which permits 16 +priority values, 0 to 15. This must correspond to the +configKERNEL_INTERRUPT_PRIORITY setting. Here 15 corresponds to the lowest +NVIC value of 255. */ +#define configLIBRARY_KERNEL_INTERRUPT_PRIORITY 15 + +#endif /* FREERTOS_CONFIG_H */ + diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/ParTest/ParTest.c b/Demo/CORTEX_STM32F103_Primer_GCC/ParTest/ParTest.c new file mode 100644 index 000000000..33cf1c279 --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/ParTest/ParTest.c @@ -0,0 +1,121 @@ +/* + FreeRTOS.org V4.6.1 - Copyright (C) 2003-2007 Richard Barry. + + This file is part of the FreeRTOS.org distribution. + + FreeRTOS.org is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FreeRTOS.org is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FreeRTOS.org; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + A special exception to the GPL can be applied should you wish to distribute + a combined work that includes FreeRTOS.org, without being obliged to provide + the source code for any proprietary components. See the licensing section + of http://www.FreeRTOS.org for full details of how and when the exception + can be applied. + + *************************************************************************** + See http://www.FreeRTOS.org for documentation, latest information, license + and contact details. Please ensure to read the configuration and relevant + port sections of the online documentation. + + Also see http://www.SafeRTOS.com a version that has been certified for use + in safety critical systems, plus commercial licensing, development and + support options. + *************************************************************************** +*/ + +/*----------------------------------------------------------- + * Simple parallel port IO routines. + *-----------------------------------------------------------*/ + +/* FreeRTOS.org includes. */ +#include "FreeRTOS.h" +#include "task.h" +#include "partest.h" + +#define partstMAX_OUTPUT_LED ( 2 ) +#define partstFIRST_LED GPIO_Pin_8 + +static unsigned portSHORT usOutputValue = 0; + +/*-----------------------------------------------------------*/ + +void vParTestInitialise( void ) +{ +GPIO_InitTypeDef GPIO_InitStructure; + + /* Enable LED GPIO clock. */ + RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE ); + + /* Configure LED pins as output push-pull. */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 ; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + + GPIO_Init( GPIOB, &GPIO_InitStructure ); +} +/*-----------------------------------------------------------*/ + +void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue ) +{ +unsigned portSHORT usBit; + + vTaskSuspendAll(); + { + if( uxLED < partstMAX_OUTPUT_LED ) + { + usBit = partstFIRST_LED << uxLED; + + if( xValue == pdFALSE ) + { + usBit ^= ( unsigned portSHORT ) 0xffff; + usOutputValue &= usBit; + } + else + { + usOutputValue |= usBit; + } + + GPIO_Write( GPIOB, usOutputValue ); + } + } + xTaskResumeAll(); +} +/*-----------------------------------------------------------*/ + +void vParTestToggleLED( unsigned portBASE_TYPE uxLED ) +{ +unsigned portSHORT usBit; + + vTaskSuspendAll(); + { + if( uxLED < partstMAX_OUTPUT_LED ) + { + usBit = partstFIRST_LED << uxLED; + + if( usOutputValue & usBit ) + { + usOutputValue &= ~usBit; + } + else + { + usOutputValue |= usBit; + } + + GPIO_Write( GPIOB, usOutputValue ); + } + } + xTaskResumeAll(); +} +/*-----------------------------------------------------------*/ + diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/RTOSDemo-globals.Standard.xml b/Demo/CORTEX_STM32F103_Primer_GCC/RTOSDemo-globals.Standard.xml new file mode 100644 index 000000000..1156f6f04 --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/RTOSDemo-globals.Standard.xml @@ -0,0 +1,577 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/RTOSDemo.Standard.xml b/Demo/CORTEX_STM32F103_Primer_GCC/RTOSDemo.Standard.xml new file mode 100644 index 000000000..e4bb7e670 --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/RTOSDemo.Standard.xml @@ -0,0 +1,2278 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/RTOSDemo.rapp b/Demo/CORTEX_STM32F103_Primer_GCC/RTOSDemo.rapp new file mode 100644 index 000000000..1d85f43d5 --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/RTOSDemo.rapp @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+ + +
+ +
+ +
+ + +
+
+ + +
+ +
+ +
+ + + +
+ +
+ +
+ + +
+
+ + +
+ +
+
+
+
\ No newline at end of file diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/RTOSDemo.rprj b/Demo/CORTEX_STM32F103_Primer_GCC/RTOSDemo.rprj new file mode 100644 index 000000000..3eb5276de --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/RTOSDemo.rprj @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/Util.c b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/Util.c new file mode 100644 index 000000000..b331df730 --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/Util.c @@ -0,0 +1,528 @@ +/********************* (C) COPYRIGHT 2007 RAISONANCE S.A.S. *******************/ +/** +* +* @file Util.c +* @brief Various utilities for STM32 CircleOS. +* @author RT +* @date 07/2007 +* +**/ +/******************************************************************************/ + +/* Includes ------------------------------------------------------------------*/ + +#include "circle.h" +#include "adc.h" + +/// @cond Internal + +/* Private defines -----------------------------------------------------------*/ +#define GPIO_USB_PIN GPIO_Pin_1 +#define GPIOx_USB GPIOA +#define OsVersion "V 1.7" /*!< CircleOS version string. */ + +/* Private typedef -----------------------------------------------------------*/ +enum eSpeed CurrentSpeed; + +/* Private variables ---------------------------------------------------------*/ +RCC_ClocksTypeDef RCC_ClockFreq; +int dummycounter = 0; +u8 fTemperatureInFahrenheit = 0; /*!< 1 : Fahrenheit, 0 : Celcius (default). */ + +/* Private function prototypes -----------------------------------------------*/ +static void _int2str( char* ptr, s32 X, u16 digit, int flagunsigned, int fillwithzero ); + +/* Private functions ---------------------------------------------------------*/ + +/******************************************************************************* +* +* _int2str +* +*******************************************************************************/ +/** +* +* Translate a 32 bit word into a string. +* +* @param[in,out] ptr A pointer to a string large enough to contain +* the translated 32 bit word. +* @param[in] X The 32 bit word to translate. +* @param[in] digit The amount of digits wanted in the result string. +* @param[in] flagunsigned Is the input word unsigned? +* @param[in] fillwithzero Fill with zeros or spaces. +* +**/ +/******************************************************************************/ +static void _int2str( char* ptr, s32 X, u16 digit, int flagunsigned, int fillwithzero ) + { + u8 c; + u8 fFirst = 0; + u8 fNeg = 0; + u32 DIG = 1; + int i; + + for( i = 1; i < digit; i++ ) + { + DIG *= 10; + } + + if( !flagunsigned && ( X < 0 ) ) + { + fNeg = 1; + X = -X; + } + + u32 r = X; + + for( i = 0; i < digit; i++, DIG /= 10 ) + { + c = (r/DIG); + r -= (c*DIG); + + if( fillwithzero || fFirst || c || ( i == ( digit - 1 ) ) ) + { + if( ( fFirst == 0 ) && !flagunsigned ) + { + *ptr++ = fNeg ? '-' : ' '; + } + + *ptr++ = c + 0x30; + fFirst = 1; + } + else + { + *ptr++ = ' '; + } + } + + *ptr++ = 0; + } + +/* Public functions for CircleOS ---------------------------------------------*/ + +/******************************************************************************* +* +* delay_unit +* +*******************************************************************************/ +/** +* +* Called by starting_delay(). +* +* @note Not in main.c to avoid inlining. +* +**/ +/******************************************************************************/ +void delay_unit( void ) + { + dummycounter++; + } + +/// @endcond + +/* Public functions ----------------------------------------------------------*/ + +/******************************************************************************* +* +* UTIL_GetBat +* +*******************************************************************************/ +/** +* +* Return the batterie tension in mV. +* +* @return Batterie tension in mV. +* +**/ +/******************************************************************************/ +u16 UTIL_GetBat( void ) + { +#ifdef _ADC + u16 vbat; + + // Measure VBAT + vbat = ADC_ConvertedValue[0]; //*( (u16*)ADC1_DR_Address ); // <=== note changed + vbat = vbat & 0xFFF; + vbat = ( vbat * VDD_VOLTAGE_MV ) / 0x1000; + + return vbat; +#else + return 0; +#endif + } + +/******************************************************************************* +* +* UTIL_GetTemp +* +*******************************************************************************/ +/** +* +* Return the Temperature: degrees / 10, Celcius or Fahrenheit. +* +* @return The temperature (C or F) (averaging of several channels). +* +**/ +/******************************************************************************/ +u16 UTIL_GetTemp( void ) + { + s32 temp; + s16 *p=&ADC_ConvertedValue[1]; //intent; point to first of 8 results from same source - use a short name for it! + + // Measure temp + //temp = ADC_ConvertedValue[1];//*( (u16*)ADC1_DR_Address ); + temp = (p[0]+p[1]+p[2]+p[3]+p[4]+p[5]+p[6]+p[7])/8; //take avg of burst of 8 temp reads. may only help reject hi freq noise a bit + //will not help reduce mains ripple because conversions are SO FAST!! + temp = temp & 0xFFF; + temp = ( temp * VDD_VOLTAGE_MV ) / 0x1000; //finds mV + temp = (((1400-temp)*100000)/448)+25000; //gives approx temp x 1000 degrees C + + //Fahrenheit = 32 + 9 / 5 * Celsius + if ( fTemperatureInFahrenheit ) + { + temp = 32000 + (9 * temp) / 5 ; + } + + return temp / 100; + } + +/******************************************************************************* +* +* UTIL_SetTempMode +* +*******************************************************************************/ +/** +* +* Set the temperature mode (F/C) +* +* @param[in] mode 0: Celcius, 1: Fahrenheit +* +**/ +/******************************************************************************/ +void UTIL_SetTempMode ( int mode ) + { + fTemperatureInFahrenheit = mode; + + return; + } + + +/******************************************************************************* +* +* UTIL_GetUsb +* +*******************************************************************************/ +/** +* +* Return the USB connexion state. +* +* @return The USB connexion state. +* +**/ +/******************************************************************************/ +u8 UTIL_GetUsb( void ) + { + GPIO_InitStructure.GPIO_Pin = GPIO_USB_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + + GPIO_Init( GPIOx_USB, &GPIO_InitStructure ); + + return ( GPIO_ReadInputDataBit( GPIOx_USB, GPIO_USB_PIN ) == Bit_SET ); + } + +/******************************************************************************* +* +* UTIL_uint2str +* +*******************************************************************************/ +/** +* +* Convert an unsigned integer into a string. +* +* @param [out] ptr The output string. +* @param [in] X The unsigned value to convert. +* @param [in] digit The number of digits in the output string. +* @param [in] fillwithzero \li 0 fill with blanks. +* \li 1 fill with zeros. +* +**/ +/********************************************************************************/ +void UTIL_uint2str( char* ptr, u32 X, u16 digit, int fillwithzero ) + { + _int2str( ptr, X, digit, 1, fillwithzero); + } + +/******************************************************************************* +* +* UTIL_int2str +* +*******************************************************************************/ +/** +* +* Convert a signed integer into a string. +* +* @param [out] ptr The output string. +* @param [in] X The unsigned value to convert. +* @param [in] digit The number of digits in the output string. +* @param [in] fillwithzero \li 0 fill with blanks. +* \li 1 fill with zeros. +* +**/ +/******************************************************************************/ +void UTIL_int2str( char* ptr, s32 X, u16 digit, int fillwithzero ) + { + _int2str( ptr, X, digit, 0, fillwithzero); + } + +/******************************************************************************* +* +* UTIL_SetPll +* +*******************************************************************************/ +/** +* +* Set clock frequency (lower to save energy) +* +* @param [in] speed New clock speed from very low to very fast. +* +**/ +/******************************************************************************/ +void UTIL_SetPll( enum eSpeed speed ) + { + /* Select PLL as system clock source */ + RCC_SYSCLKConfig( RCC_SYSCLKSource_HSI ); + + /* Enable PLL */ + RCC_PLLCmd( DISABLE ); + + if( ( speed < SPEED_VERY_LOW ) || ( speed > SPEED_VERY_HIGH ) ) + { + speed = SPEED_MEDIUM; + } + + CurrentSpeed = speed; + + switch( speed ) + { + // 18 MHz + case SPEED_VERY_LOW : + /* PLLCLK = 6MHz * 3 = 18 MHz */ + RCC_PLLConfig( RCC_PLLSource_HSE_Div2, RCC_PLLMul_3 ); + break; + + // 24MHz + case SPEED_LOW : + /* PLLCLK = 12MHz * 2 = 24 MHz */ + RCC_PLLConfig( RCC_PLLSource_HSE_Div1, RCC_PLLMul_2 ); + break; + + // 36MHz + case SPEED_MEDIUM : + default : + /* PLLCLK = 12MHz * 3 = 36 MHz */ + RCC_PLLConfig( RCC_PLLSource_HSE_Div1, RCC_PLLMul_3 ); + break; + + // 48MHz + case SPEED_HIGH : + /* PLLCLK = 12MHz * 4 = 48 MHz */ + RCC_PLLConfig( RCC_PLLSource_HSE_Div1, RCC_PLLMul_4 ); + break; + + // 72MHz + case SPEED_VERY_HIGH : + /* PLLCLK = 12MHz * 6 = 72 MHz */ + RCC_PLLConfig( RCC_PLLSource_HSE_Div1, RCC_PLLMul_6 ); + break; + } + + /* Enable PLL */ + RCC_PLLCmd( ENABLE ); + + /* Wait till PLL is ready */ + while( RCC_GetFlagStatus( RCC_FLAG_PLLRDY ) == RESET ) + { ; } + + /* Select PLL as system clock source */ + RCC_SYSCLKConfig( RCC_SYSCLKSource_PLLCLK ); + + /* Wait till PLL is used as system clock source */ + while( RCC_GetSYSCLKSource() != 0x08 ) + { ; } + + /* This function fills a RCC_ClocksTypeDef structure with the current frequencies + of different on chip clocks (for debug purpose) */ + RCC_GetClocksFreq( &RCC_ClockFreq ); + } + +/******************************************************************************* +* +* UTIL_GetPll +* +*******************************************************************************/ +/** +* +* Get clock frequency +* +* @return Current clock speed from very low to very fast. +* +**/ +/******************************************************************************/ +enum eSpeed UTIL_GetPll( void ) + { + return CurrentSpeed; + } + +/******************************************************************************* +* +* UTIL_GetVersion +* +*******************************************************************************/ +/** +* +* Get CircleOS version. +* +* @return A pointer to a string containing the CircleOS version. +* +**/ +/******************************************************************************/ +const char* UTIL_GetVersion( void ) + { + return OsVersion; + } + +/******************************************************************************* +* +* UTIL_ReadBackupRegister +* +*******************************************************************************/ +/** +* +* Reads data from the specified Data Backup Register. +* +* @param[in] BKP_DR Specifies the Data Backup Register. This parameter can be BKP_DRx where x:[1, 10] +* +* @return The content of the specified Data Backup Register. +* +**/ +/******************************************************************************/ +u16 UTIL_ReadBackupRegister( u16 BKP_DR ) + { + return (*(vu16 *)( BKP_BASE + 4 * BKP_DR ) ); + } + +/******************************************************************************* +* +* UTIL_WriteBackupRegister +* +*******************************************************************************/ +/** +* +* Writes data to the specified Data Backup Register. +* +* @param[in] BKP_DR Specifies the Data Backup Register. This parameter can be BKP_DRx where x:[1, 10] +* @param[in] Data The data to write. +* +**/ +/********************************************************************************/ +void UTIL_WriteBackupRegister( u16 BKP_DR, u16 Data ) + { + *(vu16 *)( BKP_BASE + 4 * BKP_DR ) = Data; + } + + +/******************************************************************************* +* +* UTIL_SetIrqHandler +* +*******************************************************************************/ +/** +* +* Redirect an IRQ handler. +* +* @param[in] Offs Address in the NVIC table +* @param[in] pHDL Pointer to the handler. +* +**/ +/********************************************************************************/ +void UTIL_SetIrqHandler( int Offs, tHandler pHDL ) + { + if ( (Offs >= 8) && (Offs<0x100) ) + *(tHandler *)( CIRCLEOS_RAM_BASE + Offs ) = pHDL; + } + +/******************************************************************************* +* +* UTIL_GetIrqHandler +* +*******************************************************************************/ +/** +* +* Get the current IRQ handler. +* Since (V1.6) the vector table is relocated in RAM, the vectors can be easily modified +* by the applications. +* +* @param[in] Offs Address in the NVIC table +* @return A pointer to the current handler. +* +**/ +/********************************************************************************/ +tHandler UTIL_GetIrqHandler( int Offs ) + { + if ( (Offs >= 8) && (Offs<0x100) ) + return *(tHandler *)( CIRCLEOS_RAM_BASE + Offs ); + } + + + +/******************************************************************************* +* +* UTIL_SetSchHandler +* +*******************************************************************************/ +/** +* +* Redirect a SCHEDULER handler. +* Set the current SCHEDULER handler. With UTIL_GetSchHandler(), these functions +* allow to take the control of the different handler. You can: +* - replace them (get-Set)by your own handler +* - disable a handler: UTIL_SetSchHandler(Ix,0); +* - create a new handler (using the unused handlers). +* See scheduler.c to understand further... +* +* @param[in] Ix ID if the SCH Handler +* @param[in] pHDL Pointer to the handler. +* +**/ +/********************************************************************************/ +void UTIL_SetSchHandler( enum eSchHandler Ix, tHandler pHDL ) + { + if (Ix '0') && (*CurrentMelody < '9') ) + { + duration = *CurrentMelody++ - '0'; + + if ( (*CurrentMelody > '0') && (*CurrentMelody < '9') ) + { + duration *= 10; + duration += (*CurrentMelody++ - '0'); + } + } + + Buzzer_Counter = ( (32/duration) * 256L * 32L) / DefaultBeats; + Buzzer_Counter*= (RCC_ClockFreq.SYSCLK_Frequency / 12000000L); //Adapt to HCLK1 + + //read the note + c = *CurrentMelody++; + + if ( (c >= 'a') && (c <= 'z') ) + { + c+=('A'-'a'); + } + + if ( c == 'P' ) + { + note = NOTE_PAUSE; + } + else if ( (c >= 'A') && (c <= 'G') ) + { + note = (c - 'A') + NOTE_LA; + + if ( *CurrentMelody == '#' ) + { + note|=0x8; + CurrentMelody++; + } + } + + octave = DefaultOctave; + c = *CurrentMelody; + + if ( (c>= '5') && (c<= '8') ) + { + octave = OCT_440 + (c-'5'); + CurrentMelody++; + } + + BUZZER_SetFrequency ( (Note_Freq [ note ] * (1<NOT be called by the user. +* +**/ +/******************************************************************************/ +void BUZZER_Init( void ) + { + GPIO_InitTypeDef GPIO_InitStructure; + + /* Enable GPIOB clock */ + RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE ); + + /* GPIOB Configuration: TIM3 3in Output */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + + GPIO_Init( GPIOB, &GPIO_InitStructure ); + + /* TIM3 Configuration ------------------------------------------------------*/ + /* TIM3CLK = 18 MHz, Prescaler = 0x0, TIM3 counter clock = 18 MHz */ + /* CC update rate = TIM3 counter clock / (2* CCR_Val) ~= 750 Hz */ + + /* Enable TIM3 clock */ + RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3, ENABLE ); + TIM_DeInit( TIM3 ); + TIM_TimeBaseStructInit( &TIM_TimeBaseStructure ); + TIM_OCStructInit( &TIM_OCInitStructure ); + + /* Time base configuration */ + TIM_TimeBaseStructure.TIM_Period = 0xFFFF; + TIM_TimeBaseStructure.TIM_Prescaler = 0x0; + TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + + TIM_TimeBaseInit( TIM3, &TIM_TimeBaseStructure ); + + /* Output Compare Toggle Mode configuration: Channel3 */ + TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle; + TIM_OCInitStructure.TIM_Channel = TIM_Channel_3; + TIM_OCInitStructure.TIM_Pulse = CCR_Val; + + TIM_OCInit( TIM3, &TIM_OCInitStructure ); + TIM_OC3PreloadConfig( TIM3, TIM_OCPreload_Disable ); + BUZZER_SetFrequency( 440 ); + + /* Enable TIM3 IT */ + TIM_ITConfig( TIM3, TIM_IT_CC3, ENABLE ); + + Buzzer_Mode = BUZZER_OFF; + } + +/******************************************************************************* +* +* BUZZER_Handler +* +*******************************************************************************/ +/** +* +* Called by the CircleOS scheduler to manage Buzzer tasks. +* +* @attention This function must NOT be called by the user. +* +**/ +/******************************************************************************/ +void BUZZER_Handler( void ) + { + int fSetOFF = 0; + + if ( Buzzer_Mode == BUZZER_PLAYMUSIC ) + { + if ( Buzzer_Counter == 0 ) + { + PlayMusic(); + } + else + { + Buzzer_Counter--; + } + + return; + } + else if ( Buzzer_Mode == BUZZER_SHORTBEEP ) + { + if ( Buzzer_Counter++ == (BUZZER_SHORTBEEP_DURATION) ) + { + Buzzer_Mode = BUZZER_OFF; + + return; + } + if ( Buzzer_Counter == (BUZZER_SHORTBEEP_DURATION/2) ) + { + fSetOFF = 1; + } + } + else if ( Buzzer_Mode == BUZZER_LONGBEEP ) + { + if ( Buzzer_Counter++ == (BUZZER_LONGBEEP_DURATION) ) + { + Buzzer_Mode = BUZZER_OFF; + + return; + } + if ( Buzzer_Counter > (BUZZER_LONGBEEP_DURATION/2) ) + { + fSetOFF = 1; + } + } + + if ( fSetOFF == 1 ) + { + TIM_Cmd(TIM3, DISABLE); + } + } + +/// @endcond + +/* Public functions ----------------------------------------------------------*/ + +/******************************************************************************* +* +* BUZZER_GetMode +* +*******************************************************************************/ +/** +* +* Get the current buzzer mode. +* +* @return Current buzzer mode. +* +**/ +/******************************************************************************/ +enum BUZZER_mode BUZZER_GetMode( void ) + { + return Buzzer_Mode; + } + +/******************************************************************************* +* +* BUZZER_SetMode +* +*******************************************************************************/ +/** +* +* Set new buzzer mode +* +* @param[in] mode New buzzer mode. +* +**/ +/******************************************************************************/ +void BUZZER_SetMode( enum BUZZER_mode mode ) + { + Buzzer_Mode = mode; + Buzzer_Counter = 0; + + switch ( mode ) + { + case BUZZER_PLAYMUSIC : + PlayMusic(); //start melody + /* no break */ + + case BUZZER_LONGBEEP : + case BUZZER_SHORTBEEP : + case BUZZER_ON : + TIM_Cmd( TIM3, ENABLE ); + break; + + case BUZZER_OFF : + TIM_Cmd( TIM3, DISABLE ); + break; + } + } + +/******************************************************************************* +* +* BUZZER_PlayMusic +* +*******************************************************************************/ +/** +* +* Plays the provided melody that follows the RTTTL Format. +* +* Official Specification +* @verbatim + := + [] + + := + ; maximum name length 10 characters + := ":" + := + | + | + + := "d=" + := "o=" + := "b=" + := 25,28,...,900 ; decimal value +; If not specified, defaults are + ; + ; 4 = duration + ; 6 = scale + ; 63 = beats-per-minute + := + [] [] [] + := + "1" | ; Full 1/1 note + "2" | ; 1/2 note + "4" | ; 1/4 note + "8" | ; 1/8 note + "16" | ; 1/16 note + "32" | ; 1/32 note + := + "P" | ; pause + "C" | + "C#" | + "D" | + "D#" | + "E" | + "F" | + "F#" | + "G" | + "G#" | + "A" | + "A#" | + "B" + := + "5" | ; Note A is 440Hz + "6" | ; Note A is 880Hz + "7" | ; Note A is 1.76 kHz + "8" ; Note A is 3.52 kHz + := + "." ; Dotted note + := "," +@endverbatim +* +* @param[in] melody New melody to play on buzzer. +* +**/ +/******************************************************************************/ +void BUZZER_PlayMusic (const u8 *melody ) + { + u8 c; + u8 default_id = 0; + u16 default_val = 0; + + DefaultOctave = OCT_880; // Default for the default Octave. + DefaultDuration = 4; // Default for the default Duration. + DefaultBeats = 63; + CurrentMelody = melody; + CurrentMelodySTART = melody; + + while( *CurrentMelody != RTTTL_SEP ) + { + if( *CurrentMelody == 0 ) + { + return; + } + + // Discard the melody name. + CurrentMelody++; + } + + // Now read the defaults if any. + for( ++CurrentMelody; *CurrentMelody != RTTTL_SEP; CurrentMelody++ ) + { + if( *CurrentMelody == 0 ) + { + return; + } + + // Discard any blank. + while ( *CurrentMelody == ' ' ) + { + CurrentMelody++; + } + + c = *CurrentMelody; + + if ( c == RTTTL_SEP ) + { + break; + } + + if ( (c >= 'a') && (c <= 'z') ) + { + c+=('A'-'a'); + } + + if ( (c >= 'A') && (c <= 'Z') ) + { + default_id = c; + continue; + } + + if ( (c >= '0') && (c <= '9') ) + { + default_val *= 10; + default_val += (c-'0'); + c = * (CurrentMelody + 1 ); + + if ( (c >= '0') && (c <= '9') ) + { + continue; + } + + if ( default_id == 'D' ) + { + DefaultDuration = default_val; + } + else if ( default_id == 'O' ) + { + DefaultOctave = default_val - 5; + + if ( DefaultOctave > OCT_7040 ) + DefaultOctave = OCT_440; + } + else if ( default_id == 'B' ) + { + DefaultBeats = default_val; + + if ( ( DefaultBeats == 0 ) || ( DefaultBeats > 500 ) ) + DefaultBeats = 63; + } + + default_val = 0; + default_id = 0; + } + } + + BUZZER_SetMode( BUZZER_PLAYMUSIC ); + } diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/circle.h b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/circle.h new file mode 100644 index 000000000..0a7c02177 --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/circle.h @@ -0,0 +1,431 @@ +/********************* (C) COPYRIGHT 2007 RAISONANCE S.A.S. *******************/ +/** +* +* @file circle.h +* @brief General header for the CircleOS project. +* @author FL +* @date 07/2007 +* @version 1.5 +* +* It contains the list of the utilities functions organized by sections +* (MEMS, LCD, POINTER, ...) +* +* @date 10/2007 +* @version 1.5 types of OutX_F64 and OutX_F256 changed to u32 (same for Y and Z) +**/ +/******************************************************************************/ + +#include "scheduler.h" + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __CIRCLE_H +#define __CIRCLE_H + +//-------------------------------- General ------------------------------------- +/* Defines ------------------------------------------------------------------*/ +#define VDD_VOLTAGE_MV 3300 //Voltage (mV) of the STM32 +#define FA_TABLE 0x8006000 +#define TIM2 ((TIM_TypeDef *) TIM2_BASE) +#define CIRCLEOS_RAM_BASE 0x20004000 + +/* Variables ----------------------------------------------------------------*/ +extern GPIO_InitTypeDef GPIO_InitStructure; + +/* Utilities -----------------------------------------------------------------*/ +void UTIL_uint2str( char *ptr , u32 X, u16 digit, int fillwithzero ); +void UTIL_int2str( char *ptr , s32 X, u16 digit, int fillwithzero ); +u16 UTIL_ReadBackupRegister( u16 BKP_DR ); +void UTIL_WriteBackupRegister( u16 BKP_DR, u16 Data ); +u16 UTIL_GetBat( void ); +u8 UTIL_GetUsb( void ); +u16 UTIL_GetTemp ( void ) ; +void UTIL_SetTempMode ( int mode ); +//typedef void (*tHandler) ( void ); +void UTIL_SetIrqHandler ( int , tHandler ); +tHandler UTIL_GetIrqHandler ( int ); +extern u16 ADC_ConvertedValue[17]; + + +extern enum eSpeed + { + SPEED_VERY_LOW = 1, + SPEED_LOW = 2, + SPEED_MEDIUM = 3, + SPEED_HIGH = 4, + SPEED_VERY_HIGH = 5 + } CurrentSpeed; + +enum eSchHandler + { + LED_SCHHDL_ID = 0, + BUTTON_SCHHDL_ID = 1, + BUZZER_SCHHDL_ID = 2, + MENU_SCHHDL_ID = 3, + POINTER_SCHHDL_ID = 4, + LCD_SCHHDL_ID = 5, + DRAW_SCHHDL_ID = 6, + RTC_SCHHDL_ID = 7, + + UNUSED0_SCHHDL_ID = 8, + UNUSED1_SCHHDL_ID = 9, + UNUSED2_SCHHDL_ID = 10, + UNUSED3_SCHHDL_ID = 11, + UNUSED4_SCHHDL_ID = 12, + UNUSED5_SCHHDL_ID = 13, + UNUSED6_SCHHDL_ID = 14, + UNUSED7_SCHHDL_ID = 15 + } dummy_var ; //for doxygen + +void UTIL_SetSchHandler ( enum eSchHandler , tHandler ); +tHandler UTIL_GetSchHandler ( enum eSchHandler ); +#define NULL_SCHHDL (0) +#define LAST_SCHHDL ((tHandler)(-1)) + + +void UTIL_SetPll( enum eSpeed speed ); +const char* UTIL_GetVersion( void ); +enum eSpeed UTIL_GetPll( void ); +extern RCC_ClocksTypeDef RCC_ClockFreq; +extern u8 fTemperatureInFahrenheit; /*!< 1 : Fahrenheit, 0 : Celcius (default). */ + + +//--------------------------------- MEMS ------------------------------------ + +/* Exported types ------------------------------------------------------------*/ +typedef enum + { + V12=0, + V3=1, + V6=2, + V9=3 +} Rotate_H12_V_Match_TypeDef; + +typedef struct + { + s16 OutX ; + s16 OutX_F4 ; + s16 OutX_F16 ; + s32 OutX_F64 ; + s32 OutX_F256 ; + s16 OutY ; + s16 OutY_F4 ; + s16 OutY_F16 ; + s32 OutY_F64 ; + s32 OutY_F256 ; + s16 OutZ ; + s16 OutZ_F4 ; + s16 OutZ_F16 ; + s32 OutZ_F64 ; + s32 OutZ_F256 ; + s16 Shocked ; + s16 RELATIVE_X ; + s16 RELATIVE_Y ; + s16 DoubleClick ; + } tMEMS_Info; + +extern tMEMS_Info MEMS_Info; + +/* Exported functions --------------------------------------------------------*/ +void MEMS_Init(void); +void MEMS_Handler(void); +void MEMS_GetPosition(s16 * pX, s16* pY); +void MEMS_SetNeutral( void ); +void MEMS_GetRotation(Rotate_H12_V_Match_TypeDef * H12); +tMEMS_Info* MEMS_GetInfo (void); +u8 MEMS_ReadID(void); + +//---------------------------------- LED ------------------------------------- + +/* Exported types ------------------------------------------------------------*/ +enum LED_mode { LED_UNDEF = -1, LED_OFF = 0, LED_ON = 1, LED_BLINKING_LF = 2, LED_BLINKING_HF = 3 }; +enum LED_id { LED_GREEN = 0, LED_RED = 1}; + +/* Exported functions --------------------------------------------------------*/ +void LED_Init (void); +void LED_Handler_hw ( enum LED_id id ); +void LED_Handler ( void ); +void LED_Set ( enum LED_id id, enum LED_mode mode ); + +//-------------------------------- ADC -------------------------------------- + +/* Exported functions --------------------------------------------------------*/ +void ADConverter_Init (void); + + +//============================================================================== +//-------------------------------- SHUTDOWN --------------------------------- +/* Exported functions --------------------------------------------------------*/ +void SHUTDOWN_Action (void); + +//-------------------------------- BUTTON ----------------------------------- +/* Exported types ------------------------------------------------------------*/ +enum BUTTON_mode { BUTTON_DISABLED = -1, BUTTON_ONOFF = 0, + BUTTON_ONOFF_FORMAIN = 1, BUTTON_WITHCLICK = 2 }; +enum BUTTON_state { BUTTON_UNDEF = -1, BUTTON_RELEASED = 0, BUTTON_PUSHED = 1, + BUTTON_PUSHED_FORMAIN = 2 , BUTTON_CLICK = 3, BUTTON_DBLCLICK = 4 }; + +/* Exported functions -------------------------------------------------------*/ +void BUTTON_Init (void); +void BUTTON_Handler(void); +enum BUTTON_state BUTTON_GetState(); +void BUTTON_SetMode( enum BUTTON_mode mode); +enum BUTTON_mode BUTTON_GetMode ( void ) ; +void BUTTON_WaitForRelease(); + +//-------------------------------- POINTER ---------------------------------- + +/* Exported types ------------------------------------------------------------*/ +enum POINTER_mode { POINTER_UNDEF = -1, POINTER_OFF = 0, POINTER_ON = 1, POINTER_MENU = 2, POINTER_APPLICATION = 3, POINTER_RESTORE_LESS = 4 }; +enum POINTER_state { POINTER_S_UNDEF = -1, POINTER_S_DISABLED = 0, POINTER_S_ENABLED = 1 }; + +/* Exported defines ----------------------------------------------------------*/ +#define POINTER_WIDTH 7 + +typedef struct + { + s16 xPos ; + s16 yPos ; + s16 shift_PosX ; + s16 shift_PosY ; + s16 X_PosMin ; + s16 Y_PosMin ; + s16 X_PosMax ; + s16 Y_PosMax ; + } tPointer_Info; + +extern tPointer_Info POINTER_Info ; + +/* Exported vars -------------------------------------------------------------*/ +extern unsigned char *BallPointerBmpSize; +extern unsigned char BallPointerBmp [POINTER_WIDTH], *CurrentPointerBmp,*CurrentPointerSize; +extern u16 CurrentPointerColor; +extern u16 BallColor; +extern s16 POINTER_X_PosMin; +extern s16 POINTER_Y_PosMin; +extern s16 POINTER_X_PosMax; +extern s16 POINTER_Y_PosMax; +extern unsigned char PointerAreaStore [2*POINTER_WIDTH*POINTER_WIDTH]; + +/* Exported functions --------------------------------------------------------*/ +extern void POINTER_Init ( void ) ; +void POINTER_Handler(void); +u16 POINTER_GetCurrentAngleStart ( void ); +void POINTER_SetCurrentAngleStart ( u16 ); +u16 POINTER_GetCurrentSpeedOnAngle ( void ); +void POINTER_SetCurrentSpeedOnAngle ( u16 newspeed ); +void POINTER_SetMode( enum POINTER_mode mode); +void POINTER_SetCurrentPointer( unsigned char width, unsigned char height, unsigned char *bmp); +enum POINTER_state POINTER_GetState(void); +void POINTER_Draw (u8 Line, u8 Column, u8 Width, u8 Height, u8 *Bmp); +void POINTER_SetRect ( s16 x, s16 y, s16 width, s16 height ); //Restrict the move of the pointer to a rectangle +void POINTER_SetRectScreen ( void ); //Remove any space restriction for the pointer moves. +void POINTER_Save (u8 Line, u8 Column, u8 Width, u8 Height); +void POINTER_Restore (u8 Line, u8 Column, u8 Width, u8 Height); +u16 POINTER_GetPos(void); //Return the poistion of the cursor (x=lower byte, y = upperbyte) +void POINTER_SetPos ( u16 x, u16 y ); +typedef void (*tAppPtrMgr) ( int , int ); +void POINTER_SetApplication_Pointer_Mgr( tAppPtrMgr mgr ); +tPointer_Info* POINTER_GetInfo ( void ); +u16 POINTER_GetColor ( void ) ; +void POINTER_SetColor ( u16 color ); +enum POINTER_mode POINTER_GetMode( void ); +void POINTER_SetCurrentAreaStore ( u8 *ptr ); +void LCD_SetRotateScreen ( u8 RotateScreen); +u8 LCD_GetRotateScreen (); +void LCD_SetScreenOrientation (Rotate_H12_V_Match_TypeDef ScreenOrientation); +Rotate_H12_V_Match_TypeDef LCD_GetScreenOrientation (); + +//---------------------------------- LCD ----------------------------------- + +/* Exported defines ----------------------------------------------------------*/ +//RGB is 16-bit coded as G2G1G0B4 B3B2B1B0 R4R3R2R1 R0G5G4G3 +#define RGB_MAKE(xR,xG,xB) ( ( (xG&0x07)<<13 ) + ( (xG)>>5 ) + \ + ( ((xB)>>3) << 8 ) + \ + ( ((xR)>>3) << 3 ) ) +#define RGB_RED 0x00F8 +#define RGB_BLACK 0x0000 +#define RGB_WHITE 0xffff +#define RGB_BLUE 0x1F00 +#define RGB_GREEN 0xE007 +#define RGB_YELLOW (RGB_GREEN|RGB_RED) +#define RGB_MAGENTA (RGB_BLUE|RGB_RED) +#define RGB_LIGHTBLUE (RGB_BLUE|RGB_GREEN) +#define RGB_ORANGE (RGB_RED | 0xE001) //green/2 + red +#define RGB_PINK (RGB_MAGENTA | 0xE001) //green/2 + magenta + +// SCREEN Infos +#define SCREEN_WIDTH 128 +#define SCREEN_HEIGHT 128 +#define CHIP_SCREEN_WIDTH 132 +#define CHIP_SCREEN_HEIGHT 132 + +// Characters Infos +#define CHAR_WIDTH 7 +#define CHAR_HEIGHT 14 + +// PWM rates. +#define BACKLIGHTMIN 0x1000 /*!< Minimal PWM rate. */ +#define DEFAULT_CCR_BACKLIGHTSTART 0x8000 /*!< Default PWM rate. */ + +/* Exported vars -------------------------------------------------------------*/ +extern Rotate_H12_V_Match_TypeDef Screen_Orientation; +extern int rotate_screen; + +/* Exported functions --------------------------------------------------------*/ +void LCD_Init(void); +void LCD_Handler(void); +void LCD_SetRect_For_Cmd( s16 x, s16 y, s16 width, s16 height ); +u16 LCD_GetPixel( u8 x, u8 y ); +void LCD_DrawPixel( u8 x, u8 y, u16 Pixel ); +void LCD_SendLCDCmd( u8 Cmd ); +void LCD_SendLCDData( u8 Data ); +u32 LCD_ReadLCDData( void ); +void LCD_FillRect( u16 x, u16 y, u16 width, u16 height, u16 color ); +void LCD_DrawRect( u16 x, u16 y, u16 width, u16 height, u16 color ); +void LCD_DisplayChar( u8 x, u8 y, u8 Ascii, u16 TextColor, u16 BGndColor, u16 CharMagniCoeff ); +void LCD_RectRead( u16 x, u16 y, u16 width, u16 height, u8* bmp ); +void LCD_SetBackLight (u32 newBacklightStart); +u32 LCD_GetBackLight ( void ); +void LCD_SetBackLightOff( void ); +void LCD_SetBackLightOn( void ); + +#include "lcd.h" + +//---------------------------------- DRAW ---------------------------------- + +/* Exported functions --------------------------------------------------------*/ +void DRAW_Init(void); +void DRAW_Clear(void); +void DRAW_Handler(void); +void DRAW_SetDefaultColor (void); +void DRAW_SetImage(const u16 *imageptr, u8 x, u8 y, u8 width, u8 height); +void DRAW_SetImageBW(const u8 *imageptr, u8 x, u8 y, u8 width, u8 height); +void DRAW_SetLogoBW(void); +void DRAW_DisplayVbat(u8 x, u8 y); +void DRAW_DisplayTime(u8 x, u8 y); +void DRAW_DisplayTemp(u8 x, u8 y); +void DRAW_DisplayString( u8 x, u8 y, const u8 *ptr, u8 len ); +void DRAW_DisplayStringInverted( u8 x, u8 y, const u8 *ptr, u8 len ); +u16 DRAW_GetCharMagniCoeff(void); +void DRAW_SetCharMagniCoeff(u16 Coeff); +u16 DRAW_GetTextColor(void); +void DRAW_SetTextColor(u16 Color); +u16 DRAW_GetBGndColor(void); +void DRAW_SetBGndColor(u16 Color); +void DRAW_Batt( void ); +void DRAW_Line (s16 x1, s16 y1, s16 x2, s16 y2, u16 color ); + +/* Exported vars -------------------------------------------------------------*/ +extern int fDisplayTime; + + +//-------------------------------- BUZZER ----------------------------------- + +/* Exported defines ----------------------------------------------------------*/ +#define BUZZER_BEEP BUZZER_SHORTBEEP + +/* Exported type def ---------------------------------------------------------*/ +enum BUZZER_mode { BUZZER_UNDEF = -1, BUZZER_OFF = 0, BUZZER_ON = 1, + BUZZER_SHORTBEEP = 2, BUZZER_LONGBEEP = 3, BUZZER_PLAYMUSIC = 4 }; + +/* Exported type functions ---------------------------------------------------*/ +void BUZZER_Init(void); +void BUZZER_Handler(void); +void BUZZER_SetMode( enum BUZZER_mode mode); +enum BUZZER_mode BUZZER_GetMode( void ); +void BUZZER_PlayMusic (const u8 *melody ); + +//--------------------------------- MENU ----------------------------------- + +/* Exported defines ----------------------------------------------------------*/ +#define MENU_MAXITEM 6 +#define APP_VOID ((tMenuItem *)(-1)) +#define MAX_APP_MENU_SIZE 10 +#define MAXAPP 64 +#define MAX_MENUAPP_SIZE 3 +#define REMOVE_MENU 0x01 +#define APP_MENU 0x02 + +enum MENU_code { MENU_LEAVE = 0, MENU_CONTINUE = 1, MENU_REFRESH = 2, + MENU_CHANGE = 3, MENU_CONTINUE_COMMAND = 4}; + +/* Exported type def ---------------------------------------------------------*/ +typedef struct + { + const char *Text; + enum MENU_code (*Fct_Init) ( void ); + enum MENU_code (*Fct_Manage)( void ); + int fMenuFlag; + } tMenuItem; + +typedef struct + { + unsigned fdispTitle : 1; + const char *Title; + int NbItems; + int LgMax; + int XPos, YPos; + int XSize, YSize; + unsigned int SelectedItem; + tMenuItem Items[MENU_MAXITEM]; + } tMenu; + +/* Exported vars -------------------------------------------------------------*/ +extern tMenu MainMenu, *CurrentMenu; +extern tMenuItem *CurrentCommand; +extern int BGndColor_Menu; +extern int TextColor_Menu; + +/* Exported type functions ---------------------------------------------------*/ +enum MENU_code fColor ( void ) ; +void MENU_Set ( tMenu *mptr ); +void MENU_Handler ( void ) ; +extern enum MENU_code MENU_Quit ( void ); +void MENU_Remove ( void ) ; +void MENU_Question ( char *str, int *answer ); +void MENU_Print ( char *str ); +enum MENU_code MENU_SetLevel_Ini( void ); +enum MENU_code MENU_SetLevel_Mgr( u32 *value, u32 value_range [] ) ; +void MENU_ClearCurrentCommand( void ); +void MENU_SetLevelTitle(u8* title); +void MENU_SetTextColor ( int TextColor ); +int MENU_GetTextColor ( void ); +void MENU_SetBGndColor ( int BGndColor ); +int MENU_GetBGndColor ( void ); +extern enum MENU_code fQuit ( void ) ; +void MENU_ClearCurrentMenu(void); + +//-------------------------------- BACKLIGHT -------------------------------- + +/* Exported type functions ---------------------------------------------------*/ +void BackLight_Configuration (void); +void ManageBackLight (void); +void BackLight_Change (void); + +//-------------------------------- RTC -------------------------------------- + +/* Exported type functions ---------------------------------------------------*/ +void RTC_Init(void); +void RTC_SetTime (u32 THH, u32 TMM, u32 TSS); +void RTC_GetTime (u32 * THH, u32 * TMM, u32 * TSS); +void RTC_DisplayTime ( void ); + +//Backup registers +#define BKP_SYS1 1 +#define BKP_SYS2 2 +#define BKP_SYS3 3 +#define BKP_SYS4 4 +#define BKP_SYS5 5 +#define BKP_SYS6 6 +#define BKP_USER1 7 +#define BKP_USER2 8 +#define BKP_USER3 9 +#define BKP_USER4 10 + +#define BKP_PLL (BKP_SYS2) +#define BKP_BKLIGHT (BKP_SYS3) + +//--------------------------------- Application -------------------------------- +void (*Application_Pointer_Mgr) ( int sposX, int sposY); + +#endif /*__CIRCLE_H */ diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/circle_api.h b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/circle_api.h new file mode 100644 index 000000000..f3cdb8f77 --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/circle_api.h @@ -0,0 +1,679 @@ +/********************* (C) COPYRIGHT 2007 RAISONANCE S.A.S. *******************/ +/** +* +* @file circle_api.h +* @brief General header for the STM32-circle projects. +* @author FL +* @date 07/2007 +* @version 1.2 +* @date 10/2007 +* @version 1.5 types of OutX_F64 and OutX_F256 changed to u32 (same for Y and Z) +* @date 10/2007 +* @version 1.6 Add the IRQ handler replacement +* +* It contains the list of the utilities functions organized by sections +* (MEMS, LCD, POINTER, ...) +* +**/ +/******************************************************************************* +* +* Use this header with version 1.5 or later of the OS. +* +* For a complete documentation on the CircleOS, please go to: +* http://www.stm32circle.com +* +*******************************************************************************/ + +#include "stm32f10x_lib.h" + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __CIRCLE_API_H +#define __CIRCLE_API_H + +//-------------------------------- General ------------------------------------- + +/** +* @enum eSpeed +* @brief Clock speeds. +* +* Available clock speeds. +**/ +extern enum eSpeed + { + SPEED_VERY_LOW = 1, + SPEED_LOW = 2, + SPEED_MEDIUM = 3, + SPEED_HIGH = 4, + SPEED_VERY_HIGH = 5 + } CurrentSpeed; +enum eSchHandler + { + LED_SCHHDL_ID = 0, + BUTTON_SCHHDL_ID = 1, + BUZZER_SCHHDL_ID = 2, + MENU_SCHHDL_ID = 3, + POINTER_SCHHDL_ID = 4, + LCD_SCHHDL_ID = 5, + DRAW_SCHHDL_ID = 6, + RTC_SCHHDL_ID = 7, + + UNUSED0_SCHHDL_ID = 8, + UNUSED1_SCHHDL_ID = 9, + UNUSED2_SCHHDL_ID = 10, + UNUSED3_SCHHDL_ID = 11, + UNUSED4_SCHHDL_ID = 12, + UNUSED5_SCHHDL_ID = 13, + UNUSED6_SCHHDL_ID = 14, + UNUSED7_SCHHDL_ID = 15 + }; + + +/// @cond Internal + +extern RCC_ClocksTypeDef RCC_ClockFreq; + +/* Typedefs ------------------------------------------------------------------*/ +typedef u32 (*tCircleFunc0 ) (void); +typedef u32 (*tCircleFunc1 ) (u32 param1); +typedef u32 (*tCircleFunc2 ) (u32 param1, u32 param2); +typedef u32 (*tCircleFunc3 ) (u32 param1, u32 param2, u32 param3); +typedef u32 (*tCircleFunc4 ) (u32 param1, u32 param2, u32 param3, u32 param4); +typedef u32 (*tCircleFunc5 ) (u32 param1, u32 param2, u32 param3, u32 param4, u32 param5); +typedef u32 (*tCircleFunc6 ) (u32 param1, u32 param2, u32 param3, u32 param4, u32 param5, u32 param6); + +extern tCircleFunc0 (*ptrCircle_API) []; + +/* Defines -------------------------------------------------------------------*/ +#define Circle_API (*ptrCircle_API) + +#define POINTER_ID 0x00 +#define DRAW_ID 0x20 +#define LCD_ID 0x40 +#define LED_ID 0x60 +#define MEMS_ID 0x70 +#define BUTTON_ID 0x80 +#define BUZZER_ID 0x90 +#define MENU_ID 0xA0 +#define UTIL_ID 0xB0 +#define RTC_ID 0xC0 + +// UTIL functions definition. +#define UTIL_SET_PLL_ID (UTIL_ID + 0) // Set clock frequency. +#define UTIL_GET_PLL_ID (UTIL_ID + 1) // Get clock frequency. +#define UTIL_UINT2STR_ID (UTIL_ID + 2) // Convert an unsigned integer into a string. +#define UTIL_INT2STR_ID (UTIL_ID + 3) // Convert a signed integer into a string. +#define UTIL_GET_VERSION_ID (UTIL_ID + 4) // Get CircleOS version. +#define UTIL_READ_BACKUPREGISTER_ID (UTIL_ID + 5) // Reads data from the specified Data Backup Register. +#define UTIL_WRITE_BACKUPREGISTER_ID (UTIL_ID + 6) // Writes data to the specified Data Backup Register. +#define UTIL_GET_BAT_ID (UTIL_ID + 7) // Return the batterie tension in mV. +#define UTIL_GET_USB_ID (UTIL_ID + 8) // Return the USB connexion state. +#define UTIL_SET_IRQ_HANDLER_ID (UTIL_ID + 9) // Replace an irq handler +#define UTIL_GET_IRQ_HANDLER_ID (UTIL_ID + 10) // Get the current irq handler +#define UTIL_SET_SCH_HANDLER_ID (UTIL_ID + 11) // Replace an irq handler +#define UTIL_GET_SCH_HANDLER_ID (UTIL_ID + 12) // Get the current irq handler +#define UTIL_GET_TEMP_ID (UTIL_ID + 13) // Return the temperature (1/100 C) +#define UTIL_SET_TEMPMODE_ID (UTIL_ID + 14) // Set the temperature mode (0: mCelcius, 1: mFahrenheit +typedef void (*tHandler) (void); + +// Prototypes. +#define UTIL_SetPll(a) ((tCircleFunc1)(Circle_API [UTIL_SET_PLL_ID])) ((u32)(a)) // void UTIL_SetPll( enum eSpeed speed ); +#define UTIL_GetPll() (u32) (((tCircleFunc0)(Circle_API [UTIL_GET_PLL_ID])) ()) // enum eSpeed UTIL_GetPll( void ); +#define UTIL_uint2str(a,b,c,d) ((tCircleFunc4)(Circle_API [UTIL_UINT2STR_ID])) ((u32)(a),(u32)(b),(u32)(c),(u32)(d)) // void uint2str( char* ptr , u32 X, u16 digit, int fillwithzero ); +#define UTIL_int2str(a,b,c,d) ((tCircleFunc4)(Circle_API [UTIL_INT2STR_ID])) ((u32)(a),(u32)(b),(u32)(c),(u32)(d)) // void int2str( char* ptr , s32 X, u16 digit, int fillwithzero ); +#define UTIL_GetVersion() (u32) (((tCircleFunc0)(Circle_API [UTIL_GET_VERSION_ID])) ()) // char* UTIL_GetVersion( void ); +#define UTIL_ReadBackupRegister(a) (u32) (((tCircleFunc1)(Circle_API [UTIL_READ_BACKUPREGISTER_ID])) ((u32)(a))) // u16 UTIL_ReadBackupRegister( u16 BKP_DR ); +#define UTIL_WriteBackupRegister(a,b) ((tCircleFunc2)(Circle_API [UTIL_WRITE_BACKUPREGISTER_ID])) ((u32)(a),(u32)(b)) // void UTIL_WriteBackupRegister( u16 BKP_DR, u16 Data ); +#define UTIL_GetBat() (u32) (((tCircleFunc0)(Circle_API [UTIL_GET_BAT_ID])) ()) // u16 UTIL_GetBat( void ); +#define UTIL_GetUsb() (u32) (((tCircleFunc0)(Circle_API [UTIL_GET_USB_ID])) ()) // u8 UTIL_GetUsb( void ); +#define UTIL_SetIrqHandler(a,b) (((tCircleFunc2)(Circle_API [UTIL_SET_IRQ_HANDLER_ID])) ((int)a,(tHandler)b)) // void UTIL_SetIrqHandler ( int , tHandler ); +#define UTIL_GetIrqHandler(a) (u32) (((tCircleFunc1)(Circle_API [UTIL_GET_IRQ_HANDLER_ID])) ((int)a)) // tHandler* UTIL_GetIrqHandler ( int ); +#define UTIL_SetSchHandler(a,b) (((tCircleFunc2)(Circle_API [UTIL_SET_SCH_HANDLER_ID])) ((int)a,(tHandler)b)) // void UTIL_SetSchHandler ( int , tHandler ); +#define UTIL_GetSchHandler(a) (u32) (((tCircleFunc1)(Circle_API [UTIL_GET_SCH_HANDLER_ID])) ((int)a)) // tHandler* UTIL_GetSchHandler ( int ); +#define UTIL_GetTemp() (u32) (((tCircleFunc0)(Circle_API [UTIL_GET_TEMP_ID])) ()) // u16 UTIL_GetTemp( void ); +#define UTIL_SetTempMode(a) (((tCircleFunc1)(Circle_API [UTIL_SET_TEMPMODE_ID])) ((int)a)) // void UTIL_SetTempMode( int mode ); + +/// @endcond + +//--------------------------------- MEMS ------------------------------------ + +/* Exported types ------------------------------------------------------------*/ + +/** +* @enum Rotate_H12_V_Match_TypeDef +* @brief The 4 possible rotations. +* +* The 4 possible MEM rotations. +**/ +typedef enum + { + V12 = 0, /*!< No rotation. */ + V3 = 1, /*!< Rotation to the right.*/ + V6 = 2, /*!< Rotation to the left. */ + V9 = 3 /*!< Half a rotation. */ + } Rotate_H12_V_Match_TypeDef; + +/** +* @struct tMEMS_Info +* @brief MEMS state description. +**/ +typedef struct + { + s16 OutX; /*!< MEMS X position. */ + s16 OutX_F4; /*!< MEMS X position filtered on 4 values. */ + s16 OutX_F16; /*!< MEMS X position filtered on 16 values. */ + s32 OutX_F64; /*!< MEMS X position filtered on 64 values. */ + s32 OutX_F256; /*!< MEMS X position filtered on 256 values. */ + s16 OutY; /*!< MEMS Y position. */ + s16 OutY_F4; /*!< MEMS Y position filtered on 4 values. */ + s16 OutY_F16; /*!< MEMS Y position filtered on 16 values. */ + s32 OutY_F64; /*!< MEMS Y position filtered on 64 values. */ + s32 OutY_F256; /*!< MEMS Y position filtered on 256 values. */ + s16 OutZ; /*!< MEMS Z position. */ + s16 OutZ_F4; /*!< MEMS Z position filtered on 4 values. */ + s16 OutZ_F16; /*!< MEMS Z position filtered on 16 values. */ + s32 OutZ_F64; /*!< MEMS Z position filtered on 64 values. */ + s32 OutZ_F256; /*!< MEMS Z position filtered on 256 values. */ + s16 Shocked; /*!< MEMS shock counter (incremented...) */ + s16 RELATIVE_X; /*!< MEMS relative X position. */ + s16 RELATIVE_Y; /*!< MEMS relative Y position. */ + s16 DoubleClick; /*!< MEMS DoubleClick counter(incremented...)*/ + } tMEMS_Info; + +/// @cond Internal + +/* Exported defines ----------------------------------------------------------*/ + +// MEMS functions definition +#define MEMS_GET_POSITION_ID (MEMS_ID + 0) // Return the current (relative) Mems information +#define MEMS_GET_ROTATION_ID (MEMS_ID + 1) // Return the current screen orientation of the circle +#define MEMS_SET_NEUTRAL_ID (MEMS_ID + 2) // Set the current position as "neutral position" +#define MEMS_GET_INFO_ID (MEMS_ID + 3) // Return Mems informations + +// Prototypes +#define MEMS_GetPosition(a,b) ((tCircleFunc2)(Circle_API [MEMS_GET_POSITION_ID])) ((u32)(a),(u32)(b)) // void MEMS_GetPosition(s16 * pX, s16* pY); +#define MEMS_GetRotation(a) ((tCircleFunc1)(Circle_API [MEMS_GET_ROTATION_ID])) ((u32)(a)) // void MEMS_GetRotation(Rotate_H12_V_Match_TypeDef * H12); +#define MEMS_SetNeutral() ((tCircleFunc0)(Circle_API [MEMS_GET_ROTATION_ID])) () // void MEMS_SetNeutral( void ); +#define MEMS_GetInfo() ( (tMEMS_Info*) (((tCircleFunc0)(Circle_API [MEMS_GET_INFO_ID])) ())) // tMEMS_Info* MEMS_GetInfo (void) + +/// @endcond + +//-------------------------------- POINTER ---------------------------------- + +/* Exported types ------------------------------------------------------------*/ + +/** +* @enum POINTER_mode +* @brief Available pointer modes. +* +* Description of all the available pointer modes in CircleOS. +**/ +enum POINTER_mode + { + POINTER_UNDEF = -1, /*!< Pointer's mode is unknown! */ + POINTER_OFF = 0, /*!< Pointer isn't managed and displayed. */ + POINTER_ON = 1, /*!< Pointer mode used in main screen. */ + POINTER_MENU = 2, /*!< Pointer management is used to select item menu (but pointer isn't displayed). */ + POINTER_APPLICATION = 3, /*!< The managment of pointer depend of extern application. */ + POINTER_RESTORE_LESS = 4 /*!< The background isn't restored (to go faster). */ + }; + +/** +* @enum POINTER_state +* @brief The different pointer modes. +* +* Despite beeing in a undefined state, the pointer can be disabled or enable. +**/ +enum POINTER_state + { + POINTER_S_UNDEF = -1, /*!< Pointer state is unknown! */ + POINTER_S_DISABLED = 0, /*!< Pointer is disabled. */ + POINTER_S_ENABLED = 1 /*!< Pointer is enabled. */ + }; + +/** +* @struct tPointer_Info +* @brief Pointer position description. +**/ +typedef struct + { + s16 xPos; /*!< X position of pointer. */ + s16 yPos; /*!< Y position of pointer. */ + s16 shift_PosX; /*!< Pointer speed on X axis. */ + s16 shift_PosY; /*!< Pointer speed on Y axis */ + s16 X_PosMin; /*!< Minimum position on X axis. */ + s16 Y_PosMin; /*!< Minimum position on Y axis. */ + s16 X_PosMax; /*!< Maximum position on X axis. */ + s16 Y_PosMax; /*!< Maximum position on Y axis. */ + } tPointer_Info; + +/// @cond Internal + +/* Exported defines ---------------------------------------------------------*/ +#define POINTER_WIDTH 7 + +// POINTER functions definition +#define POINTER_SET_RECT_ID (POINTER_ID + 0) // Set new limits for the move of the pointer +#define POINTER_SETRECTSCREEN_ID (POINTER_ID + 1) // Remove any space restriction for the pointer moves. +#define POINTER_GETCURRENTANGLESTART_ID (POINTER_ID + 2) // Return the current minimum angle to move pointer +#define POINTER_SETCURRENTANGLESTART_ID (POINTER_ID + 3) // Set the current minimum angle to move pointer +#define POINTER_GETCURRENTSPEEDONANGLE_ID (POINTER_ID + 4) // Return the ratio speed / angle +#define POINTER_SETCURRENTSPEEDONANGLE_ID (POINTER_ID + 5) // Set the ratio speed / angle +#define POINTER_SETMODE_ID (POINTER_ID + 6) // Change the current mode of the pointer management +#define POINTER_GETMODE_ID (POINTER_ID + 7) // Return the current mode of the pointer management +#define POINTER_SETCURRENTPOINTER_ID (POINTER_ID + 8) // Set the dimention and bitmap of pointer +#define POINTER_GETSTATE_ID (POINTER_ID + 9) // Return the current state +#define POINTER_DRAW_ID (POINTER_ID + 10) // Draw a pointer +#define POINTER_SAVE_ID (POINTER_ID + 11) // Save the background of the pointer +#define POINTER_RESTORE_ID (POINTER_ID + 12) // Restore the background of the pointer +#define POINTER_GETPOSITION_ID (POINTER_ID + 13) // Return the poistion of the cursor (x=lower byte, y = upperbyte) +#define POINTER_SETPOSITION_ID (POINTER_ID + 14) // Force the position of the pointer in the screen +#define POINTER_SETAPPLICATION_POINTER_MGR_ID (POINTER_ID + 15) // Set the application pointer manager +#define POINTER_SETCOLOR_ID (POINTER_ID + 16) // Set pointer color +#define POINTER_GETCOLOR_ID (POINTER_ID + 17) // Return pointer color +#define POINTER_GETINFO_ID (POINTER_ID + 18) // Return pointer informations +#define POINTER_SET_CURRENT_AREASTORE_ID (POINTER_ID + 19) // Change the current storage area + +// Prototypes +#define POINTER_SetRect(a,b,c,d) ((tCircleFunc4)(Circle_API [POINTER_SET_RECT_ID])) ((u32)(a),(u32)(b),(u32)(c),(u32)(d)) //void POINTER_SetRect ( s16 x, s16 y, s16 width, s16 height ); //Restrict the move of the pointer to a rectangle +#define POINTER_SetRectScreen() ((tCircleFunc0)(Circle_API [POINTER_SETRECTSCREEN_ID])) () //void POINTER_SetRectScreen ( void ); +#define POINTER_GetCurrentAngleStart() (u16) (((tCircleFunc0)(Circle_API [POINTER_GETCURRENTANGLESTART_ID])) ()) //u16 POINTER_GetCurrentAngleStart ( void ); +#define POINTER_SetCurrentAngleStart(a) ((tCircleFunc1)(Circle_API [POINTER_SETCURRENTANGLESTART_ID])) ((u32)(a)) //void POINTER_SetCurrentAngleStart ( u16 ); +#define POINTER_GetCurrentSpeedOnAngle() (u16) (((tCircleFunc0)(Circle_API [POINTER_GETCURRENTSPEEDONANGLE_ID])) ()) //u16 POINTER_GetCurrentSpeedOnAngle ( void ); +#define POINTER_SetCurrentSpeedOnAngle(a) ((tCircleFunc1)(Circle_API [POINTER_SETCURRENTSPEEDONANGLE_ID])) ((u32)(a)) //void POINTER_SetCurrentSpeedOnAngle ( u16 newspeed ); +#define POINTER_SetMode(a) ((tCircleFunc1)(Circle_API [POINTER_SETMODE_ID])) ((u32)(a)) //void POINTER_SetMode( enum POINTER_mode mode); +#define POINTER_GetMode() (enum POINTER_mode) (((tCircleFunc0)(Circle_API [POINTER_GETMODE_ID])) ()) //enum POINTER_mode POINTER_GetMode( void ); +#define POINTER_SetCurrentPointer(a,b,c) ((tCircleFunc3)(Circle_API [POINTER_SETCURRENTPOINTER_ID])) ((u32)(a),(u32)(b),(u32)(c)) //void POINTER_SetCurrentPointer( unsigned char width, unsigned char height, unsigned char *bmp); +#define POINTER_GetState() (enum POINTER_state) (((tCircleFunc0)(Circle_API [POINTER_GETSTATE_ID])) ()) //enum POINTER_state POINTER_GetState(void); +#define POINTER_Draw(a,b,c,d,e) ((tCircleFunc5)(Circle_API [POINTER_DRAW_ID])) ((u32)(a),(u32)(b),(u32)(c),(u32)(d),(u32)(e)) //void POINTER_Draw (u8 Line, u8 Column, u8 Width, u8 Height, u8 *Bmp); +#define POINTER_Save(a,b,c,d) ((tCircleFunc4)(Circle_API [POINTER_SAVE_ID])) ((u32)(a),(u32)(b),(u32)(c),(u32)(d)) //void POINTER_Save (u8 Line, u8 Column, u8 Width, u8 Height); +#define POINTER_Restore(a,b,c,d) ((tCircleFunc4)(Circle_API [POINTER_RESTORE_ID])) ((u32)(a),(u32)(b),(u32)(c),(u32)(d)) //void POINTER_Restore (u8 Line, u8 Column, u8 Width, u8 Height); +#define POINTER_GetPos() (u16) (((tCircleFunc0)(Circle_API [POINTER_GETPOSITION_ID])) ()) //u16 POINTER_GetPos(void); +#define POINTER_SetPos(a,b) ((tCircleFunc2)(Circle_API [POINTER_SETPOSITION_ID])) ((u32)(a),(u32)(b)) //void POINTER_SetPos ( u16 x, u16 y ); +#define POINTER_SetApplication_Pointer_Mgr(a) ((tCircleFunc1)(Circle_API [POINTER_SETAPPLICATION_POINTER_MGR_ID])) ((u32)(a)) //void POINTER_SetApplication_Pointer_Mgr( tAppPtrMgr mgr ); +#define POINTER_SetColor(a) ((tCircleFunc1)(Circle_API [POINTER_SETCOLOR_ID])) ((u32)(a)) //void POINTER_SetColor ( u16 color ) +#define POINTER_GetColor() (u16) (((tCircleFunc0)(Circle_API [POINTER_GETCOLOR_ID])) ()) //u16 POINTER_GetColor ( void ) +#define POINTER_GetInfo() (tPointer_Info*) (((tCircleFunc0)(Circle_API [POINTER_GETINFO_ID])) ()) //tPointer_Info* POINTER_GetInfo ( void ) +#define POINTER_SetCurrentAreaStore(a) ((tCircleFunc1)(Circle_API [POINTER_SET_CURRENT_AREASTORE_ID])) ((u32)(a)) //void POINTER_SetCurrentAreaStore ( u8 *ptr ) + +/// @endcond + +//-------------------------------- BUTTON ----------------------------------- + +/* Exported types ------------------------------------------------------------*/ + +/** +* @enum BUTTON_mode +* @brief Available button modes. +* +* List of all the available button mode in the CircleOS. +**/ +enum BUTTON_mode + { + BUTTON_DISABLED = -1, /*!< No action on the button is detected. */ + BUTTON_ONOFF = 0, /*!< Detect ON/OFF pression type. */ + BUTTON_ONOFF_FORMAIN = 1, /*!< Special mode for main screen. */ + BUTTON_WITHCLICK = 2 /*!< Currently unused. */ + }; + +/** +* @enum BUTTON_state +* @brief CircleOS button states. +* +* Description of the button states provided by CircleOS. +**/ +enum BUTTON_state + { + BUTTON_UNDEF = -1, /*!< Undefined state. */ + BUTTON_RELEASED = 0, /*!< Button is released. */ + BUTTON_PUSHED = 1, /*!< Button was just pushed. */ + BUTTON_PUSHED_FORMAIN = 2, /*!< Same as BUTTON_PUSHED when button mode is BUTTON_ONOFF_FORMAIN. */ + BUTTON_CLICK = 3, /*!< Currently unused. */ + BUTTON_DBLCLICK = 4 /*!< Currently unused. */ + }; + +/// @cond Internal + +/* Exported defines ----------------------------------------------------------*/ + +// BUTTON functions definition +#define BUTTON_GETSTATE_ID (BUTTON_ID + 0) // Return state of button +#define BUTTON_SETMODE_ID (BUTTON_ID + 1) // Set button mode +#define BUTTON_GETMODE_ID (BUTTON_ID + 2) // Return button mode +#define BUTTON_WAITFORRELEASE_ID (BUTTON_ID + 3) // Disable temporarily any new button event + +// Prototypes +#define BUTTON_GetState() (enum BUTTON_state) (((tCircleFunc0)(Circle_API [BUTTON_GETSTATE_ID])) ()) // enum BUTTON_state BUTTON_GetState(void); +#define BUTTON_SetMode(a); ((tCircleFunc1)(Circle_API [BUTTON_SETMODE_ID])) ((u32)(a)) // void BUTTON_SetMode( enum BUTTON_mode mode); +#define BUTTON_GetMode(); (enum BUTTON_mode) (((tCircleFunc0)(Circle_API [BUTTON_GETMODE_ID])) ()) // enum BUTTON_mode BUTTON_GetMode ( void ) ; +#define BUTTON_WaitForRelease() ((tCircleFunc0)(Circle_API [BUTTON_WAITFORRELEASE_ID])) () // void BUTTON_WaitForRelease(void); + +/// @endcond + +//---------------------------------- LCD ----------------------------------- + +/* Exported defines ----------------------------------------------------------*/ + +// RGB is 16-bit coded as G2G1G0B4 B3B2B1B0 R4R3R2R1 R0G5G4G3 +#define RGB_MAKE(xR,xG,xB) ( ( (xG&0x07)<<13 ) + ( (xG)>>5 ) + \ + ( ((xB)>>3) << 8 ) + \ + ( ((xR)>>3) << 3 ) ) /*!< Macro to make a LCD compatible color format from RGB. */ + +#define RGB_RED 0x00F8 /*!< Predefined color. */ +#define RGB_BLACK 0x0000 /*!< Predefined color. */ +#define RGB_WHITE 0xffff /*!< Predefined color. */ +#define RGB_BLUE 0x1F00 /*!< Predefined color. */ +#define RGB_GREEN 0xE007 /*!< Predefined color. */ +#define RGB_YELLOW (RGB_GREEN|RGB_RED) /*!< Predefined color. */ +#define RGB_MAGENTA (RGB_BLUE|RGB_RED) /*!< Predefined color. */ +#define RGB_LIGHTBLUE (RGB_BLUE|RGB_GREEN) /*!< Predefined color. */ +#define RGB_ORANGE (RGB_RED | 0xE001) /*!< Predefined color ( Green/2 + red ). */ +#define RGB_PINK (RGB_MAGENTA | 0xE001) /*!< Predefined color ( Green/2 + magenta ). */ + +// PWM rates. +#define BACKLIGHTMIN 0x1000 /*!< Minimal PWM rate. */ +#define DEFAULT_CCR_BACKLIGHTSTART 0x8000 /*!< Default PWM rate. */ + +// SCREEN Infos +#define SCREEN_WIDTH 128 /*!< Width of visible screen in pixels. */ +#define SCREEN_HEIGHT 128 /*!< Height of visible screen in pixels. */ +#define CHIP_SCREEN_WIDTH 132 /*!< Width of screen driven by LCD controller in pixels. */ +#define CHIP_SCREEN_HEIGHT 132 /*!< Height of screen driven by LCD controller in pixels. */ + +// Characters Infos +#define CHAR_WIDTH 7 /*!< Width of a character. */ +#define CHAR_HEIGHT 14 /*!< Height of a character. */ + +/// @cond Internal + +// LCD functions definition +#define LCD_SETRECTFORCMD_ID (LCD_ID + 0) // Define the rectangle (for the next command to be applied) +#define LCD_GETPIXEL_ID (LCD_ID + 1) // Read the value of one pixel +#define LCD_DRAWPIXEL_ID (LCD_ID + 2) // Draw a Graphic image on slave LCD. +#define LCD_SENDLCDCMD_ID (LCD_ID + 3) // Send one byte command to LCD LCD. +#define LCD_SENDLCDDATA_ID (LCD_ID + 4) // Display one byte data to LCD LCD. +#define LCD_READLCDDATA_ID (LCD_ID + 5) // Read LCD byte data displayed on LCD LCD. +#define LCD_FILLRECT_ID (LCD_ID + 6) // Fill a rectangle with one color +#define LCD_DRAWRECT_ID (LCD_ID + 7) // Draw a rectangle with one color +#define LCD_DISPLAYCHAR_ID (LCD_ID + 8) // Display one character +#define LCD_RECTREAD_ID (LCD_ID + 9) // Save a rectangle of the monitor RAM +#define LCD_SETBACKLIGHT_ID (LCD_ID + 10) // Modify the PWM rate +#define LCD_GETBACKLIGHT_ID (LCD_ID + 11) // Return the PWM rate +#define LCD_SETROTATESCREEN_ID (LCD_ID + 12) // Enable/Disable screen rotation +#define LCD_GETROTATESCREEN_ID (LCD_ID + 13) // Return screen rotation mode +#define LCD_SETSCREENORIENTATION_ID (LCD_ID + 14) // Set screen orientation +#define LCD_GETSCREENORIENTATION_ID (LCD_ID + 15) // Return screen orientation +#define LCD_SETBACKLIGHT_OFF_ID (LCD_ID + 16) // Switch the LCD back light off. +#define LCD_SETBACKLIGHT_ON_ID (LCD_ID + 17) // Switch the LCD back light on. + +// Prototypes +#define LCD_SetRect_For_Cmd(a,b,c,d) ((tCircleFunc4)(Circle_API [LCD_SETRECTFORCMD_ID])) ((u32)(a),(u32)(b),(u32)(c),(u32)(d)) //void LCD_SetRect_For_Cmd ( s16 x, s16 y, s16 width, s16 height) +#define LCD_GetPixel(a,b) (u16) (((tCircleFunc2)(Circle_API [LCD_GETPIXEL_ID])) ((u32)(a),(u32)(b))) //u16 LCD_GetPixel (u8 x, u8 y) +#define LCD_DrawPixel(a,b,c) ((tCircleFunc3)(Circle_API [LCD_DRAWPIXEL_ID])) ((u32)(a),(u32)(b),(u32)(c)) //void LCD_SetPixel (u8 x, u8 y, u16 Pixel) ; +#define LCD_SendLCDCmd(a) ((tCircleFunc1)(Circle_API [LCD_SENDLCDCMD_ID])) ((u32)(a)) //void LCD_SendLCDCmd(u8 Cmd); +#define LCD_SendLCDData(a) ((tCircleFunc1)(Circle_API [LCD_SENDLCDDATA_ID])) ((u32)(a)) //void LCD_SendLCDData(u8 Data); +#define LCD_ReadLCDData() (u32) (((tCircleFunc0)(Circle_API [LCD_READLCDDATA_ID])) ()) //u32 LCD_ReadLCDData(void); +#define LCD_FillRect(a,b,c,d,e) ((tCircleFunc5)(Circle_API [LCD_FILLRECT_ID])) ((u32)(a),(u32)(b),(u32)(c),(u32)(d),(u32)(e)) //void LCD_FillRect ( u16 x, u16 y, u16 width, u16 height, u16 color ); +#define LCD_DrawRect(a,b,c,d,e) ((tCircleFunc5)(Circle_API [LCD_DRAWRECT_ID])) ((u32)(a),(u32)(b),(u32)(c),(u32)(d),(u32)(e)) //void LCD_DrawRect ( u16 x, u16 y, u16 width, u16 height, u16 color ); +#define LCD_DisplayChar(a,b,c,d,e,f) ((tCircleFunc6)(Circle_API [LCD_DISPLAYCHAR_ID])) ((u32)(a),(u32)(b),(u32)(c),(u32)(d),(u32)(e),(u32)(f)) //void LCD_DisplayChar(u8 x, u8 y, u8 Ascii, u16 TextColor, u16 BGndColor, u16 CharMagniCoeff); +#define LCD_RectRead(a,b,c,d,e) ((tCircleFunc5)(Circle_API [LCD_RECTREAD_ID])) ((u32)(a),(u32)(b),(u32)(c),(u32)(d),(u32)(e)) //void LCD_RectRead ( u16 x, u16 y, u16 width, u16 height, u8* bmp ); +#define LCD_SetBackLight(a) ((tCircleFunc1)(Circle_API [LCD_SETBACKLIGHT_ID])) ((u32)(a)) //void LCD_SetBackLight(u32 newBaclightStart); +#define LCD_GetBackLight() (u32) (((tCircleFunc0)(Circle_API [LCD_GETBACKLIGHT_ID])) ()) //u32 LCD_GetBackLight(void); +#define LCD_SetRotateScreen(a) ((tCircleFunc1)(Circle_API [LCD_SETROTATESCREEN_ID])) ((u32)(a)) //void LCD_SetRotateScreen ( u8 RotateScreen) +#define LCD_GetRotateScreen() (u32) (((tCircleFunc0)(Circle_API [LCD_GETROTATESCREEN_ID])) ()) //u8 LCD_GetRotateScreen (void) +#define LCD_SetScreenOrientation(a) ((tCircleFunc1)(Circle_API [LCD_SETSCREENORIENTATION_ID])) ((u32)(a)) //void LCD_SetScreenOrientation (Rotate_H12_V_Match_TypeDef ScreenOrientation) +#define LCD_GetScreenOrientation() (u32) (((tCircleFunc0)(Circle_API [LCD_GETSCREENORIENTATION_ID])) ()) //Rotate_H12_V_Match_TypeDef LCD_GetScreenOrientation (void) +#define LCD_SetBackLightOff() ((tCircleFunc0)(Circle_API [LCD_SETBACKLIGHT_OFF_ID])) () +#define LCD_SetBackLightOn() ((tCircleFunc0)(Circle_API [LCD_SETBACKLIGHT_ON_ID])) () + +/// @endcond + +//---------------------------------- DRAW ---------------------------------- + +/// @cond Internal + +/* Exported defines ----------------------------------------------------------*/ + +// DRAW functions definition +#define DRAW_SETDEFAULTCOLOR_ID (DRAW_ID + 0) // Reset colors (bgnd + text) +#define DRAW_CLEAR_ID (DRAW_ID + 1) // Clear the LCD display +#define DRAW_SETIMAGE_ID (DRAW_ID + 2) // Draw a colored image +#define DRAW_SETIMAGEBW_ID (DRAW_ID + 3) // Draw a black and white image +#define DRAW_SETLOGOBW_ID (DRAW_ID + 4) // Draw logo +#define DRAW_DISPLAYVBAT_ID (DRAW_ID + 5) // Display the voltage of battery in ascii +#define DRAW_DISPLAYTIME_ID (DRAW_ID + 6) // Display time in ascii +#define DRAW_DISPLAYSTRING_ID (DRAW_ID + 7) // Display a 17char max string of characters +#define DRAW_DISPLAYSTRINGINVERTED_ID (DRAW_ID + 8) // Display a 17char max string of characters with inverted colors +#define DRAW_GETCHARMAGNICOEFF_ID (DRAW_ID + 9) // Return the magnifying value for the characters +#define DRAW_SETCHARMAGNICOEFF_ID (DRAW_ID + 10) // Set the magnifying value for the characters +#define DRAW_GETTEXTCOLOR_ID (DRAW_ID + 11) // Return the current text color +#define DRAW_SETTEXTCOLOR_ID (DRAW_ID + 12) // Set the current text color +#define DRAW_GETBGNDCOLOR_ID (DRAW_ID + 13) // Return the current background color +#define DRAW_SETBGNDCOLOR_ID (DRAW_ID + 14) // Set the current background color +#define DRAW_LINE_ID (DRAW_ID + 15) // Draw a Line between (using Bresenham algorithm) + +//Prototypes +#define DRAW_SetDefaultColor() ((tCircleFunc0)(Circle_API [DRAW_SETDEFAULTCOLOR_ID])) () //void DRAW_SetDefaultColor (void); +#define DRAW_Clear() ((tCircleFunc0)(Circle_API [DRAW_CLEAR_ID])) () //void DRAW_Clear(void); +#define DRAW_SetImage(a,b,c,d,e) ((tCircleFunc5)(Circle_API [DRAW_SETIMAGE_ID])) ((u32)(a),(u32)(b),(u32)(c),(u32)(d),(u32)(e)) //void DRAW_SetImage(const u16 *imageptr, u8 x, u8 y, u8 width, u8 height); +#define DRAW_SetImageBW(a,b,c,d,e) ((tCircleFunc5)(Circle_API [DRAW_SETIMAGEBW_ID])) ((u32)(a),(u32)(b),(u32)(c),(u32)(d),(u32)(e)) //void DRAW_SetImageBW(const u8 *imageptr, u8 x, u8 y, u8 width, u8 height); +#define DRAW_SetLogoBW() ((tCircleFunc0)(Circle_API [DRAW_SETLOGOBW_ID])) () //void DRAW_SetLogoBW(void); +#define DRAW_DisplayVbat(a,b) ((tCircleFunc2)(Circle_API [DRAW_DISPLAYVBAT_ID])) ((u32)(a),(u32)(b)) //void DRAW_DisplayVbat(u8 x, u8 y); +#define DRAW_DisplayTime(a,b) ((tCircleFunc2)(Circle_API [DRAW_DISPLAYTIME_ID])) ((u32)(a),(u32)(b)) //void DRAW_DisplayTime(u8 x, u8 y); +#define DRAW_DisplayString(a,b,c,d) ((tCircleFunc4)(Circle_API [DRAW_DISPLAYSTRING_ID])) ((u32)(a),(u32)(b),(u32)(c),(u32)(d)) //void DRAW_DisplayString( u8 x, u8 y, u8 *ptr, u8 len ); +#define DRAW_DisplayStringInverted(a,b,c,d) ((tCircleFunc4)(Circle_API [DRAW_DISPLAYSTRINGINVERTED_ID])) ((u32)(a),(u32)(b),(u32)(c),(u32)(d)) //void DRAW_DisplayStringInverted( u8 x, u8 y, u8 *ptr, u8 len ); +#define DRAW_GetCharMagniCoeff() (u16) (((tCircleFunc0)(Circle_API [DRAW_GETCHARMAGNICOEFF_ID])) ()) //u16 DRAW_GetCharMagniCoeff(void); +#define DRAW_SetCharMagniCoeff(a) ((tCircleFunc1)(Circle_API [DRAW_SETCHARMAGNICOEFF_ID])) ((u32)(a)) //void DRAW_SetCharMagniCoeff(u16 Coeff); +#define DRAW_GetTextColor() (u16) (((tCircleFunc0)(Circle_API [DRAW_GETTEXTCOLOR_ID])) ()) //u16 DRAW_GetTextColor(void); +#define DRAW_SetTextColor(a) ((tCircleFunc1)(Circle_API [DRAW_SETTEXTCOLOR_ID])) ((u32)(a)) //void DRAW_SetTextColor(u16 Color); +#define DRAW_GetBGndColor() (u16) (((tCircleFunc0)(Circle_API [DRAW_GETBGNDCOLOR_ID])) ()) //u16 DRAW_GetBGndColor(void); +#define DRAW_SetBGndColor(a) ((tCircleFunc1)(Circle_API [DRAW_SETBGNDCOLOR_ID])) ((u32)(a)) //void DRAW_SetBGndColor(u16 Color); +#define DRAW_Line(a,b,c,d,e) ((tCircleFunc5)(Circle_API [DRAW_LINE_ID])) ((u32)(a),(u32)(b),(u32)(c),(u32)(d),(u32)(e)) //void DRAW_Line(s16 x1, s16 y1, s16 x2, s16 y2, u16 color ); +/// @endcond + +//-------------------------------- BUZZER ----------------------------------- + +/* Exported type def ---------------------------------------------------------*/ + +/** +* @enum BUZZER_mode +* @brief CircleOS buzzer modes. +* +* Without the undefined mode, the CircleOS provides 5 modes for its buzzer. +**/ +enum BUZZER_mode + { + BUZZER_UNDEF = -1, /*!< undefined mode for buzzer */ + BUZZER_OFF = 0, /*!< The buzzer is put off. */ + BUZZER_ON = 1, /*!< The buzzer is put on. */ + BUZZER_SHORTBEEP = 2, /*!< Make buzzer to bip for a short time */ + BUZZER_LONGBEEP = 3, /*!< Make buzzer to bip for a long time */ + BUZZER_PLAYMUSIC = 4 /*!< Make buzzer to play a music */ + }; + +/// @cond Internal + +/* Exported defines ----------------------------------------------------------*/ +#define BUZZER_BEEP BUZZER_SHORTBEEP + +// BUZZER functions definition +#define BUZZER_SETMODE_ID (BUZZER_ID + 0) // Set new buzzer mode +#define BUZZER_GETMODE_ID (BUZZER_ID + 1) // Get the current buzzer mode. +#define BUZZER_PLAY_MUSIC_ID (BUZZER_ID + 2) // Plays the provided melody that follows the RTTTL Format. + +// Prototypes +#define BUZZER_SetMode(a) ((tCircleFunc1)(Circle_API [BUZZER_SETMODE_ID])) ((u32)(a)) //void BUZZER_SetMode( enum BUZZER_mode mode); +#define BUZZER_GetMode() (enum BUZZER_mode) (((tCircleFunc0)(Circle_API [BUZZER_GETMODE_ID])) ()) //enum BUZZER_mode BUZZER_GetMode( void ); +#define BUZZER_PlayMusic(a) ((tCircleFunc1)(Circle_API [BUZZER_PLAY_MUSIC_ID])) ((u32)(a)) //void BUZZER_PlayMusic (const u8 *melody ); + +/// @endcond + +//--------------------------------- MENU ----------------------------------- + +/* Exported defines ----------------------------------------------------------*/ +#define REMOVE_MENU 0x01 /*!< Menu flag: remove menu when item selected. */ +#define APP_MENU 0x02 /*!< Menu flag: item is an application. */ +#define MENU_MAXITEM 8 /*!< Maximum number of item in a menu. */ + +/* Exported type def ---------------------------------------------------------*/ + +/** +* @struct tMenuItem +* @brief Menu item description. +**/ +typedef struct + { + const char* Text; /*!< Name of Item displayed in menu */ + enum MENU_code (*Fct_Init) ( void ); /*!< First function launched if item is selected. */ + enum MENU_code (*Fct_Manage)( void ); /*!< Second function launched after a "return MENU_CONTINU_COMMAND" in the first function */ + int fRemoveMenu; /*!< Flag to know if remove menu at end */ + } tMenuItem; + +/** +* @struct tMenu +* @brief Menu description. +**/ +typedef struct + { + unsigned fdispTitle: 1; /*!< Display title is set. */ + const char* Title; /*!< Menu title. */ + int NbItems; /*!< Number of items in the menu ( must be <= MENU_MAXITEM ) */ + int LgMax; /*!< Unused. */ + int XPos; /*!< X position of menu bottom-left corner. */ + int YPos; /*!< Y position of menu bottom-left corner. */ + int XSize; /*!< Unused. */ + int YSize; /*!< Unused. */ + unsigned int SelectedItem; /*!< ID of selected item (0 for first item, 1 for second item, ...) */ + tMenuItem Items[MENU_MAXITEM]; /*!< Items of menu. */ + } tMenu; + +/** +* @enum MENU_code +* @brief Application return values. +* +* List of all the codes available for CircleOS application return values. +**/ +enum MENU_code + { + MENU_LEAVE = 0, /*!< Leave application. */ + MENU_CONTINUE = 1, /*!< Continue application. */ + MENU_REFRESH = 2, /*!< Refresh current menu. */ + MENU_CHANGE = 3, /*!< Change current menu. */ + MENU_CONTINUE_COMMAND = 4 /*!< Sent by Ini functions.*/ + }; + +/// @cond Internal + +/* Exported defines ----------------------------------------------------------*/ + +// MENU functions definition +#define MENU_SET_ID (MENU_ID + 0) // Display a menu +#define MENU_REMOVE_ID (MENU_ID + 1) // Remove the current menu, DRAW_Clear and set pointer mode to "POINTER_ON". +#define MENU_QUESTION_ID (MENU_ID + 2) // Dedicated menu for ask question and yes/no responses +#define MENU_PRINT_ID (MENU_ID + 3) // Display a popup menu with a string. +#define MENU_CLEAR_CURRENT_COMMAND_ID (MENU_ID + 4) // Set CurrentCommand to 0 +#define MENU_SET_LEVELTITLE_ID (MENU_ID + 5) // Set the title of level menu managed by MENU_SetLevel_Mgr. +#define MENU_SET_TEXTCOLOR_ID (MENU_ID + 6) // Set the color used for text menu. +#define MENU_GET_TEXTCOLOR_ID (MENU_ID + 7) // Return the color used for text menu. +#define MENU_SET_BGNDCOLOR_ID (MENU_ID + 8) // Set the background color used for menu. +#define MENU_GET_BGNDCOLOR_ID (MENU_ID + 9) // Return the background color used for menu. +#define MENU_QUIT_ID (MENU_ID + 10) // Leave the current menu (stand for "cancel" and do a DRAW_Clear) +#define MENU_SET_LEVELINI_ID (MENU_ID + 11) // Initialise a generic function to set a avalue in the range of [0,4] +#define MENU_CLEAR_CURRENT_MENU_ID (MENU_ID + 12) // Set CurrentMenu to 0 +#define MENU_SET_LEVEL_MGR_ID (MENU_ID + 13) // Generic function to set a avalue in the range of [0,4] (handling of the control) + +// Prototypes +#define MENU_Set(a) ((tCircleFunc1)(Circle_API [MENU_SET_ID])) ((u32)(a)) //void MENU_Set ( tMenu *mptr ); +#define MENU_Remove() ((tCircleFunc0)(Circle_API [MENU_REMOVE_ID])) () //void MENU_Remove ( void ) ; +#define MENU_Question(a,b) ((tCircleFunc2)(Circle_API [MENU_QUESTION_ID])) ((u32)(a),(u32)(b)) //void MENU_Question ( char *str, int *answer ); +#define MENU_Print(a) ((tCircleFunc1)(Circle_API [MENU_PRINT_ID])) ((u32)(a)) //void MENU_Print ( char *str ); +#define MENU_ClearCurrentCommand() ((tCircleFunc0)(Circle_API [MENU_CLEAR_CURRENT_COMMAND_ID])) () //void MENU_ClearCurrentCommand(void) +#define MENU_SetLevelTitle(a) ((tCircleFunc1)(Circle_API [MENU_SET_LEVELTITLE_ID])) ((u32)(a)) //void MENU_SetLevelTitle(u8* title) +#define MENU_SetTextColor(a) ((tCircleFunc1)(Circle_API [MENU_SET_TEXTCOLOR_ID])) ((u32)(a)) //void MENU_SetTextColor ( int TextColor ) +#define MENU_GetTextColor() (u32) (((tCircleFunc0)(Circle_API [MENU_GET_TEXTCOLOR_ID])) ()) //int MENU_GetTextColor ( void ) +#define MENU_SetBGndColor(a) ((tCircleFunc1)(Circle_API [MENU_SET_BGNDCOLOR_ID])) ((u32)(a)) //void MENU_SetBGndColor ( int BGndColor ) +#define MENU_GetBGndColor() (u32) (((tCircleFunc0)(Circle_API [MENU_GET_BGNDCOLOR_ID])) ()) //int MENU_GetBGndColor ( void ) +#define MENU_Quit() (enum MENU_code) (((tCircleFunc0)(Circle_API [MENU_QUIT_ID])) ()) //enum MENU_code MENU_Quit ( void ) +#define MENU_SetLevel_Ini() (enum MENU_code) (((tCircleFunc0)(Circle_API [MENU_SET_LEVELINI_ID])) ()) //enum MENU_code MENU_SetLevel_Ini ( void ) +#define MENU_ClearCurrentMenu() ((tCircleFunc0)(Circle_API [MENU_CLEAR_CURRENT_MENU_ID])) () //void MENU_ClearCurrentMenu(void) +#define MENU_SetLevel_Mgr(a,b) (enum MENU_code) ((tCircleFunc2)(Circle_API [MENU_SET_LEVEL_MGR_ID])) ((u32)(a),(u32)(b)) //enum MENU_code MENU_SetLevel_Mgr ( u32 *value, u32 value_range [] ) + +/// @endcond + +//---------------------------------- LED ------------------------------------- + +/* Exported types ------------------------------------------------------------*/ + +/** +* @enum LED_mode +* @brief LED modes. +* +* LEDs may be on, off or blinking slowly or fastly! +**/ +enum LED_mode + { + LED_UNDEF = -1, /*!< Undefined led mode. */ + LED_OFF = 0, /*!< Put off the led. */ + LED_ON = 1, /*!< Put on the led. */ + LED_BLINKING_LF = 2, /*!< Slow blinking led mode. */ + LED_BLINKING_HF = 3 /*!< Fast blinking led mode. */ + }; + +/** +* @enum LED_id +* @brief Available LEDs. +* +* List of all the available LEDs. +**/ +enum LED_id + { + LED_GREEN = 0, /*!< Green led id. */ + LED_RED = 1 /*!< Red led id. */ + }; + +/// @cond Internal + +/* Exported defines ----------------------------------------------------------*/ + +// LED functions definition +#define LED_SET_ID (LED_ID + 0) // Set a specified LED in a specified mode. + +// Prototypes +#define LED_Set(a,b) ((tCircleFunc2)(Circle_API [LED_SET_ID])) ((u32)(a),(u32)(b)) //void LED_Set ( enum LED_id id, enum LED_mode mode ) //void LED_Set ( enum LED_id id, enum LED_mode mode ); + +/// @endcond + +//-------------------------------- RTC -------------------------------------- + +/* Exported defines ----------------------------------------------------------*/ + +// Backup registers +#define BKP_SYS1 1 /*!< Backup register reserved for OS */ +#define BKP_SYS2 2 /*!< Backup register reserved for OS */ +#define BKP_SYS3 3 /*!< Backup register reserved for OS */ +#define BKP_SYS4 4 /*!< Backup register reserved for OS */ +#define BKP_SYS5 5 /*!< Backup register reserved for OS */ +#define BKP_SYS6 6 /*!< Backup register reserved for OS */ + +#define BKP_USER1 7 /*!< Backup available for users application */ +#define BKP_USER2 8 /*!< Backup available for users application */ +#define BKP_USER3 9 /*!< Backup available for users application */ +#define BKP_USER4 10 /*!< Backup available for users application */ + +/// @cond Internal + +//RTC functions definition +#define RTC_SET_TIME_ID (RTC_ID + 0) // Set current time. +#define RTC_GET_TIME_ID (RTC_ID + 1) // Return current time. +#define RTC_DISPLAY_TIME_ID (RTC_ID + 2) // Display current time on the 6th line at column 0. + +// Prototypes +#define RTC_SetTime(a,b,c) ((tCircleFunc3)(Circle_API [RTC_SET_TIME_ID])) ((u32)(a),(u32)(b),(u32)(c)) //void RTC_SetTime (u32 THH, u32 TMM, u32 TSS); +#define RTC_GetTime(a,b,c) ((tCircleFunc3)(Circle_API [RTC_GET_TIME_ID])) ((u32)(a),(u32)(b),(u32)(c)) //void RTC_GetTime (u32 * THH, u32 * TMM, u32 * TSS); +#define RTC_DisplayTime() ((tCircleFunc0)(Circle_API [RTC_DISPLAY_TIME_ID])) () //void RTC_DisplayTime ( void ); + +/// @endcond + +//--------------------------------- Application ------------------------------- +typedef void (*tAppPtrMgr) ( int , int ); + +#endif /*__CIRCLE_API_H */ diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/crt0_STM32x.c b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/crt0_STM32x.c new file mode 100644 index 000000000..6dfbb2de1 --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/crt0_STM32x.c @@ -0,0 +1,217 @@ +/******************** (C) COPYRIGHT 2007 STMicroelectronics ******************** +* File Name : stm32f10x_vector.c +* Author : MCD Tools Team +* Date First Issued : 05/14/2007 +* Description : This file contains the vector table for STM32F10x. +* After Reset the Cortex-M3 processor is in Thread mode, +* priority is Privileged, and the Stack is set to Main. +******************************************************************************** +* History: +* 05/14/2007: V0.2 +* +******************************************************************************** +* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS +* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. +* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, +* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE +* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING +* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. +*******************************************************************************/ + +/* Includes ----------------------------------------------------------------------*/ + +void NMIException(void); +void HardFaultException(void); +void MemManageException(void); +void BusFaultException(void); +void UsageFaultException(void); +void DebugMonitor(void); +void SVCHandler(void); +void PendSVC(void); +void SysTickHandler(void); +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 DMAChannel1_IRQHandler(void); +void DMAChannel2_IRQHandler(void); +void DMAChannel3_IRQHandler(void); +void DMAChannel4_IRQHandler(void); +void DMAChannel5_IRQHandler(void); +void DMAChannel6_IRQHandler(void); +void DMAChannel7_IRQHandler(void); +void ADC_IRQHandler(void); +void USB_HP_CAN_TX_IRQHandler(void); +void USB_LP_CAN_RX0_IRQHandler(void); +void CAN_RX1_IRQHandler(void); +void CAN_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 TIM2_IRQHandler(void); +void TIM3_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); + + +/* Exported types --------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +extern unsigned long _etext; +extern unsigned long _sidata; /* start address for the initialization values of the .data section. defined in linker script */ +extern unsigned long _sdata; /* start address for the .data section. defined in linker script */ +extern unsigned long _edata; /* end address for the .data section. defined in linker script */ + +extern unsigned long _sbss; /* start address for the .bss section. defined in linker script */ +extern unsigned long _ebss; /* end address for the .bss section. defined in linker script */ + +extern void _estack; /* init value for the stack pointer. defined in linker script */ + + + +/* Private typedef -----------------------------------------------------------*/ +/* function prototypes ------------------------------------------------------*/ +void Reset_Handler(void) __attribute__((__interrupt__)); +extern int main(void); +extern void xPortPendSVHandler(void); +extern void xPortSysTickHandler(void); +extern void vTimer2IntHandler( void ); + + +/****************************************************************************** +* +* The minimal vector table for a Cortex M3. Note that the proper constructs +* must be placed on this to ensure that it ends up at physical address +* 0x0000.0000. +* +******************************************************************************/ + + +__attribute__ ((section(".isr_vector"))) +void (* const g_pfnVectors[])(void) = +{ + &_estack, // The initial stack pointer + Reset_Handler, // The reset handler + NMIException, + HardFaultException, + MemManageException, + BusFaultException, + UsageFaultException, + 0, 0, 0, 0, /* Reserved */ + SVCHandler, + DebugMonitor, + 0, /* Reserved */ + xPortPendSVHandler, + xPortSysTickHandler, + WWDG_IRQHandler, + PVD_IRQHandler, + TAMPER_IRQHandler, + RTC_IRQHandler, + FLASH_IRQHandler, + RCC_IRQHandler, + EXTI0_IRQHandler, + EXTI1_IRQHandler, + EXTI2_IRQHandler, + EXTI3_IRQHandler, + EXTI4_IRQHandler, + DMAChannel1_IRQHandler, + DMAChannel2_IRQHandler, + DMAChannel3_IRQHandler, + DMAChannel4_IRQHandler, + DMAChannel5_IRQHandler, + DMAChannel6_IRQHandler, + DMAChannel7_IRQHandler, + ADC_IRQHandler, + USB_HP_CAN_TX_IRQHandler, + USB_LP_CAN_RX0_IRQHandler, + CAN_RX1_IRQHandler, + CAN_SCE_IRQHandler, + EXTI9_5_IRQHandler, + TIM1_BRK_IRQHandler, + TIM1_UP_IRQHandler, + TIM1_TRG_COM_IRQHandler, + TIM1_CC_IRQHandler, + vTimer2IntHandler, + TIM3_IRQHandler, + TIM4_IRQHandler, + I2C1_EV_IRQHandler, + I2C1_ER_IRQHandler, + I2C2_EV_IRQHandler, + I2C2_ER_IRQHandler, + SPI1_IRQHandler, + SPI2_IRQHandler, + USART1_IRQHandler, + USART2_IRQHandler, + USART3_IRQHandler, + EXTI15_10_IRQHandler, + RTCAlarm_IRQHandler, + USBWakeUp_IRQHandler, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + (unsigned long)0xF108F85F //this is a workaround for boot in RAM mode. +}; + +/******************************************************************************* +* Function Name : Reset_Handler +* Description : This is the code that gets called when the processor first starts execution +* following a reset event. Only the absolutely necessary set is performed, +* after which the application supplied main() routine is called. +* Input : +* Output : +* Return : +*******************************************************************************/ +void Reset_Handler(void) +{ + unsigned long *pulSrc, *pulDest; + + // + // Copy the data segment initializers from flash to SRAM. + // + pulSrc = &_sidata; + for(pulDest = &_sdata; pulDest < &_edata; ) + { + *(pulDest++) = *(pulSrc++); + } + + // + // Zero fill the bss segment. + // + for(pulDest = &_sbss; pulDest < &_ebss; ) + { + *(pulDest++) = 0; + } + + // + // Call the application's entry point. + // + main(); +} + + +/********************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/ + + diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/draw.c b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/draw.c new file mode 100644 index 000000000..17b5f51aa --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/draw.c @@ -0,0 +1,545 @@ +/********************* (C) COPYRIGHT 2007 RAISONANCE S.A.S. *******************/ +/** +* +* @file draw.c +* @brief Various utilities for drawings (characters, ..) +* @author FL +* @author IB +* @date 07/2007 +* +**/ +/******************************************************************************/ + +/* Includes ------------------------------------------------------------------*/ +#include "circle.h" + +/// @cond Internal + +/* Private define ------------------------------------------------------------*/ +#define V9_MADCTRVAL 0x90 +#define V12_MADCTRVAL 0x30 +#define V3_MADCTRVAL 0x50 +#define V6_MADCTRVAL 0xF0 + +#define ROTATE_DIVISER 500 + +/* Private variables ---------------------------------------------------------*/ + +static u16 CharMagniCoeff = 1; /*!< Current character magnify coefficient. */ +static u16 BGndColor; /*!< Current background color. */ +static u16 TextColor; /*!< Current text color. */ + +int fDisplayTime = 0; +u16 BatState; +u16 OldBatState; +u32 OldTHH; +u32 OldTMM; +u32 OldTSS; +u32 OldTemp; //FL071107 +u16 xBat; +u16 yBat; +u16 widthBat; +u16 heightBat; +u8 UsbState,OldUsbState; +static int divider_coord = 0; + +// Screen orientation management +int rotate_counter = 0; +Rotate_H12_V_Match_TypeDef previous_H12 = V9; +Rotate_H12_V_Match_TypeDef previous_previous_H12 = V9; +Rotate_H12_V_Match_TypeDef H12; +Rotate_H12_V_Match_TypeDef CurrentScreenOrientation; +int CurrentRotateScreen = 1; + +extern s16 XInit; +extern s16 YInit; + +/* Private functions ---------------------------------------------------------*/ + +/******************************************************************************* +* +* vbattoa +* +*******************************************************************************/ +/** +* +* This function convert an u16 in ascii radix 10 +* +* @param[out] ptr A pointer to a string where the converted value will be put. +* @param[in] X The value to convert. +* +* @see DRAW_DisplayVbat +* +**/ +/******************************************************************************/ +static void vbattoa( char* ptr, u16 X ) + { + u8 c; + u16 r = 0; + + // 1 000 digit + c = ((X-r)/1000); + r = r + (c*1000); + *ptr++ = c + 0x30; + + // dot + *ptr++ = '.'; + + // 100 digit + c = ((X-r)/100); + r = r + (c*100); + *ptr++ = c + 0x30; + + // 10 digit + c = ((X-r)/10); + r = r + (c*10); + *ptr++ = c + 0x30; + + // Volt + *ptr++ = 'V'; + *ptr++ = 0; + } + +/******************************************************************************* +* +* DRAW_DisplayStringWithMode +* +*******************************************************************************/ +/** +* +* This function is used to display a 17char max string of +* characters on the LCD display on the selected line. +* Note: +* this function is the user interface to use the LCD driver. +* +* @param[in] x The horizontal screen coordinate where to draw the string. +* @param[in] y The vertical screen coordinate where to draw the string. +* @param[in] ptr Pointer to string to display. +* @param[in] len String size. +* @param[in] mode Display mode: 0 normal, 1 inverted colors. +* +* @warning The (0x0) point in on the low left corner. +* +* @see DRAW_DisplayString +* @see DRAW_DisplayStringInverted +* +**/ +/******************************************************************************/ +static void DRAW_DisplayStringWithMode( u8 x, u8 y, const u8* ptr, u8 len, int mode ) + { + u8 ref_x = x, i = 0; + + /* Send the string character by character on LCD */ + while ((*ptr!=0)&&(i<18)) + { + /* Display one character on LCD */ + LCD_DisplayChar( ref_x, y, *ptr, mode ? BGndColor : TextColor, mode ? TextColor : BGndColor, CharMagniCoeff ); + + /* Increment the column position by 7 */ + ref_x+= (7*CharMagniCoeff); + + /* Point on the next character */ + ptr++; + + /* Increment the character counter */ + i++; + /* If we reach the maximum Line character */ + } + + while ( i < len ) + { + /* Display one character on LCD */ + LCD_DisplayChar( ref_x, y, ' ', mode ? BGndColor : TextColor, mode ? TextColor : BGndColor, CharMagniCoeff ); + + /* Increment the column position by 7 */ + ref_x += ( 7 * CharMagniCoeff ); + + /* Increment the character counter */ + i++; + } + } + +/* Public functions for CircleOS ---------------------------------------------*/ + +/******************************************************************************* +* +* DRAW_Init +* +*******************************************************************************/ +/** +* +* Initialize GUI drawing. Called at CircleOS startup. +* +* @attention This function must NOT be called by the user. +* +**/ +/******************************************************************************/ +void DRAW_Init( void ) + { + LCD_Init(); +#ifdef _MEMS + MEMS_GetRotation( &CurrentScreenOrientation ); +#endif + LCD_SetScreenOrientation( CurrentScreenOrientation ); + + xBat = 98; + yBat = 3; + OldBatState = 10; + OldTSS = 100; + OldTMM = 100; + OldTHH = 100; + OldTemp = -1; + + // Clear LCD and draw black and white logo + DRAW_SetDefaultColor(); + LCD_FillRect( 0, 0, CHIP_SCREEN_WIDTH, CHIP_SCREEN_HEIGHT, BGndColor ); +// POINTER_Init(); + } + + + + +/* Public functions ----------------------------------------------------------*/ + +/******************************************************************************* +* +* DRAW_SetCharMagniCoeff +* +*******************************************************************************/ +/** +* +* Set the magnifying value for the characters (should be 1 or 2) +* +* @param[in] Coeff The new magnifying coefficent. +* +**/ +/******************************************************************************/ +void DRAW_SetCharMagniCoeff( u16 Coeff ) + { + CharMagniCoeff = Coeff; + } + + /****************************************************************************** +* +* DRAW_GetCharMagniCoeff +* +*******************************************************************************/ +/** +* +* Return the current magnifying value for the characters +* +* @return Current magnifying value. +* +**/ +/******************************************************************************/ +u16 DRAW_GetCharMagniCoeff( void ) + { + return CharMagniCoeff; + } + + /****************************************************************************** +* +* DRAW_GetTextColor +* +*******************************************************************************/ +/** +* +* Return current text color. +* +* @return The current RGB color used to draw text. +* +**/ +/******************************************************************************/ +u16 DRAW_GetTextColor( void ) + { + return TextColor; + } + +/******************************************************************************* +* +* DRAW_SetTextColor +* +*******************************************************************************/ +/** +* +* Set current text color. +* +* @param[in] Color The new RGB color used when drawing text. +* +**/ +/******************************************************************************/ +void DRAW_SetTextColor( u16 Color ) + { + TextColor = Color ; + } + +/******************************************************************************* +* +* DRAW_GetBGndColor +* +*******************************************************************************/ +/** +* +* Return current background color. +* +* @return The current RGB color used for the background. +* +**/ +/******************************************************************************/ +u16 DRAW_GetBGndColor( void ) + { + return BGndColor; + } + +/******************************************************************************* +* +* DRAW_SetBGndColor +* +*******************************************************************************/ +/** +* +* Set current background color +* +* @param[in] Color The new RGB color for background. +* +**/ +/******************************************************************************/ +void DRAW_SetBGndColor(u16 Color) + { + BGndColor = Color; + } + + +/******************************************************************************* +* +* DRAW_SetImage +* +*******************************************************************************/ +/** +* +* The provided bitmap is made width * height 2 byte words. Each 2 byte word contains +* the RGB color of a pixel. +* +* @brief Draw a color bitmap at the provided coordinates. +* @param[in] imageptr A pointer to an array of width * height 2 byte words. +* @param[in] x The horizontal coordinate of the low left corner of the bitmap. +* @param[in] y The vertical coordinate of the low left corner of the bitmap. +* @param[in] width The bitmap width. +* @param[in] height The bitmap height. +* +* @warning The (0x0) point in on the low left corner. +* +**/ +/******************************************************************************/ +void DRAW_SetImage( const u16* imageptr, u8 x, u8 y, u8 width, u8 height ) + { + int i; + + // Select screen area to access. + LCD_SetRect_For_Cmd( x, y, width, height ); + + // Send command to write data on the LCD screen. + LCD_SendLCDCmd(ST7637_RAMWR); + + for( i = 0; i < ( width * height ); i++ ) + { + LCD_SendLCDData( imageptr[ i ] & 0xff ); + LCD_SendLCDData( ( imageptr[ i ] >> 8 ) & 0xff ); + } + } + + + +/******************************************************************************* +* +* DRAW_DisplayString +* +*******************************************************************************/ +/** +* +* This function is used to display a 17 character max string of +* characters on the LCD display at the provided coordinates. +* +* @param[in] x The horizontal coordinate of the displayed string. +* @param[in] y The vertical coordinate of the display string. +* @param[in] *ptr Pointer to the string to display on LCD. +* @param[in] len String length. +* +* @warning The (0x0) point in on the low left corner. +* +**/ +/******************************************************************************/ +void DRAW_DisplayString( u8 x, u8 y, const u8* ptr, u8 len ) + { + DRAW_DisplayStringWithMode( x, y, ptr, len, 0 ); + } + +/******************************************************************************* +* +* DRAW_DisplayStringInverted +* +*******************************************************************************/ +/** +* +* This function is used to display a 17 character max string of +* characters on the LCD display at the provided coordinates with inverted colors. +* +* @param[in] x The horizontal coordinate of the displayed string. +* @param[in] y The vertical coordinate of the display string. +* @param[in] *ptr Pointer to the string to display on LCD. +* @param[in] len String length. +* +* @warning The (0x0) point in on the low left corner. +* +**/ +/******************************************************************************/ +void DRAW_DisplayStringInverted( u8 x, u8 y, const u8* ptr, u8 len ) + { + //BackGround and Text Colors are inverted + DRAW_DisplayStringWithMode( x, y, ptr, len, 1 ); + } + +/******************************************************************************* +* +* DRAW_SetDefaultColor +* +*******************************************************************************/ +/** +* +* Reset text and background colors to their default values. +* +**/ +/******************************************************************************/ +void DRAW_SetDefaultColor (void) + { + BGndColor = RGB_WHITE; + TextColor = RGB_BLACK; + } + +/******************************************************************************* +* +* DRAW_DisplayTemp +* +*******************************************************************************/ +/** +* +* This function is used to display the current temperature in ascii. +* The choice between Celcius and Fahrenheit is fixed by UTIL_SetModeTemp() +* +* @param[in] x The horizontal coordinate of the displayed string. +* @param[in] y The vertical coordinate of the display string. +* +* @warning The (0x0) point in on the low left corner. +* +**/ +/******************************************************************************/ +void DRAW_DisplayTemp( u8 x, u8 y ) + { + u32 Temp = 0; + u8 TextBuffer[5] = { 0,0,0,0,0}; + + // Get Time + Temp = UTIL_GetTemp() ; + + if( Temp != OldTemp ) + { + // Display C (if modified). + UTIL_uint2str( TextBuffer, Temp/10, 2, 1 ); + TextBuffer[ 2 ] = '.'; + DRAW_DisplayString( x + ( 0 * CharMagniCoeff * 7 ), y, TextBuffer, 3 ); + + // Display C/10 (if modified). + UTIL_uint2str( TextBuffer, Temp%10, 1, 1 ); + TextBuffer[ 1 ] = fTemperatureInFahrenheit ? 'F' : 'C'; TextBuffer[ 2 ] = 0; + DRAW_DisplayString( x + ( 3 * CharMagniCoeff * 7 ), y, TextBuffer, 2 ); + } + OldTemp = Temp; + } + +/******************************************************************************* +* +* DRAW_Line +* +*******************************************************************************/ +/** +* Draw a line on the LCD screen. Optimized for horizontal/vertical lines, +* and use the Bresenham algorithm for other cases. +* +* @param[in] x1 The x-coordinate of the first line endpoint. +* @param[in] x2 The x-coordinate of the second line endpoint. +* @param[in] y1 The y-coordinate of the first line endpoint. +* @param[in] y2 The y-coordinate of the second line endpoint. +* @param[in] color The line color. +* +**/ +void DRAW_Line (s16 x1, s16 y1, s16 x2, s16 y2, u16 color ) + { + int i,dx,dy,sdx,sdy,dxabs,dyabs,x,y,px,py; + + #define abs(X) ( ( (X) < 0 ) ? -(X) : (X) ) + #define sgn(X) ( ( (X) < 0 ) ? -1 : 1 ) + + if ( x1==x2 ) //Vertical Line + { + if ( y1 > y2 ) //We assume y2>y1 and invert if not + { + i = y2; + y2 = y1; + y1 = i; + } + LCD_FillRect( x1, y1, 1, y2-y1+1, color ); + return; + } + else if ( y1==y2 ) //Horizontal Line + { + if ( x1 > x2 ) //We assume x2>x1 and we swap them if not + { + i = x2; + x2 = x1; + x1 = i; + } + LCD_FillRect( x1, y1, x2-x1+1, 1, color ); + return; + } + + dx=x2-x1; /* the horizontal distance of the line */ + dy=y2-y1; /* the vertical distance of the line */ + dxabs=abs(dx); + dyabs=abs(dy); + sdx=sgn(dx); + sdy=sgn(dy); + x=dyabs>>1; + y=dxabs>>1; + px=x1; + py=y1; + + if (dxabs>=dyabs) /* the line is more horizontal than vertical */ + { + for(i=0;i=dxabs) + { + y-=dxabs; + py+=sdy; + } + px+=sdx; + LCD_DrawPixel(px,py,color); + } + } + else /* the line is more vertical than horizontal */ + { + for(i=0;i=dyabs) + { + x-=dyabs; + px+=sdx; + } + py+=sdy; + LCD_DrawPixel(px,py,color); + } + } + } + diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/lcd.c b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/lcd.c new file mode 100644 index 000000000..0f39b47cf --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/lcd.c @@ -0,0 +1,1189 @@ +/********************* (C) COPYRIGHT 2007 RAISONANCE S.A.S. *******************/ +/** +* +* @file lcd.c +* @brief The LCD driver for the ST7637. +* @author FL +* @date 07/2007 +* +**/ +/******************************************************************************/ + +/* Includes ------------------------------------------------------------------*/ +#include "lcd.h" +#include "circle.h" + +/// @cond Internal + +/* Private define ------------------------------------------------------------*/ +#define V9_MADCTRVAL 0x90 /*!< Left orientation value. */ +#define V12_MADCTRVAL 0x30 /*!< Up orientation value. */ +#define V3_MADCTRVAL 0x50 /*!< Right orientation value. */ +#define V6_MADCTRVAL 0xF0 /*!< Bottom orientation value. */ +#define BACKLIGHT_DIVIDER 500 /*!< LCD handler step. */ + +/* Private variables ---------------------------------------------------------*/ + +// vars for timer dedicated for lcd backlight +static TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; +static TIM_OCInitTypeDef TIM_OCInitStructure; +static int HandlerDivider = 0; + +int Current_CCR_BackLightStart = DEFAULT_CCR_BACKLIGHTSTART; + +/* External variable ---------------------------------------------------------*/ +extern GPIO_InitTypeDef GPIO_InitStructure; +extern u16 CCR_BackLight_Tab[5]; +extern int CurrentRotateScreen; +extern Rotate_H12_V_Match_TypeDef CurrentScreenOrientation; + +/*! ASCII Table. Each character is 7 column (7dots large) on two pages (16dots high) + 7 column character: Two 8 bit data to display one column*/ +static const u8 AsciiDotsTable[95 * 14 ] = { + /* ASCII 32 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + /* ASCII 33 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x13,0xe0,0x00,0x00,0x00,0x00,0x00,0x00, + /* ASCII 34 */ 0x00,0x00,0x00,0xe0,0x00,0x20,0x00,0x00,0x00,0xe0,0x00,0x20,0x00,0x00, + /* ASCII 35 */ 0x00,0x00,0x35,0x00,0x0f,0x80,0x35,0x60,0x0f,0x80,0x05,0x60,0x00,0x00, + /* ASCII 36 */ 0x00,0x00,0x0d,0x80,0x0a,0x40,0x3a,0x60,0x06,0x40,0x00,0x00,0x00,0x00, + /* ASCII 37 */ 0x00,0x00,0x02,0x40,0x02,0xa0,0x0a,0x40,0x15,0x00,0x09,0x00,0x00,0x00, + /* ASCII 38 */ 0x00,0x00,0x0c,0x00,0x13,0x00,0x14,0x80,0x08,0x80,0x14,0x00,0x00,0x00, + /* ASCII 39 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00, + /* ASCII 40 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x80,0x60,0x60,0x00,0x00,0x00,0x00, + /* ASCII 41 */ 0x00,0x00,0x00,0x00,0x60,0x60,0x1f,0x80,0x00,0x00,0x00,0x00,0x00,0x00, + /* ASCII 42 */ 0x00,0x00,0x00,0x40,0x03,0x40,0x00,0xe0,0x03,0x40,0x00,0x40,0x00,0x00, + /* ASCII 43 */ 0x02,0x00,0x02,0x00,0x02,0x00,0x1f,0xc0,0x02,0x00,0x02,0x00,0x02,0x00, + /* ASCII 44 */ 0x00,0x00,0x00,0x00,0x60,0x00,0x38,0x00,0x08,0x00,0x00,0x00,0x00,0x00, + /* ASCII 45 */ 0x00,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x00,0x00, + /* ASCII 46 */ 0x00,0x00,0x00,0x00,0x18,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + /* ASCII 47 */ 0x00,0x00,0x20,0x00,0x18,0x00,0x06,0x00,0x01,0x80,0x00,0x60,0x00,0x00, + /* ASCII 48 */ 0x00,0x00,0x0f,0xc0,0x10,0x20,0x10,0x20,0x10,0x20,0x0f,0xc0,0x00,0x00, + /* ASCII 49 */ 0x00,0x00,0x10,0x00,0x10,0x20,0x1f,0xe0,0x10,0x00,0x10,0x00,0x00,0x00, + /* ASCII 50 */ 0x00,0x00,0x18,0x40,0x14,0x20,0x12,0x20,0x11,0x20,0x18,0xc0,0x00,0x00, + /* ASCII 51 */ 0x00,0x00,0x08,0x40,0x10,0x20,0x11,0x20,0x11,0x20,0x0e,0xc0,0x00,0x00, + /* ASCII 52 */ 0x00,0x00,0x06,0x00,0x05,0x00,0x04,0xc0,0x14,0x20,0x1f,0xe0,0x14,0x00, + /* ASCII 53 */ 0x00,0x00,0x08,0x00,0x11,0xe0,0x11,0x20,0x11,0x20,0x0e,0x20,0x00,0x00, + /* ASCII 54 */ 0x00,0x00,0x0f,0x80,0x11,0x40,0x11,0x20,0x11,0x20,0x0e,0x20,0x00,0x00, + /* ASCII 55 */ 0x00,0x00,0x00,0x60,0x00,0x20,0x18,0x20,0x07,0x20,0x00,0xe0,0x00,0x00, + /* ASCII 56 */ 0x00,0x00,0x0e,0xc0,0x11,0x20,0x11,0x20,0x11,0x20,0x0e,0xc0,0x00,0x00, + /* ASCII 57 */ 0x00,0x00,0x11,0xc0,0x12,0x20,0x12,0x20,0x0a,0x20,0x07,0xc0,0x00,0x00, + /* ASCII 58 */ 0x00,0x00,0x00,0x00,0x19,0x80,0x19,0x80,0x00,0x00,0x00,0x00,0x00,0x00, + /* ASCII 59 */ 0x00,0x00,0x00,0x00,0x30,0x00,0x19,0x80,0x09,0x80,0x00,0x00,0x00,0x00, + /* ASCII 60 */ 0x02,0x00,0x05,0x00,0x05,0x00,0x08,0x80,0x10,0x40,0x10,0x40,0x00,0x00, + /* ASCII 61 */ 0x00,0x00,0x05,0x00,0x05,0x00,0x05,0x00,0x05,0x00,0x05,0x00,0x00,0x00, + /* ASCII 62 */ 0x10,0x40,0x10,0x40,0x08,0x80,0x05,0x00,0x05,0x00,0x02,0x00,0x00,0x00, + /* ASCII 63 */ 0x00,0x00,0x00,0x00,0x10,0x80,0x14,0x40,0x02,0x40,0x01,0x80,0x00,0x00, + /* ASCII 64 */ 0x00,0x00,0x1f,0xe0,0x20,0x10,0x23,0x10,0x24,0x90,0x17,0xe0,0x00,0x00, + /* ASCII 65 */ 0x10,0x00,0x1c,0x00,0x17,0xa0,0x04,0x60,0x17,0x80,0x1c,0x00,0x10,0x00, + /* ASCII 66 */ 0x10,0x20,0x1f,0xe0,0x11,0x20,0x11,0x20,0x11,0x20,0x0e,0xc0,0x00,0x00, + /* ASCII 67 */ 0x00,0x00,0x0f,0xc0,0x10,0x20,0x10,0x20,0x10,0x20,0x08,0x60,0x00,0x00, + /* ASCII 68 */ 0x10,0x20,0x1f,0xe0,0x10,0x20,0x10,0x20,0x08,0x40,0x07,0x80,0x00,0x00, + /* ASCII 69 */ 0x10,0x20,0x1f,0xe0,0x11,0x20,0x13,0xa0,0x10,0x20,0x18,0x60,0x00,0x00, + /* ASCII 70 */ 0x00,0x00,0x10,0x20,0x1f,0xe0,0x11,0x20,0x03,0xa0,0x00,0x20,0x00,0x60, + /* ASCII 71 */ 0x00,0x00,0x0f,0xc0,0x10,0x20,0x10,0x20,0x12,0x20,0x0e,0x60,0x02,0x00, + /* ASCII 72 */ 0x10,0x20,0x1f,0xe0,0x11,0x20,0x01,0x00,0x11,0x20,0x1f,0xe0,0x10,0x20, + /* ASCII 73 */ 0x00,0x00,0x10,0x20,0x10,0x20,0x1f,0xe0,0x10,0x20,0x10,0x20,0x00,0x00, + /* ASCII 74 */ 0x00,0x00,0x0e,0x00,0x10,0x20,0x10,0x20,0x0f,0xe0,0x00,0x20,0x00,0x00, + /* ASCII 75 */ 0x10,0x20,0x1f,0xe0,0x12,0x20,0x03,0x00,0x04,0xa0,0x18,0x60,0x10,0x20, + /* ASCII 76 */ 0x00,0x00,0x10,0x20,0x1f,0xe0,0x10,0x20,0x10,0x00,0x1c,0x00,0x00,0x00, + /* ASCII 77 */ 0x10,0x20,0x1f,0xe0,0x10,0xe0,0x03,0x00,0x10,0xe0,0x1f,0xe0,0x10,0x20, + /* ASCII 78 */ 0x10,0x20,0x1f,0xe0,0x10,0xe0,0x07,0x00,0x18,0x20,0x1f,0xe0,0x00,0x20, + /* ASCII 79 */ 0x00,0x00,0x0f,0xc0,0x10,0x20,0x10,0x20,0x10,0x20,0x0f,0xc0,0x00,0x00, + /* ASCII 80 */ 0x00,0x00,0x10,0x20,0x1f,0xe0,0x12,0x20,0x02,0x20,0x01,0xc0,0x00,0x00, + /* ASCII 81 */ 0x00,0x00,0x0f,0xc0,0x10,0x20,0x30,0x20,0x30,0x20,0x2f,0xc0,0x00,0x00, + /* ASCII 82 */ 0x10,0x20,0x1f,0xe0,0x12,0x20,0x02,0x20,0x06,0x20,0x09,0xc0,0x10,0x00, + /* ASCII 83 */ 0x00,0x00,0x18,0xc0,0x09,0x20,0x11,0x20,0x11,0x40,0x0e,0x60,0x00,0x00, + /* ASCII 84 */ 0x00,0x60,0x00,0x20,0x10,0x20,0x1f,0xe0,0x10,0x20,0x00,0x20,0x00,0x60, + /* ASCII 85 */ 0x00,0x20,0x0f,0xe0,0x10,0x20,0x10,0x00,0x10,0x20,0x0f,0xe0,0x00,0x20, + /* ASCII 86 */ 0x00,0x20,0x00,0xe0,0x07,0x20,0x18,0x00,0x07,0x20,0x00,0xe0,0x00,0x20, + /* ASCII 87 */ 0x00,0x20,0x0f,0xe0,0x10,0x20,0x0f,0x00,0x10,0x20,0x0f,0xe0,0x00,0x20, + /* ASCII 88 */ 0x10,0x20,0x18,0x60,0x04,0x80,0x03,0x00,0x04,0x80,0x18,0x60,0x10,0x20, + /* ASCII 89 */ 0x00,0x20,0x00,0x60,0x11,0xa0,0x1e,0x00,0x11,0xa0,0x00,0x60,0x00,0x20, + /* ASCII 90 */ 0x00,0x00,0x18,0x60,0x14,0x20,0x13,0x20,0x10,0xa0,0x18,0x60,0x00,0x00, + /* ASCII 91 */ 0x00,0x00,0x00,0x00,0x7f,0xe0,0x40,0x20,0x40,0x20,0x00,0x00,0x00,0x00, + /* ASCII 92 */ 0x00,0x00,0x00,0x20,0x01,0xc0,0x06,0x00,0x38,0x00,0x00,0x00,0x00,0x00, + /* ASCII 93 */ 0x00,0x00,0x00,0x00,0x40,0x20,0x40,0x20,0x7f,0xe0,0x00,0x00,0x00,0x00, + /* ASCII 94 */ 0x00,0x00,0x01,0x00,0x00,0x80,0x00,0x60,0x00,0x80,0x01,0x00,0x00,0x00, + /* ASCII 95 */ 0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00, + /* ASCII 96 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x40,0x00,0x00,0x00,0x00, + /* ASCII 97 */ 0x00,0x00,0x0d,0x00,0x12,0x80,0x12,0x80,0x12,0x80,0x1f,0x00,0x10,0x00, + /* ASCII 98 */ 0x10,0x20,0x1f,0xe0,0x11,0x00,0x10,0x80,0x10,0x80,0x0f,0x00,0x00,0x00, + /* ASCII 99 */ 0x00,0x00,0x0f,0x00,0x10,0x80,0x10,0x80,0x10,0x80,0x09,0x80,0x00,0x00, + /* ASCII 100 */ 0x00,0x00,0x0f,0x00,0x10,0x80,0x10,0x80,0x11,0x20,0x1f,0xe0,0x10,0x00, + /* ASCII 101 */ 0x00,0x00,0x0f,0x00,0x12,0x80,0x12,0x80,0x12,0x80,0x13,0x00,0x00,0x00, + /* ASCII 102 */ 0x00,0x00,0x10,0x80,0x1f,0xc0,0x10,0xa0,0x10,0xa0,0x10,0xa0,0x00,0x00, + /* ASCII 103 */ 0x00,0x00,0x0f,0x00,0x50,0x80,0x50,0x80,0x51,0x00,0x3f,0x80,0x00,0x80, + /* ASCII 104 */ 0x10,0x20,0x1f,0xe0,0x11,0x00,0x00,0x80,0x10,0x80,0x1f,0x00,0x10,0x00, + /* ASCII 105 */ 0x00,0x00,0x10,0x80,0x10,0x80,0x1f,0xa0,0x10,0x00,0x10,0x00,0x00,0x00, + /* ASCII 106 */ 0x00,0x00,0x40,0x80,0x40,0x80,0x40,0xa0,0x3f,0x80,0x00,0x00,0x00,0x00, + /* ASCII 107 */ 0x10,0x20,0x1f,0xe0,0x02,0x00,0x16,0x80,0x19,0x80,0x10,0x80,0x00,0x00, + /* ASCII 108 */ 0x00,0x00,0x10,0x00,0x10,0x20,0x1f,0xe0,0x10,0x00,0x10,0x00,0x00,0x00, + /* ASCII 109 */ 0x10,0x80,0x1f,0x80,0x10,0x80,0x1f,0x00,0x10,0x80,0x1f,0x00,0x10,0x00, + /* ASCII 110 */ 0x10,0x80,0x1f,0x80,0x11,0x00,0x00,0x80,0x10,0x80,0x1f,0x00,0x10,0x00, + /* ASCII 111 */ 0x00,0x00,0x0f,0x00,0x10,0x80,0x10,0x80,0x10,0x80,0x0f,0x00,0x00,0x00, + /* ASCII 112 */ 0x40,0x80,0x7f,0x80,0x51,0x00,0x10,0x80,0x10,0x80,0x0f,0x00,0x00,0x00, + /* ASCII 113 */ 0x00,0x00,0x0f,0x00,0x10,0x80,0x10,0x80,0x51,0x00,0x7f,0x80,0x40,0x80, + /* ASCII 114 */ 0x00,0x00,0x10,0x80,0x1f,0x80,0x11,0x00,0x10,0x80,0x10,0x80,0x00,0x00, + /* ASCII 115 */ 0x00,0x00,0x19,0x00,0x12,0x80,0x12,0x80,0x12,0x80,0x0d,0x80,0x00,0x00, + /* ASCII 116 */ 0x00,0x00,0x00,0x80,0x0f,0xc0,0x10,0x80,0x10,0x80,0x10,0x80,0x08,0x00, + /* ASCII 117 */ 0x00,0x80,0x0f,0x80,0x10,0x00,0x10,0x00,0x08,0x80,0x1f,0x80,0x10,0x00, + /* ASCII 118 */ 0x00,0x80,0x03,0x80,0x0c,0x80,0x10,0x00,0x0c,0x80,0x03,0x80,0x00,0x80, + /* ASCII 119 */ 0x00,0x80,0x0f,0x80,0x10,0x80,0x0e,0x00,0x10,0x80,0x0f,0x80,0x00,0x80, + /* ASCII 120 */ 0x10,0x80,0x19,0x80,0x06,0x00,0x06,0x00,0x19,0x80,0x10,0x80,0x00,0x00, + /* ASCII 121 */ 0x00,0x80,0x41,0x80,0x46,0x80,0x78,0x00,0x4c,0x80,0x03,0x80,0x00,0x80, + /* ASCII 122 */ 0x00,0x00,0x19,0x80,0x14,0x80,0x12,0x80,0x11,0x80,0x18,0x80,0x00,0x00, + /* ASCII 123 */ 0x00,0x00,0x00,0x00,0x04,0x00,0x3b,0xc0,0x40,0x20,0x00,0x00,0x00,0x00, + /* ASCII 124 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xe0,0x00,0x00,0x00,0x00,0x00,0x00, + /* ASCII 125 */ 0x00,0x00,0x00,0x00,0x40,0x20,0x3b,0xc0,0x04,0x00,0x00,0x00,0x00,0x00, + /* ASCII 126 */ 0x00,0x00,0x04,0x00,0x02,0x00,0x04,0x00,0x04,0x00,0x02,0x00,0x00,0x00}; + +int OrientationOffsetX [] = { 0 /* V12*/,0 /* V3*/,+4 /* V6*/,+4 /* V9*/ }; +int OrientationOffsetY [] = { +4 /* V12*/,0 /* V3*/,0 /* V6*/,+4 /* V9*/ }; + +/* Private function prototypes -----------------------------------------------*/ +static void LCD_7637_Controller( void ); +static void LCD_DrawChar( u8 x, u8 y, u8 width, const u8 *bmp, u16 textColor, u16 bGndColor, u16 charMagniCoeff ); +static void LCD_BackLightChange( void ); +static void LCD_BackLightConfig( void ); +static void LCD_CtrlLinesWrite( GPIO_TypeDef* GPIOx, u32 CtrlPins, BitAction BitVal ); + +/* Private functions ---------------------------------------------------------*/ + +/******************************************************************************* +* +* LCD_DataLinesConfig +* +*******************************************************************************/ +/** +* Configure data lines D0~D7 in Input Floating mode for read from LCD or in +* Output Push-Pull mode for write on LCD +* +* @param[in] Mode Specifies the configuration mode for data lines D0~D7. +* @n @c Input: configure in Input Floating mode +* @n @c Output: configure in Output Push-Pul mode +* +**/ +/******************************************************************************/ +static void LCD_DataLinesConfig( DataConfigMode_TypeDef Mode ) + { + GPIO_InitTypeDef GPIO_InitStructure; + + GPIO_InitStructure.GPIO_Pin = LCD_DATA_PINS; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + + if( Mode == Input ) + { + /* Configure D0~D7 lines as Input */ + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; + } + else + { + /* Configure D0~D7 lines in Output Push-Pull mode */ + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + } + + GPIO_Init( GPIOx_D_LCD, &GPIO_InitStructure ); + } + +/******************************************************************************* +* +* LCD_DataLinesWrite +* +*******************************************************************************/ +/** +* Write a value on D0~D7 +* +* @param[in] GPIOx GPIO port to write on. +* @param[in] PortVal The value to write. Only the lowest 8 bits are taken into +* account. +* +**/ +/******************************************************************************/ +static void LCD_DataLinesWrite( GPIO_TypeDef* GPIOx, u32 PortVal ) + { + // Write only the lowest 8 bits! + GPIOx->ODR = ( (GPIOx->ODR) & 0xFF00 ) | (u8)PortVal; + } + +/******************************************************************************* +* +* LCD_CtrlLinesConfig +* +*******************************************************************************/ +/** +* Configure control lines in Output Push-Pull mode. +* +**/ +/******************************************************************************/ +static void LCD_CtrlLinesConfig( void ) + { + GPIO_InitTypeDef GPIO_InitStructure; + + GPIO_InitStructure.GPIO_Pin = LCD_CTRL_PINS; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + + GPIO_Init( GPIOx_CTRL_LCD, &GPIO_InitStructure ); + + GPIO_InitStructure.GPIO_Pin = CtrlPin_CS; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + + GPIO_Init( GPIOx_CS_LCD, &GPIO_InitStructure ); + + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RS, Bit_SET ); /* RS = 1 */ + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */ + LCD_CtrlLinesWrite( GPIOx_CS_LCD, CtrlPin_CS, Bit_SET ); /* CS = 1 */ + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_SET ); /* WR = 1 */ + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_RESET ); /* RST = 0 */ + } + +/******************************************************************************* +* +* LCD_CtrlLinesWrite +* +*******************************************************************************/ +/** +* Set or reset control lines. +* +* @param[in] GPIOx Where x can be 0, 1 or 2 to select the GPIO peripheral. +* @param[in] CtrlPins The Control line. +* @param[in] BitVal +* +**/ +/******************************************************************************/ +static void LCD_CtrlLinesWrite( GPIO_TypeDef* GPIOx, u32 CtrlPins, BitAction BitVal ) + { + /* Set or Reset the control line */ + GPIO_WriteBit( GPIOx, CtrlPins, BitVal ); + } + +/******************************************************************************* +* +* LCD_CheckLCDStatus +* +*******************************************************************************/ +/** +* Check whether LCD LCD is busy or not. +* +**/ +/******************************************************************************/ +static void LCD_CheckLCDStatus( void ) + { + unsigned char ID1; + unsigned char ID2; + unsigned char ID3; + + LCD_SendLCDCmd( ST7637_RDDID ); + + /* Configure Data lines as Input */ + LCD_DataLinesConfig (Input ); + + /* Start the LCD send data sequence */ + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RS, Bit_RESET ); /* RS = 0 */ + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_RESET ); /* RD = 0 */ + LCD_CtrlLinesWrite( GPIOx_CS_LCD, CtrlPin_CS, Bit_RESET ); /* CS = 0 */ + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_SET ); /* WR = 1 */ + + /* Read data to the LCD */ + GPIO_ReadInputData( GPIOx_D_LCD ); + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */ + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_RESET ); /* RD = 0 */ + + ID1 = GPIO_ReadInputData( GPIOx_D_LCD ); + + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */ + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_RESET ); /* RD = 0 */ + + ID2 = GPIO_ReadInputData( GPIOx_D_LCD ); + + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */ + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_RESET ); /* RD = 0 */ + + ID3 = GPIO_ReadInputData( GPIOx_D_LCD ); + + LCD_DataLinesConfig( Output ); + } + +/******************************************************************************* +* +* LCD_DrawChar +* +*******************************************************************************/ +/** +* Draw a character on the LCD screen. +* +* @param[in] x The line where to display the character shape. +* @param[in] y The column start address. +* @param[in] width The number of columns (dots) in a character width. +* @param[in] bmp The character (monochrome) bitmap. A pointer of the dot matrix data. +* @param[in] textColor The character color. +* @param[in] bGndColor The character background color. +* @param[in] charMagniCoeff The character magnifying coefficient. +* +* @warning The (0x0) point in on the low left corner. +* +**/ +/******************************************************************************/ +static void LCD_DrawChar( u8 x, u8 y, u8 width, const u8* bmp, u16 textColor, u16 bGndColor, u16 charMagniCoeff ) + { + int i; + int j; + int k1; + int k2; + + // Select the area for LCD output. + LCD_SetRect_For_Cmd( x, y, 7 * charMagniCoeff, 14 * charMagniCoeff ); + + // Select LCD output mode. + LCD_SendLCDCmd( ST7637_RAMWR ); + + for( i = 0; i < 7; i++ ) + { + for( k1 = 0; k1 < charMagniCoeff; k1++ ) + { + for( j = 0x80; j; j >>= 1 ) // 8 + { + for( k2 = 0; k2 < charMagniCoeff; k2++ ) + { + LCD_SendLCDData( ( bmp[2*i] & j ) ? ( textColor & 255 ) : ( bGndColor & 255 ) ); + LCD_SendLCDData( ( bmp[2*i] & j ) ? ( textColor >> 8 ) : ( bGndColor >> 8 ) ); + } + } + + for( j = 0x80; j > 2; j >>= 1 ) // 8 + { + for( k2 = 0; k2 < charMagniCoeff; k2++ ) + { + LCD_SendLCDData( ( bmp[2*i+1] & j ) ? ( textColor & 255 ) : ( bGndColor & 255 ) ); + LCD_SendLCDData( ( bmp[2*i+1] & j ) ? ( textColor >> 8 ) : ( bGndColor >> 8 ) ); + } + } + } + } + } + +/******************************************************************************* +* +* LCD_DisplayRotate +* +*******************************************************************************/ +/** +* Configure the LCD controller for a given orientation. +* +* @param[in] H12 The new screen orientation. +* +**/ +/******************************************************************************/ +static void LCD_DisplayRotate( Rotate_H12_V_Match_TypeDef H12 ) + { + // Memory Access Control 0x36 + LCD_SendLCDCmd( ST7637_MADCTR ); + + switch( H12 ) + { + case V3 : + LCD_SendLCDData( V3_MADCTRVAL ); + break; + + case V6 : + LCD_SendLCDData( V6_MADCTRVAL ); + break; + + case V9 : + LCD_SendLCDData( V9_MADCTRVAL ); + break; + + case V12 : + default : + LCD_SendLCDData( V12_MADCTRVAL ); + break; + } + } + +/******************************************************************************* +* +* LCD_7637_Controller +* +*******************************************************************************/ +/** +* Initialization of the controller registers. +* +* @note See ST7637.PDF for more information. +* +**/ +/******************************************************************************/ +static void LCD_7637_Controller( void ) + { + extern void starting_delay ( long unsigned ); + + /** Apply hardware reset **/ + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_SET ); /* RST = 1 */ + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_RESET ); /* RST = 0 */ + starting_delay( 0x500 ); + + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_SET ); /* RST = 1 */ + starting_delay( 0x500 ); + + //default mode is output + LCD_DataLinesConfig( Output ); + + LCD_CheckLCDStatus(); + + LCD_SendLCDCmd( ST7637_SWRESET ); + + //-----------disable autoread + Manual read once ---------------------------- + LCD_SendLCDCmd( ST7637_AUTOLOADSET ); // Auto Load Set 0xD7 + LCD_SendLCDData( 0xBF ); // Auto Load Disable + + LCD_SendLCDCmd( ST7637_EPCTIN ); // EE Read/write mode 0xE0 + LCD_SendLCDData( 0x00 ); // Set read mode + + LCD_SendLCDCmd( ST7637_EPMRD ); // Read active 0xE3 + LCD_SendLCDCmd( ST7637_EPCTOUT ); // Cancel control 0xE1 + + //---------------------------------- Sleep OUT ------------------------------ + LCD_SendLCDCmd( ST7637_DISPOFF ); // display off 0x28 + LCD_SendLCDCmd( ST7637_SLPOUT ); // Sleep Out 0x11 + + //--------------------------------Vop setting-------------------------------- + LCD_SendLCDCmd( ST7637_VOPSET ); // Set Vop by initial Module 0xC0 + LCD_SendLCDData( 0xFB ); // Vop = 13.64 + LCD_SendLCDData( 0x00 ); // base on Module + + //----------------------------Set Register----------------------------------- + LCD_SendLCDCmd( ST7637_BIASSEL ); // Bias select 0xC3 + LCD_SendLCDData( 0x00 ); // 1/12 Bias, base on Module + + LCD_SendLCDCmd( ST7637_BSTBMPXSEL ); // Setting Booster times 0xC4 + LCD_SendLCDData( 0x05 ); // Booster X 8 + + LCD_SendLCDCmd( ST7637_BSTEFFSEL ); // Booster eff 0xC5 + LCD_SendLCDData( 0x11 ); // BE = 0x01 (Level 2) + + LCD_SendLCDCmd( ST7637_VGSORCSEL ); // Vg with booster x2 control 0xcb + LCD_SendLCDData( 0x01 ); // Vg from Vdd2 + + LCD_SendLCDCmd( ST7637_ID1SET ); // ID1 = 00 0xcc + LCD_SendLCDData( 0x00 ); // + + LCD_SendLCDCmd( ST7637_ID3SET ); // ID3 = 00 0xce + LCD_SendLCDData( 0x00 ); // + + LCD_SendLCDCmd( 0xB7 ); // Glass direction + LCD_SendLCDData( 0xC0 ); // + + LCD_SendLCDCmd( ST7637_ANASET ); // Analog circuit setting 0xd0 + LCD_SendLCDData( 0x1D ); // + + LCD_SendLCDCmd( 0xB4 ); // PTL mode set + LCD_SendLCDData( 0x18 ); // power normal mode + LCD_SendLCDCmd( ST7637_INVOFF ); // Display Inversion OFF 0x20 + + LCD_SendLCDCmd( 0x2A ); // column range + LCD_SendLCDData( 0x04 ); // + LCD_SendLCDData( 0x83 ); // + + LCD_SendLCDCmd( 0x2B ); // raw range + LCD_SendLCDData( 0x04 ); // + LCD_SendLCDData( 0x83 ); // + + + LCD_SendLCDCmd( ST7637_COLMOD ); // Color mode = 65k 0x3A + LCD_SendLCDData( 0x05 ); // + + LCD_SendLCDCmd( ST7637_MADCTR ); // Memory Access Control 0x36 + LCD_SendLCDData( V9_MADCTRVAL ); + + LCD_SendLCDCmd( ST7637_DUTYSET ); // Duty = 132 duty 0xb0 + LCD_SendLCDData( 0x7F ); + + LCD_SendLCDCmd( 0x29 ); // Display ON + LCD_SendLCDCmd( 0xF9 ); // Gamma + LCD_SendLCDData( 0x00 ); // + LCD_SendLCDData( 0x03 ); // + LCD_SendLCDData( 0x05 ); // + LCD_SendLCDData( 0x07 ); // + LCD_SendLCDData( 0x09 ); // + LCD_SendLCDData( 0x0B ); // + LCD_SendLCDData( 0x0D ); // + LCD_SendLCDData( 0x0F ); // + LCD_SendLCDData( 0x11 ); // + LCD_SendLCDData( 0x13 ); // + LCD_SendLCDData( 0x15 ); // + LCD_SendLCDData( 0x17 ); // + LCD_SendLCDData( 0x19 ); // + LCD_SendLCDData( 0x1B ); // + LCD_SendLCDData( 0x1D ); // + LCD_SendLCDData( 0x1F ); // + } + +/******************************************************************************* +* +* LCD_BackLightConfig +* +*******************************************************************************/ +/** +* Setting of the PWM that drives the backlight intensity. +* +**/ +/******************************************************************************/ +static void LCD_BackLightConfig( void ) + { + GPIO_InitTypeDef GPIO_InitStructure; + + /* Enable GPIOB clock */ + RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE ); + + /* GPIOB Configuration:TIM4 2 in Output */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + + GPIO_Init( GPIOB, &GPIO_InitStructure ); + + /* TIM4 Configuration -----------------------------------------------------*/ + /* TIM4CLK = 12 MHz, Prescaler = 0x0 */ + + /* Enable TIM4 clock */ + RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM4, ENABLE ); + + TIM_DeInit( TIM4 ); + TIM_TimeBaseStructInit( &TIM_TimeBaseStructure ); + TIM_OCStructInit( &TIM_OCInitStructure ); + + /* Time base configuration */ + TIM_TimeBaseStructure.TIM_Period = 0xFFFF; + TIM_TimeBaseStructure.TIM_Prescaler = 0x0; + TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + + TIM_TimeBaseInit( TIM4, &TIM_TimeBaseStructure ); + + /* Output Compare Toggle Mode configuration: Channel2 */ + TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; + TIM_OCInitStructure.TIM_Channel = TIM_Channel_2; + TIM_OCInitStructure.TIM_Pulse = Current_CCR_BackLightStart; + + TIM_OCInit( TIM4, &TIM_OCInitStructure ); + TIM_OC4PreloadConfig( TIM4, TIM_OCPreload_Disable ); + + TIM_ARRPreloadConfig( TIM4, ENABLE ); + + /* Enable TIM4 IT */ + TIM_ITConfig( TIM4, TIM_IT_CC2, ENABLE ); + + // Go !!! + TIM_Cmd( TIM4, ENABLE ); + } + +/******************************************************************************* +* +* LCD_BackLightChange +* +*******************************************************************************/ +/** +* Modify the PWM rate. +* +**/ +/******************************************************************************/ +static void LCD_BackLightChange( void ) + { + /* Output Compare Toggle Mode configuration: Channel2 */ + TIM_OCInitStructure.TIM_Pulse = Current_CCR_BackLightStart; + + TIM_OCInit( TIM4, &TIM_OCInitStructure ); + } + +/* Public functions for CircleOS ---------------------------------------------*/ + +/******************************************************************************* +* +* LCD_Init +* +*******************************************************************************/ +/** +* +* Initialize LCD. Called at CircleOS startup. +* +* @attention This function must NOT be called by the user. +* +**/ +/******************************************************************************/ +void LCD_Init( void ) + { + LCD_SetBackLight( UTIL_ReadBackupRegister( BKP_BKLIGHT ) ); + + /* Do some gpio configs*/ + GPIO_InitTypeDef GPIO_InitStructure; + + /* Enable GPIO clock for LCD */ + RCC_APB2PeriphClockCmd( GPIO_LCD_CTRL_PERIPH, ENABLE ); + RCC_APB2PeriphClockCmd( GPIO_LCD_D_PERIPH, ENABLE ); + RCC_APB2PeriphClockCmd( GPIO_LCD_CS_PERIPH, ENABLE ); + + /* Enable GPIOC clock */ + RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE ); + + /* Init BackLight*/ + LCD_BackLightConfig(); + + /* Configure control lines signals as output mode */ + LCD_CtrlLinesConfig(); + + /* LCD LCD Init */ + LCD_7637_Controller(); + } + +/******************************************************************************* +* +* LCD_Handler +* +*******************************************************************************/ +/** +* +* Called by the CircleOS scheduler to manage LCD tasks. +* +* @attention This function must NOT be called by the user. +* +**/ +/******************************************************************************/ +void LCD_Handler( void ) + { + if( ++HandlerDivider % BACKLIGHT_DIVIDER ) + { + return; + } + + LCD_BackLightChange(); + } + + +/// @endcond + +/* Public functions ----------------------------------------------------------*/ + +/******************************************************************************* +* +* LCD_SendLCDCmd +* +*******************************************************************************/ +/** +* +* Send on command byte to the LCD. +* +* @param[in] Cmd An unsigned char containing the user command to send to the LCD. +* +**/ +/******************************************************************************/ +void LCD_SendLCDCmd( u8 Cmd ) + { + /* Start the LCD send data sequence */ + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RS, Bit_RESET ); /* RS = 0 */ + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */ + LCD_CtrlLinesWrite( GPIOx_CS_LCD, CtrlPin_CS, Bit_RESET ); /* CS = 0 */ + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_RESET ); /* WR = 0 */ + + /* Write data to the LCD */ + LCD_DataLinesWrite( GPIOx_D_LCD, (u32)Cmd ); + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_SET ); /* WR = 1 */ + } + +/******************************************************************************* +* +* LCD_SendLCDData +* +*******************************************************************************/ +/** +* +* Send one data byte to the LCD. +* +* @param[in] Data An unsigned character containing the data to send to the LCD. +* @pre An LCD_SendLCDCmd was done with a command waiting for data. +* +* +**/ +/******************************************************************************/ +void LCD_SendLCDData( u8 Data ) + { + /* Configure Data lines as Output */ + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RS, Bit_SET ); + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET ); + LCD_CtrlLinesWrite( GPIOx_CS_LCD, CtrlPin_CS, Bit_RESET ); + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_RESET ); + + /* Write data to the LCD */ + LCD_DataLinesWrite( GPIOx_D_LCD,(u32)Data ); + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_SET ); + } + +/*********************************************************************************** +* +* LCD_ReadLCDData +* +************************************************************************************/ +/** +* +* Read one data byte from the LCD. +* +* @return An unsigned 32 bit word containing the data returned by a LCD command. +* @pre An LCD_SendLCDCmd was done with a command returning data. +* +**/ +/********************************************************************************/ +u32 LCD_ReadLCDData( void ) + { + u32 LCDData = 0; + + /* Configure Data lines as Input */ + LCD_DataLinesConfig(Input); + + /* Start the LCD send data sequence */ + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RS, Bit_SET ); /* RS = 1 */ + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_WR, Bit_SET ); /* WR = 1 */ + LCD_CtrlLinesWrite( GPIOx_CS_LCD, CtrlPin_CS, Bit_RESET ); /* CS = 0 */ + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RD, Bit_RESET ); /* RD = 0 */ + + /* Read data from the LCD */ + LCDData = (GPIO_ReadInputData( GPIOx_D_LCD ) & LCD_DATA_PINS ); + + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */ + + /* Read the LCD returned data */ + LCD_DataLinesConfig( Output ); + + return LCDData; + } + +/******************************************************************************* +* +* LCD_FillRect +* +*******************************************************************************/ +/** +* +* Fill a rectangle with a provided color. +* +* @param[in] x The horizontal coordinate of the rectangle low left corner. +* @param[in] y The vertical coordinate of the rectangle low left corner. +* @param[in] width The rectangle width in pixels. +* @param[in] height The rectangle height in pixels. +* @param[in] color The RGB color to fill the rectangle with. +* +* @warning The (0x0) point in on the low left corner. +* +**/ +/******************************************************************************/ +void LCD_FillRect( u16 x, u16 y, u16 width, u16 height, u16 color ) + { + u8 Line; + u8 Column; + + /* Select LCD screen area. */ + LCD_SetRect_For_Cmd( x, y, width, height ); + + /* Send LCD RAM write command. */ + LCD_SendLCDCmd( ST7637_RAMWR ); + + /* Fill selected LCD screen area with provided color. */ + for( Line = 0; Line < width; Line++ ) + { + for( Column = 0; Column < height; Column++ ) + { + LCD_SendLCDData( color & 0xff ); + LCD_SendLCDData( ( color >> 8 ) & 0xff ); + } + } + + #ifdef TESTLCD + /* Configure Data lines as Input */ + LCD_DataLinesConfig( Input ); + + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_SET ); /* RST = 1 */ + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_RESET ); /* RST = 0 */ + LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_SET ); /* RST = 1 */ + + /* Start the LCD send data sequence */ + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RS, Bit_SET ); /* RS = 1 */ + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RS, Bit_RESET ); /* RS = 0 */ + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RS, Bit_SET ); /* RS = 1 */ + + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RS, Bit_SET ); /* RS = 1 */ + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RS, Bit_RESET ); /* RS = 0 */ + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RS, Bit_SET ); /* RS = 1 */ + + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_WR, Bit_SET ); /* WR = 1 */ + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_WR, Bit_RESET ); /* WR = 1 */ + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_WR, Bit_SET ); /* WR = 1 */ + + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */ + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RD, Bit_RESET ); /* RD = 0 */ + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */ + + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */ + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RD, Bit_RESET ); /* RD = 0 */ + LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */ + + /* Configure Data lines as Input */ + LCD_DataLinesConfig( Output ); + + LCD_DataLinesWrite( GPIOx_D_LCD, ~0 ); + LCD_DataLinesWrite( GPIOx_D_LCD, 0 ); + LCD_DataLinesWrite( GPIOx_D_LCD, ~1 ); + LCD_DataLinesWrite( GPIOx_D_LCD, 1 ); + LCD_DataLinesWrite( GPIOx_D_LCD, ~2 ); + LCD_DataLinesWrite( GPIOx_D_LCD, 2 ); + LCD_DataLinesWrite( GPIOx_D_LCD, ~4 ); + LCD_DataLinesWrite( GPIOx_D_LCD, 4 ); + LCD_DataLinesWrite( GPIOx_D_LCD, ~8 ); + LCD_DataLinesWrite( GPIOx_D_LCD, 8 ); + LCD_DataLinesWrite( GPIOx_D_LCD, ~0x10 ); + LCD_DataLinesWrite( GPIOx_D_LCD, 0x10 ); + LCD_DataLinesWrite( GPIOx_D_LCD, ~0x20 ); + LCD_DataLinesWrite( GPIOx_D_LCD, 0x20 ); + LCD_DataLinesWrite( GPIOx_D_LCD, ~0x40 ); + LCD_DataLinesWrite( GPIOx_D_LCD, 0x40 ); + LCD_DataLinesWrite( GPIOx_D_LCD, ~0x80 ); + LCD_DataLinesWrite( GPIOx_D_LCD, 0x80 ); + + LCD_DataLinesConfig( Input ); + + #endif + } + +/******************************************************************************* +* +* LCD_DrawRect +* +*******************************************************************************/ +/** +* +* Draw a rectangle with a provided color. +* +* @param[in] x The horizontal coordinate of the rectangle low left corner. +* @param[in] y The vertical coordinate of the rectangle low left corner. +* @param[in] width The rectangle width in pixels. +* @param[in] height The rectangle height in pixels. +* @param[in] color The RGB color to draw the rectangle with. +* +* @warning The (0x0) point in on the low left corner. +* +**/ +/******************************************************************************/ +void LCD_DrawRect( u16 x, u16 y, u16 width, u16 height, u16 color ) + { + // Draw horizontal sides. + LCD_FillRect( x, y, width, 1, color ); + LCD_FillRect( x, y + height - 1, width, 1, color ); + + // Draw vertical sides. + LCD_FillRect( x, y, 1, height, color ); + LCD_FillRect( x + width - 1, y, 1, height, color ); + } + +/******************************************************************************* +* +* LCD_DrawPixel +* +*******************************************************************************/ +/** +* +* Draw a pixel on the LCD with the provided color. +* +* @param[in] XPos The horizontal coordinate of the pixel. +* @param[in] YPos The vertical coordinate of the pixel. +* @param[in] Color The RGB color to draw the pixel with. +* +* @warning The (0x0) point in on the low left corner. +* +**/ +/******************************************************************************/ +void LCD_DrawPixel( u8 XPos, u8 YPos, u16 Color ) + { + /* Select LCD screen area. */ + LCD_SetRect_For_Cmd( XPos, YPos, 1, 1 ); + + /* Send LCD RAM write command. */ + LCD_SendLCDCmd( ST7637_RAMWR ); + + // Draw pixel. + LCD_SendLCDData( Color ); + LCD_SendLCDData( Color >> 8 ); + } + +/******************************************************************************* +* +* LCD_RectRead +* +*******************************************************************************/ +/** +* +* Save the pixels of a rectangle part of the LCD into a RAM variable. +* +* @param[in] x The horizontal coordinate of the rectangle low left corner. +* @param[in] y The vertical coordinate of the rectangle low left corner. +* @param[in] width The rectangle width in pixels. +* @param[in] height The rectangle height in pixels. +* @param[out] bmp The variable to store the read data into. +* +* @warning One pixel weights 2 bytes. +* @warning The (0x0) point in on the low left corner. +* +**/ +/******************************************************************************/ +void LCD_RectRead( u16 x, u16 y, u16 width, u16 height, u8* bmp ) + { + int i; + int bytesize = (width * height) *2; // 2 bytes per pixel. + + /* Select LCD screen area. */ + LCD_SetRect_For_Cmd( x, y, width, height ); + + /* Send LCD RAM write command. */ + LCD_SendLCDCmd(ST7637_RAMRD); + + // First read byte is dummy! + LCD_ReadLCDData(); + + // Read pixels from LCD screen. + for( i = 0; i < bytesize; i++ ) + { + *bmp++ = LCD_ReadLCDData(); + } + } + +/******************************************************************************* +* +* LCD_GetPixel +* +*******************************************************************************/ +/** +* +* Read the RGB color of the pixel the coordinate are provided in parameter. +* +* @param[in] x The horizontal coordinate of the pixel. +* @param[in] y The vertical coordinate of the pixel. +* @return An unsigned 16 bit word containing the RGB color of the pixel. +* +* @warning The (0x0) point in on the low left corner. +* @see LCD_RectRead +* +**/ +/******************************************************************************/ +u16 LCD_GetPixel( u8 x, u8 y ) + { + u16 val; + + LCD_RectRead( x, y, 1, 1, (u8*)&val ); + + return val; + } + +/******************************************************************************* +* +* LCD_DisplayChar +* +*******************************************************************************/ +/** +* +* Display at provided coordinates the provided ASCII character with the provided +* text and background colors and with the provided magnify coefficient. +* +* @param[in] x The horizontal coordinate of the character. +* @param[in] y The vertical coordinate of the character. +* @param[in] Ascii The ASCII code of the character to display. +* @n Ascii must be higher than 31 and lower than 127. +* @param[in] TextColor The color used to draw the character. +* @param[in] BGndColor The background color of the drawn character. +* @param[in] CharMagniCoeff The magnify coefficient used to draw the character. +* +* @warning The (0x0) point in on the low left corner. +* +**/ +/******************************************************************************/ +void LCD_DisplayChar( u8 x, u8 y, u8 Ascii, u16 TextColor, u16 BGndColor, u16 CharMagniCoeff) + { + // Display the selected bitmap according to the provided ASCII character. + LCD_DrawChar( x, y, 7, (u8*)&AsciiDotsTable[ (Ascii-32) * 14 ], TextColor, BGndColor, CharMagniCoeff ); + } + +/******************************************************************************* +* +* LCD_SetRect_For_Cmd +* +*******************************************************************************/ +/** +* +* Define the rectangle for the next command to be applied. +* +* @param[in] x The horizontal coordinate of the rectangle low left corner. +* @param[in] y The vertical coordinate of the rectangle low left corner. +* @param[in] width The rectangle width in pixels. +* @param[in] height The rectangle height in pixels. +* +* @warning The (0x0) point in on the low left corner. +* +**/ +/******************************************************************************/ +void LCD_SetRect_For_Cmd( s16 x, s16 y, s16 width, s16 height ) + { + LCD_SendLCDCmd( ST7637_CASET ); + LCD_SendLCDData( y + OrientationOffsetX[ CurrentScreenOrientation ] ); + LCD_SendLCDData( y + OrientationOffsetX[ CurrentScreenOrientation ] + height - 1 ); + + LCD_SendLCDCmd( ST7637_RASET ); + LCD_SendLCDData( x + OrientationOffsetY[ CurrentScreenOrientation ] ); + LCD_SendLCDData( x + OrientationOffsetY[ CurrentScreenOrientation ] + width - 1 ); + } + +/******************************************************************************* +* +* LCD_SetBackLight +* +*******************************************************************************/ +/** +* +* Modify the PWM rate. Any value below BACKLIGHTMIN reset the value to the +* default value (DEFAULT_CCR_BACKLIGHTSTART). +* +* @param[in] newBacklightStart The new PWM rate. +* +**/ +/******************************************************************************/ +void LCD_SetBackLight( u32 newBacklightStart ) + { + if( newBacklightStart >= BACKLIGHTMIN ) + { + Current_CCR_BackLightStart = newBacklightStart; + } + else + { + Current_CCR_BackLightStart = DEFAULT_CCR_BACKLIGHTSTART; + } + } + +/******************************************************************************* +* +* LCD_SetBackLightOff +* +*******************************************************************************/ +/** +* +* Switch the LCD back light off. +* +**/ +/******************************************************************************/ +void LCD_SetBackLightOff( void ) + { + Current_CCR_BackLightStart = 0; + } + +/******************************************************************************* +* +* LCD_SetBackLightOn +* +*******************************************************************************/ +/** +* +* Switch the LCD back light on. +* +**/ +/******************************************************************************/ +void LCD_SetBackLightOn( void ) + { + Current_CCR_BackLightStart = DEFAULT_CCR_BACKLIGHTSTART; + } + +/******************************************************************************* +* +* LCD_GetBackLight +* +*******************************************************************************/ +/** +* +* Returns le LCD PWM rate. +* +* @return The current LCD PWM rate. +* +**/ +/******************************************************************************/ +u32 LCD_GetBackLight( void ) + { + return Current_CCR_BackLightStart; + } + +/******************************************************************************* +* +* LCD_SetRotateScreen +* +*******************************************************************************/ +/** +* +* Enable or disable the ability of the screen display to rotate according to +* the MEMs information. +* +* @param[in] RotateScreen 0 to disable screen rotation and 1 to enable. +* +**/ +/******************************************************************************/ +void LCD_SetRotateScreen( u8 RotateScreen) + { + CurrentRotateScreen = RotateScreen; + } + +/******************************************************************************* +* +* LCD_GetRotateScreen +* +*******************************************************************************/ +/** +* +* Return the screen rotation mode. +* +* @retval 0 screen rotation is disabled. +* @retval 1 screen rotation is enabled. +* +**/ +/******************************************************************************/ +u8 LCD_GetRotateScreen( void ) + { + return CurrentRotateScreen; + } + +/******************************************************************************* +* +* LCD_SetScreenOrientation +* +*******************************************************************************/ +/** +* +* Set the screen orientation. +* +* @param[in] ScreenOrientation The new screen orientation. +* +**/ +/******************************************************************************/ +void LCD_SetScreenOrientation( Rotate_H12_V_Match_TypeDef ScreenOrientation ) + { + CurrentScreenOrientation = ScreenOrientation; + + LCD_DisplayRotate( CurrentScreenOrientation ); + } + +/******************************************************************************* +* +* LCD_GetScreenOrientation +* +*******************************************************************************/ +/** +* +* Return current screen orientation. +* +* @return A Rotate_H12_V_Match_TypeDef telling the current screen orientation. +* +**/ +/******************************************************************************/ +Rotate_H12_V_Match_TypeDef LCD_GetScreenOrientation( void ) + { + return CurrentScreenOrientation; + } + diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/lcd.h b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/lcd.h new file mode 100644 index 000000000..478f43824 --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/lcd.h @@ -0,0 +1,154 @@ +/********************* (C) COPYRIGHT 2007 RAISONANCE S.A.S. *******************/ +/** +* +* @file lcd.h +* @brief The header file for ST7637 driver. +* @author IB +* @date 07/2007 +* +**/ +/******************************************************************************/ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __LCD_H +#define __LCD_H + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f10x_lib.h" + +/* Type def -----------------------------------------------------------------*/ + +/* Data lines configuration mode */ +typedef enum + { + Input, + Output + } DataConfigMode_TypeDef; + +/* Constants -----------------------------------------------------------------*/ + +/* LCD Control pins */ +#define CtrlPin_RS GPIO_Pin_8 +#define CtrlPin_RD GPIO_Pin_9 +#define CtrlPin_WR GPIO_Pin_10 +#define CtrlPin_RST GPIO_Pin_12 +#define LCD_CTRL_PINS (CtrlPin_RS|CtrlPin_RD|CtrlPin_WR|CtrlPin_RST) +#define GPIOx_CTRL_LCD GPIOC +#define GPIO_LCD_CTRL_PERIPH RCC_APB2Periph_GPIOC + +#define CtrlPin_CS GPIO_Pin_2 +#define GPIOx_CS_LCD GPIOD +#define GPIO_LCD_CS_PERIPH RCC_APB2Periph_GPIOD + +#define LCD_D0 GPIO_Pin_0 +#define LCD_D1 GPIO_Pin_1 +#define LCD_D2 GPIO_Pin_2 +#define LCD_D3 GPIO_Pin_3 +#define LCD_D4 GPIO_Pin_4 +#define LCD_D5 GPIO_Pin_5 +#define LCD_D6 GPIO_Pin_6 +#define LCD_D7 GPIO_Pin_7 +#define LCD_DATA_PINS (LCD_D0|LCD_D1|LCD_D2|LCD_D3|LCD_D4|LCD_D5|LCD_D6|LCD_D7) +#define GPIOx_D_LCD GPIOC +#define GPIO_LCD_D_PERIPH RCC_APB2Periph_GPIOC + +/* LCD Commands */ +#define DISPLAY_ON 0xAF +#define DISPLAY_OFF 0xAE +#define START_LINE 0xC0 +#define START_COLUMN 0x00 +#define CLOCKWISE_OUTPUT 0xA0 +#define DYNAMIC_DRIVE 0xA4 +#define DUTY_CYCLE 0xA9 +#define READ_MODIFY_WRITE_OFF 0xEE +#define SOFTWARE_RESET 0xE2 + +#define ST7637_NOP 0x00 +#define ST7637_SWRESET 0x01 +#define ST7637_RDDID 0x04 +#define ST7637_RDDST 0x09 +#define ST7637_RDDPM 0x0A +#define ST7637_RDDMADCTR 0x0B +#define ST7637_RDDCOLMOD 0x0C +#define ST7637_RDDIM 0x0D +#define ST7637_RDDSM 0x0E +#define ST7637_RDDSDR 0x0F + +#define ST7637_SLPIN 0x10 +#define ST7637_SLPOUT 0x11 +#define ST7637_PTLON 0x12 +#define ST7637_NORON 0x13 + +#define ST7637_INVOFF 0x20 +#define ST7637_INVON 0x21 +#define ST7637_APOFF 0x22 +#define ST7637_APON 0x23 +#define ST7637_WRCNTR 0x25 +#define ST7637_DISPOFF 0x28 +#define ST7637_DISPON 0x29 +#define ST7637_CASET 0x2A +#define ST7637_RASET 0x2B +#define ST7637_RAMWR 0x2C +#define ST7637_RGBSET 0x2D +#define ST7637_RAMRD 0x2E + +#define ST7637_PTLAR 0x30 +#define ST7637_SCRLAR 0x33 +#define ST7637_TEOFF 0x34 +#define ST7637_TEON 0x35 +#define ST7637_MADCTR 0x36 +#define ST7637_VSCSAD 0x37 +#define ST7637_IDMOFF 0x38 +#define ST7637_IDMON 0x39 +#define ST7637_COLMOD 0x3A + +#define ST7637_RDID1 0xDA +#define ST7637_RDID2 0xDB +#define ST7637_RDID3 0xDC + +#define ST7637_DUTYSET 0xB0 +#define ST7637_FIRSTCOM 0xB1 +#define ST7637_OSCDIV 0xB3 +#define ST7637_PTLMOD 0xB4 +#define ST7637_NLINVSET 0xB5 +#define ST7637_COMSCANDIR 0xB7 +#define ST7637_RMWIN 0xB8 +#define ST7637_RMWOUT 0xB9 + +#define ST7637_VOPSET 0xC0 +#define ST7637_VOPOFSETINC 0xC1 +#define ST7637_VOPOFSETDEC 0xC2 +#define ST7637_BIASSEL 0xC3 +#define ST7637_BSTBMPXSEL 0xC4 +#define ST7637_BSTEFFSEL 0xC5 +#define ST7637_VOPOFFSET 0xC7 +#define ST7637_VGSORCSEL 0xCB + +#define ST7637_ID1SET 0xCC +#define ST7637_ID2SET 0xCD +#define ST7637_ID3SET 0xCE + +#define ST7637_ANASET 0xD0 +#define ST7637_AUTOLOADSET 0xD7 +#define ST7637_RDTSTSTATUS 0xDE + +#define ST7637_EPCTIN 0xE0 +#define ST7637_EPCTOUT 0xE1 +#define ST7637_EPMWR 0xE2 +#define ST7637_EPMRD 0xE3 +#define ST7637_MTPSEL 0xE4 +#define ST7637_ROMSET 0xE5 +#define ST7637_HPMSET 0xEB + +#define ST7637_FRMSEL 0xF0 +#define ST7637_FRM8SEL 0xF1 +#define ST7637_TMPRNG 0xF2 +#define ST7637_TMPHYS 0xF3 +#define ST7637_TEMPSEL 0xF4 +#define ST7637_THYS 0xF7 +#define ST7637_FRAMESET 0xF9 + +#define ST7637_MAXCOL 0x83 +#define ST7637_MAXPAG 0x83 + +#endif /*__LCD_H */ diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/led.c b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/led.c new file mode 100644 index 000000000..107ac66c4 --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/led.c @@ -0,0 +1,210 @@ +/********************* (C) COPYRIGHT 2007 RAISONANCE S.A.S. *******************/ +/** +* +* @file led.c +* @brief LED management. +* @author IB +* @date 07/2007 +* +**/ +/******************************************************************************/ + +/* Includes ------------------------------------------------------------------*/ +#include "circle.h" + +/// @cond Internal + +/* Private variables ---------------------------------------------------------*/ + +int GreenLED_Counter = 0; +int RedLED_Counter = 0; +enum LED_mode GreenLED_mode = LED_UNDEF; +enum LED_mode RedLED_mode = LED_UNDEF; +enum LED_mode GreenLED_newmode = LED_OFF; +enum LED_mode RedLED_newmode = LED_OFF; +const int HalfPeriod_LF = 200; +const int HalfPeriod_HF = 50; +const int Period_LF = 200 * 2; +const int Period_HF = 50 * 2; + +/* Public functions for CircleOS ---------------------------------------------*/ + +/******************************************************************************* +* +* LED_Init +* +*******************************************************************************/ +/** +* +* Initialization of the GPIOs for the LEDs +* +* @note Is called by CircleOS startup. +* +**/ +/******************************************************************************/ +void LED_Init( void ) + { + GPIO_InitTypeDef GPIO_InitStructure; + + /* Enable LED GPIO clock */ + RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE ); + + /* Configure LED pins as output push-pull */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 ; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + + GPIO_Init( GPIOB, &GPIO_InitStructure ); + } + +/******************************************************************************* +* +* LED_Handler +* +*******************************************************************************/ +/** +* +* Called by the CircleOS scheduler to manage the states of the LEDs. +* LEDs may be on, off or blinking according to their state. +* +**/ +/******************************************************************************/ +void LED_Handler( void ) + { + LED_Handler_hw(LED_GREEN); + LED_Handler_hw(LED_RED); + } + +/******************************************************************************* +* +* LED_Handler +* +*******************************************************************************/ +/** +* +* Called by the CircleOS scheduler to manage the states of the LEDs. +* LEDs may be on, off or blinking according to their state. +* +* @param[in] id A LED_id indicating the LED to take care of. +* +**/ +/******************************************************************************/ +void LED_Handler_hw( enum LED_id id ) + { + int counter; + enum LED_mode mode; + + // Choose the right LED parameters. + if( id == LED_GREEN ) + { + counter = GreenLED_Counter; + mode = GreenLED_newmode; + } + else + { + counter = RedLED_Counter; + mode = RedLED_newmode; + } + + switch( mode ) + { + case LED_OFF : + case LED_ON : + if( ( ( id == LED_GREEN ) && ( GreenLED_mode == mode ) ) || + ( ( id == LED_RED ) && ( RedLED_mode == mode ) ) ) + { + return; + } + + if( id == LED_GREEN ) + { + GPIO_WriteBit( GPIOB, GPIO_Pin_8, ( mode == LED_OFF ) ? Bit_RESET : Bit_SET ); + + GreenLED_mode = mode; + } + else if( id == LED_RED ) + { + GPIO_WriteBit( GPIOB, GPIO_Pin_9, ( mode == LED_OFF ) ? Bit_RESET : Bit_SET ); + + RedLED_mode = mode; + } + + counter = -1; + break; + + case LED_BLINKING_HF : + counter++; + + if( counter == HalfPeriod_HF ) + { + GPIO_WriteBit( GPIOB, ( id == LED_RED ) ? GPIO_Pin_9 : GPIO_Pin_8, Bit_SET ); + } + else if( ( counter < 0 ) || ( counter >= Period_HF ) ) + { + GPIO_WriteBit( GPIOB, ( id == LED_RED ) ? GPIO_Pin_9 : GPIO_Pin_8, Bit_RESET ); + + counter = 0; + } + break; + + case LED_BLINKING_LF : + counter++; + + if( counter == HalfPeriod_LF ) + { + GPIO_WriteBit( GPIOB, ( id == LED_RED ) ? GPIO_Pin_9 : GPIO_Pin_8, Bit_SET ); + } + + else if( ( counter < 0 ) || ( counter >= Period_LF ) ) + { + GPIO_WriteBit( GPIOB, ( id == LED_RED ) ? GPIO_Pin_9 : GPIO_Pin_8, Bit_RESET ); + + counter = 0; + } + break; + + default : + break; + } + + if( id == LED_GREEN ) + { + GreenLED_Counter = counter; + GreenLED_mode = mode; + } + else + { + RedLED_Counter = counter; + RedLED_mode = mode; + } + } + +/// @endcond + +/* Public functions ----------------------------------------------------------*/ + +/******************************************************************************* +* +* LED_Set +* +*******************************************************************************/ +/** +* +* Set a specified LED in a specified mode. +* +* @param[in] id A LED_id specifying the LED to change the mode. +* @param[in] mode A LED_mode describing the new LED mode. +* +**/ +/******************************************************************************/ +void LED_Set( enum LED_id id, enum LED_mode mode ) + { + if( id == LED_GREEN ) + { + GreenLED_newmode = mode; + } + else if( id == LED_RED ) + { + RedLED_newmode = mode; + } + } diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/mems.c b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/mems.c new file mode 100644 index 000000000..e226cd9fa --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/mems.c @@ -0,0 +1,605 @@ +/********************* (C) COPYRIGHT 2007 RAISONANCE S.A.S. *******************/ +/** +* +* @file mems.c +* @brief Mems Initialization and management +* @author FL +* @date 07/2007 +* @version 1.1 +* @date 10/2007 +* @version 1.5 various corrections reported by Ron Miller +* +**/ +/******************************************************************************/ + +/* Includes ------------------------------------------------------------------*/ +#include "circle.h" + +/// @cond Internal + +/* Private define ------------------------------------------------------------*/ +#define RDOUTXL 0xE8 /*!< Multiple Read from OUTXL */ +#define WRCTRL_REG1 0x20 /*!< Single Write CTRL_REG */ +#define RDCTRL_REG1 0xA0 /*!< Single Read CTRL_REG */ +#define RDID 0x8F /*!< Single Read WHO_AM_I */ +#define LOW 0x00 /*!< ChipSelect line low */ +#define HIGH 0x01 /*!< ChipSelect line high */ +#define DUMMY_BYTE 0xA5 +#define MEMS_DIVIDER 1 +#define MEMS_TESTING_DIVIDER 101 +#define MARGIN 500 +#define DELAY_REACT 20 +#define MIN_REACT 15 +#define DIV_REACT 10 +#define GRAD_SHOCK 200000 + +/* Private variables ---------------------------------------------------------*/ +tMEMS_Info MEMS_Info = {0}; // structure definition in circle.h +int TestingActive = 0; +int StartingFromResetOrShockCounter = 1000; +int TimeCounterForDoubleClick = 0; +int TimeLastShock = 0; +static int divider = 0; +static Rotate_H12_V_Match_TypeDef previous_Screen_Orientation; +u32 Gradient2; + +//Filtering +unsigned N_filtering = 0; + +//Gradient +s16 GradX = 0; +s16 GradY = 0; +s16 GradZ = 0; + +// Pointer move: +// each coordinate (X, Y and Z) is described by 3 variables where suffix means: +// f = flag to indicate that a move has been done. Cleared by the Ptr Manager when acknowledged. +// i = amplitude of the move (Grad / 10) +// t = delay to accept the counter reaction +int fMovePtrX; +int iMovePtrX; +int tMovePtrX; +int fMovePtrY; +int iMovePtrY; +int tMovePtrY; +int fMovePtrZ; +int iMovePtrZ; +int tMovePtrZ; + +s16 XInit = 0; +s16 YInit = 0; +s16 ZInit = 0; + +/* Private function prototypes -----------------------------------------------*/ +static void MEMS_ChipSelect( u8 State ); +static u8 MEMS_SendByte( u8 byte ); +static void MEMS_WriteEnable( void ); +static u32 MEMS_ReadOutXY( void ); +static void MEMS_WakeUp( void ); + +/* Private functions ---------------------------------------------------------*/ + +/******************************************************************************* +* +* MEMS_WakeUp +* +*******************************************************************************/ +/** +* Wake Up Mems. +* +**/ +/******************************************************************************/ +static void MEMS_WakeUp( void ) + { + u8 reg_val; + + /* read RDCTRL_REG1 */ + + /* Chip Select low */ + MEMS_ChipSelect( LOW ); + + /* Send "RDCTRL_REG1" instruction */ + MEMS_SendByte( RDCTRL_REG1 ); + + reg_val = MEMS_SendByte( DUMMY_BYTE ); + + /* Chip Select high */ + MEMS_ChipSelect( HIGH ); + + /* SET P0:P1 to '11' */ + /* 0xC0 to wake up and 0x30 for full speed frequency (640 Hz). */ + reg_val = reg_val | 0xC0 | 0x30; + + /* Chip Select low */ + MEMS_ChipSelect( LOW ); + + /* Send "WRCTRL_REG1" instruction */ + MEMS_SendByte( WRCTRL_REG1 ); + MEMS_SendByte( reg_val ); + + /* Chip Select high */ + MEMS_ChipSelect( HIGH ); + } + +/******************************************************************************* +* +* MEMS_ReadOutXY +* +*******************************************************************************/ +/** +* Reads X and Y Out. +* +* @return An unsigned 32 bit word with the highest 16 bits containing the Y +* and the lowest 16 bits the X. +* +**/ +/******************************************************************************/ +static u32 MEMS_ReadOutXY( void ) + { + u8 OutXL; + u8 OutXH; + u8 OutYL; + u8 OutYH; + u8 OutZL; + u8 OutZH; + + /* Chip Select low */ + MEMS_ChipSelect( LOW ); + + /* Send "RDOUTXL" instruction */ + MEMS_SendByte( RDOUTXL ); + + /* Read a byte */ + OutXL = MEMS_SendByte( DUMMY_BYTE ); + + /* Read a byte */ + OutXH = MEMS_SendByte( DUMMY_BYTE ); + + /* Read a byte */ + OutYL = MEMS_SendByte( DUMMY_BYTE ); + + /* Read a byte */ + OutYH = MEMS_SendByte( DUMMY_BYTE ); + + /* Read a byte */ + OutZL = MEMS_SendByte( DUMMY_BYTE ); + + /* Read a byte */ + OutZH = MEMS_SendByte( DUMMY_BYTE ); + + MEMS_Info.OutX = OutXL + ( OutXH << 8 ); + MEMS_Info.OutY = OutYL + ( OutYH << 8 ); + MEMS_Info.OutZ = OutZL + ( OutZH << 8 ); + + /* Chip Select high */ + MEMS_ChipSelect( HIGH ); + + MEMS_Info.OutX_F4 += ( MEMS_Info.OutX - ( MEMS_Info.OutX_F4 >> 2 ) ); // Filter on 4 values. + MEMS_Info.OutY_F4 += ( MEMS_Info.OutY - ( MEMS_Info.OutY_F4 >> 2 ) ); // Filter on 4 values. + MEMS_Info.OutZ_F4 += ( MEMS_Info.OutZ - ( MEMS_Info.OutZ_F4 >> 2 ) ); // Filter on 4 values. + + MEMS_Info.OutX_F16 += ( MEMS_Info.OutX - ( MEMS_Info.OutX_F16 >> 4 ) ); // Filter on 16 values. + MEMS_Info.OutY_F16 += ( MEMS_Info.OutY - ( MEMS_Info.OutY_F16 >> 4 ) ); // Filter on 16 values. + MEMS_Info.OutZ_F16 += ( MEMS_Info.OutZ - ( MEMS_Info.OutZ_F16 >> 4 ) ); // Filter on 16 values. + + MEMS_Info.OutX_F64 += ( MEMS_Info.OutX - ( MEMS_Info.OutX_F64 >> 6 ) ); // Filter on 64 values. + MEMS_Info.OutY_F64 += ( MEMS_Info.OutY - ( MEMS_Info.OutY_F64 >> 6 ) ); // Filter on 64 values. + MEMS_Info.OutZ_F64 += ( MEMS_Info.OutZ - ( MEMS_Info.OutZ_F64 >> 6 ) ); // Filter on 64 values. + + MEMS_Info.OutX_F256 += ( MEMS_Info.OutX - ( MEMS_Info.OutX_F256 >> 8) ); // Filter on 256 values. + MEMS_Info.OutY_F256 += ( MEMS_Info.OutY - ( MEMS_Info.OutY_F256 >> 8) ); // Filter on 256 values. + MEMS_Info.OutZ_F256 += ( MEMS_Info.OutZ - ( MEMS_Info.OutZ_F256 >> 8) ); // Filter on 256 values. + + if( N_filtering < 256 ) + { + // Just to validate the calculated average values. + N_filtering++; + } + + return ( MEMS_Info.OutX + ( MEMS_Info.OutY << 16 ) ); + } + +/******************************************************************************* +* +* MEMS_ChipSelect +* +*******************************************************************************/ +/** +* Selects or deselects the MEMS device. +* +* @param[in] State Level to be applied on ChipSelect pin. +* +**/ +/******************************************************************************/ +static void MEMS_ChipSelect( u8 State ) + { + /* Set High or low the chip select line on PA.4 pin */ + GPIO_WriteBit( GPIOD, GPIO_Pin_2, (BitAction)State ); + } + +/******************************************************************************* +* +* MEMS_SendByte +* +*******************************************************************************/ +/** +* Sends a byte through the SPI interface and return the byte received from +* the SPI bus. +* +* @param[in] byte The byte to send to the SPI interface. +* +* @return The byte returned by the SPI bus. +* +**/ +/******************************************************************************/ +static u8 MEMS_SendByte( u8 byte ) + { + /* Loop while DR register in not emplty */ + while( SPI_GetFlagStatus( SPI2, SPI_FLAG_TXE ) == RESET ); + + /* Send byte through the SPI2 peripheral */ + SPI_SendData( SPI2, byte ); + + /* Wait to receive a byte */ + while( SPI_GetFlagStatus( SPI2, SPI_FLAG_RXNE ) == RESET ); + + /* Return the byte read from the SPI bus */ + return SPI_ReceiveData( SPI2 ); + } + +/* Public functions for CircleOS ---------------------------------------------*/ + +/******************************************************************************* +* +* MEMS_Init +* +*******************************************************************************/ +/** +* +* Initializes the peripherals used by the SPI MEMS driver. +* +* @attention This function must NOT be called by the user. +* +**/ +/******************************************************************************/ +void MEMS_Init(void) +{ + SPI_InitTypeDef SPI_InitStructure; + GPIO_InitTypeDef GPIO_InitStructure; + + /* Configure PC6 and PC7 as Output push-pull For MEMS*/ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + + GPIO_Init( GPIOC, &GPIO_InitStructure ); + + /* Enable SPI2 and GPIOA clocks */ + RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE ); + RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE ); + RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOD, ENABLE ); + + /* Configure SPI2 pins: SCK, MISO and MOSI */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + + GPIO_Init( GPIOB, &GPIO_InitStructure ); + + /* Configure PD2 as Output push-pull, used as MEMS Chip select */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + + GPIO_Init( GPIOD, &GPIO_InitStructure ); + + /* SPI2 configuration */ + SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; + SPI_InitStructure.SPI_Mode = SPI_Mode_Master; + SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; + SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; + SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; + SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; + SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; + SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; + SPI_InitStructure.SPI_CRCPolynomial = 7; + + SPI_Init( SPI2, &SPI_InitStructure ); + + /* Enable SPI2 */ + SPI_Cmd( SPI2, ENABLE ); + + if( MEMS_ReadID() != 0x3A ) + { + int i; + + // Try to resynchronize + for( i = 0 ; i < 17 ; i++ ) + { + /* Configure SPI2 pins: SCK, MISO and MOSI */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_15; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + + GPIO_Init( GPIOB, &GPIO_InitStructure ); + GPIO_WriteBit( GPIOB, GPIO_Pin_15, HIGH ); + MEMS_ChipSelect( LOW ); + + GPIO_WriteBit( GPIOB, GPIO_Pin_13, LOW ); + GPIO_WriteBit( GPIOB, GPIO_Pin_13, HIGH ); + MEMS_ChipSelect( HIGH ); + + /* Configure again PB. SCK as SPI2 pin */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_15; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + + GPIO_Init( GPIOB, &GPIO_InitStructure ); + if ( MEMS_ReadID() == 0x3A ) + { + break; + } + } + + if( i == 17 ) + { + DRAW_DisplayString( 1, 50, "Test MEM ID Failed", 17 ); + } + } + + /* Read for the first time */ + N_filtering = 0; + + MEMS_ReadOutXY(); + + MEMS_Info.OutX_F4 = MEMS_Info.OutX_F16 = MEMS_Info.OutX_F64 = MEMS_Info.OutX_F256 = MEMS_Info.OutX; + MEMS_Info.OutY_F4 = MEMS_Info.OutY_F16 = MEMS_Info.OutY_F64 = MEMS_Info.OutY_F256 = MEMS_Info.OutY; + MEMS_Info.OutZ_F4 = MEMS_Info.OutZ_F16 = MEMS_Info.OutZ_F64 = MEMS_Info.OutZ_F256 = MEMS_Info.OutZ; + + /* Init X and Y*/ + MEMS_GetPosition( &XInit, &YInit ); + + /* Wake Up Mems*/ + MEMS_WakeUp(); +} + +/******************************************************************************* +* +* MEMS_Handler +* +*******************************************************************************/ +/** +* +* Called by the CircleOS scheduler to manage the MEMS. The Circle beeps if the +* MEMS is shocked. +* +* @attention This function must NOT be called by the user. +* +**/ +/******************************************************************************/ +void MEMS_Handler( void ) + { + char buffer [20]; + int i; + int ofs_disp = 0; + + if( StartingFromResetOrShockCounter ) + { + StartingFromResetOrShockCounter--; + } + TimeCounterForDoubleClick++; + + MEMS_ReadOutXY(); + + // Evaluate gradients + GradX = ( MEMS_Info.OutX_F4 >> 2 ) - MEMS_Info.OutX; + GradY = ( MEMS_Info.OutY_F4 >> 2 ) - MEMS_Info.OutY; + GradZ = ( MEMS_Info.OutZ_F4 >> 2 ) - MEMS_Info.OutZ; + + // Decide whether a direction is selected + if( tMovePtrX == 0 ) + { + if( ( GradX > MIN_REACT ) || ( GradX < -MIN_REACT ) ) + { + iMovePtrX = GradX / DIV_REACT; + tMovePtrX = DELAY_REACT; + fMovePtrX = 1; + } + } + else + { + tMovePtrX--; + } + + if( tMovePtrY == 0 ) + { + if( ( GradY > MIN_REACT ) || ( GradY < -MIN_REACT ) ) + { + iMovePtrY = GradY / DIV_REACT; //FL071012 rrm fix + tMovePtrY = DELAY_REACT; + fMovePtrY = 1; + } + } + else + { + tMovePtrY--; + } + + if( tMovePtrZ==0 ) + { + if( ( GradZ > MIN_REACT ) || ( GradY < -MIN_REACT ) ) + { + iMovePtrZ = GradZ / DIV_REACT; + tMovePtrZ = DELAY_REACT; + fMovePtrZ = 1; + } + } + else + { + tMovePtrZ--; + } + + Gradient2 = (s32)GradX * (s32)GradX + (s32)GradY * (s32)GradY + (s32)GradZ * (s32)GradZ; + + // MEMS is shocked, let's beep! + if( ( Gradient2 > GRAD_SHOCK ) && ( BUZZER_GetMode() == BUZZER_OFF ) && ( StartingFromResetOrShockCounter == 0 ) ) + { + MEMS_Info.Shocked++; +/*FL071007 = 1; + Suggested by Bob Seabrook: a further posiblity is to increment Shocked rather than just setting it + So it can still be tested for non zero as before but one can get more + info from the int without extra cost. */ + +#define DELAY_BETWEEN_TWO_SHOCK 20 +#define MAX_DELAY_FOR_DOUBLECLICK 150 + StartingFromResetOrShockCounter = DELAY_BETWEEN_TWO_SHOCK; //< filter: short delay before detecting the next shock + if ( (TimeCounterForDoubleClick - TimeLastShock) < MAX_DELAY_FOR_DOUBLECLICK ) + { + MEMS_Info.DoubleClick++; + TimeLastShock = 0; + } + else + { + TimeLastShock = TimeCounterForDoubleClick; + } + BUZZER_SetMode( BUZZER_SHORTBEEP ); + } + } + +/******************************************************************************* +* +* MEMS_ReadID +* +*******************************************************************************/ +/** +* Reads SPI chip identification. +* +* @return The SPI chip identification. +* +**/ +/******************************************************************************/ +u8 MEMS_ReadID( void ) + { + u8 Temp = 0; + + /* Chip Select low */ + MEMS_ChipSelect( LOW ); + + /* Send "RDID" instruction */ + MEMS_SendByte( RDID ); + + /* Read a byte from the MEMS */ + Temp = MEMS_SendByte( DUMMY_BYTE ); + + /* Chip Select low */ + MEMS_ChipSelect( HIGH ); + + return Temp; + } + +/// @endcond + +/* Public functions ----------------------------------------------------------*/ + +/******************************************************************************* +* +* MEMS_GetPosition +* +*******************************************************************************/ +/** +* +* Returns the current (relative) position of the Primer. +* Only X-Y axis are considered here. +* +* @param[out] pX Current horizontal coordinate. +* @param[out] pY Current vertical coordinate. +* +* @warning The (0x0) point in on the low left corner. +* @note For absolute position information use MEMS_GetInfo() +* +**/ +/******************************************************************************/ +void MEMS_GetPosition( s16* pX, s16* pY ) + { + *pX = MEMS_Info.OutX - XInit; + *pY = MEMS_Info.OutY - YInit; + } + +/******************************************************************************* +* +* MEMS_GetRotation +* +*******************************************************************************/ +/** +* +* Returns current screen orientation. +* +* @param[out] pH12 Current screen orientation. +* +**/ +/******************************************************************************/ +void MEMS_GetRotation( Rotate_H12_V_Match_TypeDef* pH12 ) + { + s16 sX = MEMS_Info.OutX; + s16 sY = MEMS_Info.OutY; + + if( ( ( sX <= -MARGIN ) && ( sY <= 0 ) && (sX<=sY ) ) || + ( ( sX <=- MARGIN ) && ( sY > 0) && (sX <= (-sY ) ) ) ) + { + // 1st case: x<0, |x|>y => H12 = V9 + *pH12 = V9; + } + else if( ( ( sY <= -MARGIN ) && ( sX <= 0 ) && ( sY <= sX ) ) || + ( ( sY <= -MARGIN ) && ( sX > 0 ) && ( sY <= (-sX ) ) ) ) + { + // 2nd case: y<0, |y|>x => H12 = V12 + *pH12 = V12; + } + else if( ( ( sX >= MARGIN ) && ( sY <= 0 ) && ( sX >= (-sY) ) ) || + ( ( sX >= MARGIN ) && ( sY > 0 ) && ( sX >= sY ) ) ) + { + // 3rd case: x>0, |x|>y => H12=V3 + *pH12 = V3; + } + else if( ( ( sY >= MARGIN ) && ( sX <= 0 ) && ( sY >= (-sX ) ) ) || + ( ( sY >= MARGIN ) && ( sX > 0 ) && ( sY >= sX ) ) ) + { + // 4th case: y>0, |y|>x => H12=V6 + *pH12 = V6; + } + } + +/******************************************************************************* +* +* MEMS_SetNeutral +* +*******************************************************************************/ +/** +* +* Set current position as "neutral position". +* +**/ +/******************************************************************************/ +void MEMS_SetNeutral( void ) + { + // Set Neutral position. + MEMS_GetPosition( &XInit, &YInit ); + } + +/******************************************************************************* +* +* MEMS_GetInfo +* +*******************************************************************************/ +/** +* +* Return the current MEMS information (state, absolute position...). +* +* @return a pointer to tMEMS_Info +* +**/ +/******************************************************************************/ +tMEMS_Info* MEMS_GetInfo( void ) + { + return &MEMS_Info; + } diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/pointer.c b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/pointer.c new file mode 100644 index 000000000..02fe9834b --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/pointer.c @@ -0,0 +1,901 @@ +/********************* (C) COPYRIGHT 2007 RAISONANCE S.A.S. *******************/ +/** +* +* @file pointer.c +* @brief Various utilities for the pointer management for STM32-primer. +* @author FL +* @date 07/2007 +* @version 1.1 +* @date 10/2007 +* @version 1.5 various corrections reported by Ron Miller to suppress jittery +* +* +**/ +/******************************************************************************/ + +/* Includes ------------------------------------------------------------------*/ +#include "circle.h" + +/// @cond Internal + +/* Private define ------------------------------------------------------------*/ +#define POS_MIN 0 +#define POS_MAX (SCREEN_WIDTH - POINTER_WIDTH - 1) +#define POINTER_DIVIDER 50 +#define POINTER_DEFAULT_COLOR RGB_BLUE + +// defines for pointer move +#define ANGLEPAUSE 500 +#define DEFAULT_ANGLESTART 25 +#define MIN_ANGLE_FOR_SHIFT_UP (ANGLEPAUSE+CurrentAngleStart) +#define MIN_ANGLE_FOR_SHIFT_DOWN (ANGLEPAUSE-CurrentAngleStart) +#define MIN_ANGLE_FOR_SHIFT_RIGHT (signed)(0+CurrentAngleStart) +#define MIN_ANGLE_FOR_SHIFT_LEFT (signed)(0-CurrentAngleStart) +#define DEFAULT_SPEED_ON_ANGLE 60 + +/* Private variables ---------------------------------------------------------*/ +static int divider = 0; + +unsigned char BallPointerBmp[ POINTER_WIDTH ] = { 0x38, 0x7C, 0xFF, 0xFF, 0xFF, 0x7C, 0x38 } ; +unsigned char locbuf[ POINTER_WIDTH ]; +unsigned char DefaultAreaStore[ 2 * POINTER_WIDTH * POINTER_WIDTH ]; + +// Variables for pointer. +u8* CurrentPointerBmp = 0; +u8 CurrentPointerWidth = 0; +u8 CurrentPointerHeight = 0; +u16 CurrentSpeedOnAngle = DEFAULT_SPEED_ON_ANGLE; +u32 CurrentAngleStart = DEFAULT_ANGLESTART ; +unsigned char* ptrAreaStore = DefaultAreaStore; +u16 CurrentPointerColor = POINTER_DEFAULT_COLOR; +enum POINTER_mode Pointer_Mode = POINTER_UNDEF; +enum POINTER_state Pointer_State = POINTER_S_UNDEF; + +s16 OUT_X; +s16 OUT_Y; + +// Init pointer Info Structure (structure definition in circle.h) +tPointer_Info POINTER_Info = { + SCREEN_WIDTH - POINTER_WIDTH / 2, + SCREEN_WIDTH - POINTER_WIDTH / 2, + 0, + 0} ; + +/* Private function prototypes -----------------------------------------------*/ +static int POINTER_Move ( void ); + +/* Private functions ---------------------------------------------------------*/ + +/******************************************************************************* +* +* Pointer_Move +* +*******************************************************************************/ +/** +* Moves LCD pointer according to Mems indications. +* +* @retval 0 The pointer resides in the screen +* @retval -1 The pointer touche the screen edges. +* +**/ +/******************************************************************************/ +static int POINTER_Move( void ) + { + int res = 0; + s16 oldPointer_xPos = POINTER_Info.xPos; + s16 oldPointer_yPos = POINTER_Info.yPos; + s16 unmodied_shift_PosX; + s16 unmodied_shift_PosY; + signed outx = MEMS_Info.OutX_F16 >> 4; + signed outy = MEMS_Info.OutY_F16 >> 4; + + POINTER_Info.shift_PosX = POINTER_Info.shift_PosY = 0; + + // The move depends on the screen orientation + switch( LCD_GetScreenOrientation() ) + { + // north + case V12 : + MEMS_Info.RELATIVE_X = outx; + MEMS_Info.RELATIVE_Y = outy; + + if( outx > MIN_ANGLE_FOR_SHIFT_RIGHT ) + { + POINTER_Info.shift_PosX = ( outx - MIN_ANGLE_FOR_SHIFT_RIGHT ); + } + else if( outx < MIN_ANGLE_FOR_SHIFT_LEFT ) + { + POINTER_Info.shift_PosX = ( outx - MIN_ANGLE_FOR_SHIFT_LEFT ); + } + + if( outy < -MIN_ANGLE_FOR_SHIFT_UP ) + { + POINTER_Info.shift_PosY = ( outy + MIN_ANGLE_FOR_SHIFT_UP ); + } + else if( outy > -MIN_ANGLE_FOR_SHIFT_DOWN ) + { + POINTER_Info.shift_PosY = ( outy + MIN_ANGLE_FOR_SHIFT_DOWN ); + } + break; + + // West + case V9 : + MEMS_Info.RELATIVE_X = -( outy ); + MEMS_Info.RELATIVE_Y = outx; + + if( outy > MIN_ANGLE_FOR_SHIFT_RIGHT ) + { + POINTER_Info.shift_PosX = -( outy - MIN_ANGLE_FOR_SHIFT_RIGHT ); + } + else if( outy < MIN_ANGLE_FOR_SHIFT_LEFT ) + { + POINTER_Info.shift_PosX = -( outy - MIN_ANGLE_FOR_SHIFT_LEFT ); + } + + if( outx < -MIN_ANGLE_FOR_SHIFT_UP ) + { + POINTER_Info.shift_PosY = ( outx + MIN_ANGLE_FOR_SHIFT_UP ); + } + else if( outx > -MIN_ANGLE_FOR_SHIFT_DOWN ) + { + POINTER_Info.shift_PosY = ( outx + MIN_ANGLE_FOR_SHIFT_DOWN ); + } + break; + + // South + case V6 : + MEMS_Info.RELATIVE_X = -( outx ); + MEMS_Info.RELATIVE_Y = -( outy ); + + if( outx > MIN_ANGLE_FOR_SHIFT_RIGHT ) + { + POINTER_Info.shift_PosX = ( MIN_ANGLE_FOR_SHIFT_RIGHT - outx ); + } + else if( outx < MIN_ANGLE_FOR_SHIFT_LEFT ) + { + POINTER_Info.shift_PosX = ( MIN_ANGLE_FOR_SHIFT_LEFT - outx ); + } + + if( outy > MIN_ANGLE_FOR_SHIFT_UP ) + { + POINTER_Info.shift_PosY = -( outy - MIN_ANGLE_FOR_SHIFT_UP ); + } + else if( outy < MIN_ANGLE_FOR_SHIFT_DOWN ) + { + POINTER_Info.shift_PosY = +( MIN_ANGLE_FOR_SHIFT_DOWN - outy ); + } + break; + + // East + case V3 : + MEMS_Info.RELATIVE_X = outy; + MEMS_Info.RELATIVE_Y = -( outx ); + + if( outy > MIN_ANGLE_FOR_SHIFT_RIGHT ) + { + POINTER_Info.shift_PosX = ( outy - MIN_ANGLE_FOR_SHIFT_RIGHT ); + } + else if( outy < MIN_ANGLE_FOR_SHIFT_LEFT ) + { + POINTER_Info.shift_PosX = ( outy - MIN_ANGLE_FOR_SHIFT_LEFT ); + } + + if( outx > MIN_ANGLE_FOR_SHIFT_UP ) + { + POINTER_Info.shift_PosY = ( MIN_ANGLE_FOR_SHIFT_UP - outx); + } + else if( outx < MIN_ANGLE_FOR_SHIFT_DOWN ) + { + POINTER_Info.shift_PosY = ( MIN_ANGLE_FOR_SHIFT_DOWN - outx ); + } + + default : + break; + } + + unmodied_shift_PosX = POINTER_Info.shift_PosX; + unmodied_shift_PosY = POINTER_Info.shift_PosY; + + POINTER_Info.shift_PosX /= CurrentSpeedOnAngle; + POINTER_Info.shift_PosY /= CurrentSpeedOnAngle; + + if( Pointer_Mode == POINTER_APPLICATION ) + { + if ( Application_Pointer_Mgr ) + { + Application_Pointer_Mgr( POINTER_Info.shift_PosX, POINTER_Info.shift_PosY ); + } + + return 0; + } + + POINTER_Info.xPos += POINTER_Info.shift_PosX; + POINTER_Info.yPos += POINTER_Info.shift_PosY; + + if( POINTER_Info.xPos < POINTER_Info.X_PosMin ) + { + POINTER_Info.xPos = POINTER_Info.X_PosMin; + } + + if( POINTER_Info.xPos > POINTER_Info.X_PosMax ) + { + POINTER_Info.xPos = POINTER_Info.X_PosMax; + } + + if( POINTER_Info.yPos < POINTER_Info.Y_PosMin ) + { + POINTER_Info.yPos = POINTER_Info.Y_PosMin; + } + + if( POINTER_Info.yPos > POINTER_Info.Y_PosMax ) + { + POINTER_Info.yPos = POINTER_Info.Y_PosMax; + } + + if( ( Pointer_Mode != POINTER_MENU ) && ( Pointer_Mode != POINTER_RESTORE_LESS ) && + ( ( oldPointer_xPos != POINTER_Info.xPos ) || ( oldPointer_yPos != POINTER_Info.yPos ) ) ) + { + // Use default area. + POINTER_SetCurrentAreaStore( 0 ); + + // Restore previously drawn area. + POINTER_Restore( oldPointer_xPos, oldPointer_yPos, POINTER_WIDTH, POINTER_WIDTH ); + + // Save new area and draw pointer + POINTER_Save( POINTER_Info.xPos, POINTER_Info.yPos, POINTER_WIDTH, POINTER_WIDTH ); + POINTER_Draw( POINTER_Info.xPos, POINTER_Info.yPos, POINTER_WIDTH, POINTER_WIDTH, CurrentPointerBmp ); + } + + if( ( Pointer_Mode == POINTER_RESTORE_LESS ) && + ( ( oldPointer_xPos != POINTER_Info.xPos ) || ( oldPointer_yPos != POINTER_Info.yPos ) ) ) + { + // Use default area. + POINTER_SetCurrentAreaStore( 0 ); + + // Restore previously drawn area. + POINTER_Restore( oldPointer_xPos, oldPointer_yPos, CurrentPointerWidth, CurrentPointerHeight ); + + // Save new area and draw pointer + POINTER_Save( POINTER_Info.xPos, POINTER_Info.yPos, CurrentPointerWidth, CurrentPointerHeight ); + POINTER_Draw( POINTER_Info.xPos, POINTER_Info.yPos, CurrentPointerWidth, CurrentPointerHeight, CurrentPointerBmp ); + } + + // Is the pointer touching one edge of the screen ? + if( ( POINTER_Info.xPos == POS_MIN ) || ( POINTER_Info.yPos == POS_MIN ) || + ( POINTER_Info.xPos == POS_MAX ) || ( POINTER_Info.yPos == POS_MAX ) ) + { + res = -1; + } + + return res; + } + +/* Public functions for CircleOS ---------------------------------------------*/ + +/******************************************************************************* +* +* POINTER_Init +* +*******************************************************************************/ +/** +* Initialize pointer. Called at CircleOS startup. Set default pointer at the +* middle of the screen and allows it to move into the whole screen. +* +* @attention This function must NOT be called by the user. +* +**/ +/******************************************************************************/ +void POINTER_Init( void ) + { + // Increase pointer sensibility. + POINTER_SetCurrentSpeedOnAngle( DEFAULT_SPEED_ON_ANGLE ); + POINTER_SetCurrentAngleStart( DEFAULT_ANGLESTART ); + POINTER_SetCurrentPointer( POINTER_WIDTH, POINTER_WIDTH, BallPointerBmp ); + POINTER_SetMode( POINTER_ON ); + POINTER_SetPos( 56, 56 ); + POINTER_SetRectScreen(); + + CurrentPointerColor = POINTER_DEFAULT_COLOR; + } + +/******************************************************************************* +* +* POINTER_Handler +* +*******************************************************************************/ +/** +* +* Called by the CircleOS scheduler to manage the pointer. +* +* @attention This function must NOT be called by the user. +* +**/ +/******************************************************************************/ +void POINTER_Handler( void ) + { + switch( Pointer_Mode ) + { + // Nothing to do! + case POINTER_OFF : + case POINTER_UNDEF: + return; + } + + // Where is the MEMS ? + MEMS_GetPosition( &OUT_X, &OUT_Y ); + + POINTER_Move(); + } + +/// @endcond + +/* Public functions ----------------------------------------------------------*/ + +/******************************************************************************* +* +* POINTER_SetCurrentPointer +* +*******************************************************************************/ +/** +* +* Set the dimension and the bitmap of the pointer. +* @note The bitmap is a monochrome one! +* +* @param[in] width width of the pointer (u8) +* @param[in] height height of the pointer (u8) +* @param[in] bmp pointer to an array of width * height bits. +* +**/ +/********************************************************************************/ +void POINTER_SetCurrentPointer( u8 width, u8 height, u8* bmp ) + { + if( !bmp ) + { + bmp = BallPointerBmp; + } + + CurrentPointerWidth = width; + CurrentPointerHeight = height; + CurrentPointerBmp = bmp; + } + +/******************************************************************************* +* +* POINTER_GetCurrentAngleStart +* +*******************************************************************************/ +/** +* +* Get the current minimal angle to move pointer +* +* @return current minimal angle. +* +**/ +/******************************************************************************/ +u16 POINTER_GetCurrentAngleStart( void ) + { + return CurrentAngleStart; + } + +/******************************************************************************* +* +* POINTER_SetCurrentAngleStart +* +*******************************************************************************/ +/** +* +* Set the current minimal angle to move pointer +* +* @param[in] newangle The new minimal angle to move pointer. +* +**/ +/******************************************************************************/ +void POINTER_SetCurrentAngleStart( u16 newangle ) + { + CurrentAngleStart = newangle; + } + +/******************************************************************************* +* +* POINTER_GetCurrentSpeedOnAngle +* +*******************************************************************************/ +/** +* +* Return the current speed/angle ratio. +* +* @return current ratio. +* +**/ +/******************************************************************************/ +u16 POINTER_GetCurrentSpeedOnAngle( void ) + { + return CurrentSpeedOnAngle; + } + +/******************************************************************************* +* +* POINTER_SetCurrentSpeedOnAngle +* +*******************************************************************************/ +/** +* +* Set the current speed/angle ratio. +* +* @param[in] newspeed New speed/angle ratio. +* +**/ +/******************************************************************************/ +void POINTER_SetCurrentSpeedOnAngle( u16 newspeed ) + { + CurrentSpeedOnAngle = newspeed; + } + +/******************************************************************************* +* +* POINTER_SetCurrentAreaStore +* +*******************************************************************************/ +/** +* +* Change the current storage area. If the provided value is NULL, the default +* storage area will be used. +* +* @param[in] ptr New storage area (may be null). +* +* @warning Memory space pointed by the provided pointer must be large enough +* to store a color bitmap corresponding to the pointer area. +* In other words, space must be width * height * 2 large. +* +**/ +/******************************************************************************/ +void POINTER_SetCurrentAreaStore( u8* ptr ) + { + ptrAreaStore = ( ptr == 0 ) ? DefaultAreaStore : ptr; + } + +/******************************************************************************* +* +* POINTER_SetMode +* +*******************************************************************************/ +/** +* +* Change the current mode of the pointer management. +* +* @note Must be called only ONCE!! +* +* @param[in] mode New pointer management mode. +* +**/ +/******************************************************************************/ +void POINTER_SetMode( enum POINTER_mode mode ) + { + u16* ptr; + u16 i; + u16 color; + + switch( mode ) + { + case POINTER_APPLICATION: + ptr = (u16*)DefaultAreaStore; + color = DRAW_GetBGndColor(); + + for ( i = 0; i < (CurrentPointerWidth*CurrentPointerHeight) ; i++ ) + { + *ptr++ = color; + } + + POINTER_Draw( POINTER_Info.xPos, POINTER_Info.yPos, CurrentPointerWidth, CurrentPointerHeight, CurrentPointerBmp ); + break; + + case POINTER_RESTORE_LESS: + POINTER_Draw( POINTER_Info.xPos, POINTER_Info.yPos, CurrentPointerWidth, CurrentPointerHeight, CurrentPointerBmp ); + break; + + case POINTER_ON: + POINTER_SetCurrentAreaStore( 0 ); + POINTER_Save( POINTER_Info.xPos, POINTER_Info.yPos, POINTER_WIDTH, POINTER_WIDTH ); + POINTER_Draw( POINTER_Info.xPos, POINTER_Info.yPos, CurrentPointerWidth, CurrentPointerHeight,CurrentPointerBmp ); + break; + + case POINTER_OFF: + POINTER_Info.xPos = ( SCREEN_WIDTH - POINTER_WIDTH ) / 2; + POINTER_Info.yPos = ( SCREEN_WIDTH - POINTER_WIDTH ) / 2; + + case POINTER_MENU: + if( Pointer_Mode == POINTER_ON ) + { + POINTER_SetCurrentAreaStore( 0 ); + POINTER_Restore( POINTER_Info.xPos, POINTER_Info.yPos, POINTER_WIDTH, POINTER_WIDTH ); + } + break; + } + + Pointer_Mode = mode; + } + +/******************************************************************************* +* +* POINTER_GetMode +* +*******************************************************************************/ +/** +* +* Return the current mode of the pointer management +* +* @return Current pointer management mode. +* +**/ +/******************************************************************************/ +enum POINTER_mode POINTER_GetMode( void ) + { + return Pointer_Mode; + } + +/******************************************************************************* +* +* POINTER_GetState +* +*******************************************************************************/ +/** +* +* Return current pointer state. +* +* @return Current pointer state. +* +**/ +/******************************************************************************/ +enum POINTER_state POINTER_GetState( void ) + { + return Pointer_State; + } + +/******************************************************************************* +* +* POINTER_SetRect +* +*******************************************************************************/ +/** +* +* Set new limits for the move of the pointer +* +* @param[in] x Horizontal coordinate of the bottom left corner of the new area. +* @param[in] y Vertical coordinate of the bottom left corner of the new are. +* @param[in] width New area width. +* @param[in] height New area height. +* +* @warning The (0x0) point in on the low left corner. +* +**/ +/******************************************************************************/ +void POINTER_SetRect( s16 x, s16 y, s16 width, s16 height ) + { + POINTER_Info.X_PosMin = x; + + if( POINTER_Info.xPos < POINTER_Info.X_PosMin ) + { + POINTER_Info.xPos = POINTER_Info.X_PosMin; + } + + POINTER_Info.X_PosMax = x + width - 1; + + if( POINTER_Info.xPos > POINTER_Info.X_PosMax ) + { + POINTER_Info.xPos = POINTER_Info.X_PosMax; + } + + POINTER_Info.Y_PosMin = y; + + if( POINTER_Info.yPos < POINTER_Info.Y_PosMin ) + { + POINTER_Info.yPos = POINTER_Info.Y_PosMin; + } + + POINTER_Info.Y_PosMax = y + height - 1; + + if( POINTER_Info.yPos > POINTER_Info.Y_PosMax ) + { + POINTER_Info.yPos = POINTER_Info.Y_PosMax; + } + } + +/******************************************************************************* +* +* POINTER_SetRectScreen +* +*******************************************************************************/ +/** +* +* Allow the pointer to move on the whole screen. +* +**/ +/******************************************************************************/ +void POINTER_SetRectScreen( void ) + { + POINTER_SetRect( 0, 0, POS_MAX, POS_MAX ); + } + +/******************************************************************************* +* +* POINTER_GetPos +* +*******************************************************************************/ +/** +* +* Return the current position of the pointer (on the screen). +* +* @return The current pointer screen position with X in the LSB and Y in the MSB. +* +* @warning The (0x0) point in on the low left corner. +**/ +/******************************************************************************/ +u16 POINTER_GetPos( void ) + { + return ( POINTER_Info.xPos | ( POINTER_Info.yPos << 8 ) ); + } + +/******************************************************************************* +* +* POINTER_SetPos +* +*******************************************************************************/ +/** +* +* Force the screen position of the pointer. +* +* @param[in] x New horizontal coordinate. +* @param[in] y New vertical coordinate. +* +* @warning The (0x0) point in on the low left corner. +* +**/ +/******************************************************************************/ +void POINTER_SetPos( u16 x, u16 y ) + { + POINTER_Info.xPos = x; + POINTER_Info.yPos = y; + } + +/******************************************************************************* +* +* POINTER_Draw +* +*******************************************************************************/ +/** +* +* Draw pointer. +* +* @param[in] x Horizontal coordinate of the bottom left corner of the pointer. +* @param[in] y Vertical coordinate of the bottom left corner of the pointer. +* @param[in] width Pointer bitmap width. +* @param[in] height Pointer bitmap height. +* @param[in] bmp Pointer to width * height bit array. If null used default +* pointer bitmap. +* +* @note The provided bitmap is a monochrome one. +* @warning The (0x0) point in on the low left corner. +* +**/ +/******************************************************************************/ +void POINTER_Draw( u8 x, u8 y, u8 width, u8 height, u8* bmp ) + { + int i = 0; + int l = 0; + int n = 0; + char* ptr = ptrAreaStore; + char c; + u16 val; + + // No bitmap provided, use the default one! + if( bmp == 0 ) + { + bmp = BallPointerBmp; + } + + // Select the screen area were going to take care about! + LCD_SetRect_For_Cmd( x, y, width, height ); + + // Let draw to the LCD screen. + LCD_SendLCDCmd( ST7637_RAMWR ); + + while( n < ( width * height ) ) + { + if( Pointer_Mode != POINTER_RESTORE_LESS ) + { + // Draw pixel using current storage area data for background pixels. + c = *ptr++; + LCD_SendLCDData( ( bmp[ l + ( i / 8 ) ] & ( 1 << ( 7 - ( i % 8 ) ) ) ) ? ( POINTER_GetColor() & 255 ) : c ); + + c = *ptr++; + LCD_SendLCDData( ( bmp[ l + ( i / 8 ) ] & ( 1 << ( 7 - ( i % 8 ) ) ) ) ? ( POINTER_GetColor() >> 8 ) : c ); + } + else + { + // POINTER_RESTORE_LESS: use current background color for background color. + c = DRAW_GetBGndColor(); + val = ( bmp[ l + ( i / 8 ) ] & ( 1 << ( 7 - ( i % 8 ) ) ) ) ? POINTER_GetColor() : c; + + LCD_SendLCDData( val & 255 ); + LCD_SendLCDData( val >> 8 ); + } + + n++; + + i++; + + // End of line ? + if( i == width ) + { + // Next line! + l++; + i=0; + } + } + } + +/******************************************************************************* +* +* POINTER_Save +* +*******************************************************************************/ +/** +* +* Save the background of the pointer. +* +* @param[in] x Horizontal coordinate of the bottom left corner of the area to save. +* @param[in] y Vertical coordinate of the bottom left corner of the area to save. +* @param[in] width Width of the area to save. +* @param[in] height Height of the area to save. +* +* @note The store area must be large enough to store all the pixels (16 bits). +* @warning The (0x0) point in on the low left corner. +* @see POINTER_Restore +* @see POINTER_SetCurrentAreaStore +* +**/ +/******************************************************************************/ +void POINTER_Save( u8 x, u8 y, u8 width, u8 height ) + { + int i; + char* ptr = ptrAreaStore; + int bytesize = ( width * height ) * 2; // 2 bytes per pixel. + + // Is this pointer management mode, don't save pointer background! + if( Pointer_Mode == POINTER_RESTORE_LESS ) + { + return; + } + + // Select the LCD screen area to read. + LCD_SetRect_For_Cmd ( x, y, width, height ); + + // Send the memory read command to the LCD controller. + LCD_SendLCDCmd( ST7637_RAMRD ); + + // First returned byte is a dummy! + LCD_ReadLCDData(); + + for( i = 0; i < bytesize; i++ ) + { + *ptr++ = LCD_ReadLCDData(); + } + } + +/******************************************************************************* +* +* POINTER_Restore +* +*******************************************************************************/ +/** +* +* Restore the background of the pointer with data saved in the current store area. +* +* @param[in] x Horizontal coordinate of the bottom left corner of the area to restore. +* @param[in] y Vertical coordinate of the bottom left corner of the area to restore. +* @param[in] width Width of the area to restore. +* @param[in] height Height of the area to restore. +* +* @warning The (0x0) point in on the low left corner. +* @see POINTER_Save +* @see POINTER_SetCurrentAreaStore +* +**/ +/******************************************************************************/ +void POINTER_Restore( u8 x, u8 y, u8 width, u8 height ) + { + int i; + char* ptr = ptrAreaStore; + int bytesize = ( width * height ) * 2; // 2 bytes per pixel. + + // Select the screen area to write. + LCD_SetRect_For_Cmd( x, y, width, height ); + + // Send the memory write command to the LCD controller. + LCD_SendLCDCmd( ST7637_RAMWR ); + + for( i = 0; i < bytesize; i++ ) + { + // In this mode, use background color (no data was previously saved). + if ( Pointer_Mode == POINTER_RESTORE_LESS ) + { + LCD_SendLCDData( DRAW_GetBGndColor() ); + } + else + { + LCD_SendLCDData( *ptr++ ); + } + } + } + +/******************************************************************************* +* +* POINTER_SetApplication_Pointer_Mgr +* +*******************************************************************************/ +/** +* +* Provides an user defined pointer manager. +* +* @param[in] mgr Pointer to the user defined pointer manager. +* +**/ +/******************************************************************************/ +void POINTER_SetApplication_Pointer_Mgr( tAppPtrMgr mgr ) + { + Application_Pointer_Mgr = mgr; + } + +/******************************************************************************* +* +* POINTER_SetColor +* +*******************************************************************************/ +/** +* +* Set the pointer color. +* +* @param[in] color The new pointer color. +* +**/ +/******************************************************************************/ +void POINTER_SetColor( u16 color ) + { + CurrentPointerColor = color; + } + +/******************************************************************************* +* +* POINTER_GetColor +* +*******************************************************************************/ +/** +* +* Return the current pointer color. +* +* @return Current pointer color. +* +**/ +/******************************************************************************/ +u16 POINTER_GetColor( void ) + { + return CurrentPointerColor; + } + +/******************************************************************************* +* +* POINTER_GetInfo +* +*******************************************************************************/ +/** +* +* Get pointer informations. +* +* @return A pointer to a pointer information structure. +* +**/ +/******************************************************************************/ +tPointer_Info* POINTER_GetInfo( void ) + { + return &POINTER_Info; + } diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/scheduler.h b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/scheduler.h new file mode 100644 index 000000000..11c7e67fa --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/scheduler.h @@ -0,0 +1,81 @@ +/********************* (C) COPYRIGHT 2007 RAISONANCE S.A.S. *******************/ +/** +* +* @file scheduler.h +* @brief Header file for the SysTick interrupt handler of the CircleOS project. +* @author FL +* @author IB +* @date 07/2007 +* +**/ +/******************************************************************************/ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F10x_IT_H +#define __STM32F10x_IT_H + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f10x_lib.h" + +void NMIException( void ); +void HardFaultException( void ); +void MemManageException( void ); +void BusFaultException( void ); +void UsageFaultException( void ); +void DebugMonitor( void ); +void SVCHandler( void ); +void PendSVC( void ); +void SysTickHandler( void ); +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 DMAChannel1_IRQHandler( void ); +void DMAChannel2_IRQHandler( void ); +void DMAChannel3_IRQHandler( void ); +void DMAChannel4_IRQHandler( void ); +void DMAChannel5_IRQHandler( void ); +void DMAChannel6_IRQHandler( void ); +void DMAChannel7_IRQHandler( void ); +void ADC_IRQHandler( void ); +void USB_HP_CAN_TX_IRQHandler( void ); +void USB_LP_CAN_RX0_IRQHandler( void ); +void CAN_RX1_IRQHandler( void ); +void CAN_SCE_IRQHandler( void ); +void EXTI9_5_IRQHandler( void ); +void TIM1_BRK_IRQHandler( void ); +void TIM1_UP_IRQHandler( void ); +void TIM1_TRG_CCUP_IRQHandler( void ); +void TIM1_CC_IRQHandler( void ); +void TIM2_IRQHandler( void ); +void TIM3_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 ); + +//FL071107 Make the scheduler configurable. The handler are inserted into a list that could +//be modified by the applications. +typedef void (*tHandler) ( void ); +extern tHandler SchHandler [16+1]; +#define SCH_HDL_MAX ( sizeof SchHandler / sizeof (tHandler) ) + + + +#endif /* __STM32F10x_IT_H */ diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/stm32f10x_circle_it.c b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/stm32f10x_circle_it.c new file mode 100644 index 000000000..a656d685f --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/stm32f10x_circle_it.c @@ -0,0 +1,217 @@ +/********************* (C) COPYRIGHT 2007 RAISONANCE S.A.S. *******************/ +/** +* +* @file stm32f10x_circle_it.c +* @brief Interrupt handler for the CircleOS project. +* @author FL +* @author IB +* @date 07/2007 +* +**/ +/******************************************************************************/ + +/* Includes ------------------------------------------------------------------*/ +#include "circle.h" + +/* External variables --------------------------------------------------------*/ +extern u16 CCR_Val; +extern u16 Current_CCR_BackLightStart; + +/******************************************************************************* +* +* NMIException +* +*******************************************************************************/ +/** +* +* Handles the NMI exception. +* +**/ +/******************************************************************************/ +void NMIException( void ) {} + +/******************************************************************************* +* +* HardFaultException +* +*******************************************************************************/ +/** +* +* Handles the Hard Fault exception. +* +**/ +/******************************************************************************/ +void HardFaultException( void ) + { + #ifdef TIMING_ANALYSIS //to debug with a scope + GPIO_WriteBit( GPIOA, GPIO_Pin_5, Bit_RESET ); + GPIO_WriteBit( GPIOA, GPIO_Pin_5, Bit_SET ); + #endif + } + +/******************************************************************************* +* +* MemManageException +* +*******************************************************************************/ +/** +* +* Handles the Memory Manage exception. +* +**/ +/******************************************************************************/ +void MemManageException( void ) {} + +/******************************************************************************* +* +* BusFaultException +* +*******************************************************************************/ +/** +* +* Handles the Bus Fault exception. +* +**/ +/******************************************************************************/ +void BusFaultException( void ) {} + +/******************************************************************************* +* +* UsageFaultException +* +*******************************************************************************/ +/** +* +* Handles the Usage Fault exception. +* +**/ +/******************************************************************************/ +void UsageFaultException( void ) {} + +/******************************************************************************* +* +* DebugMonitor +* +*******************************************************************************/ +/** +* +* Handles the Debug Monitor exception. +* +**/ +/******************************************************************************/ +void DebugMonitor( void ) {} + +/******************************************************************************* +* +* SVCHandler +* +*******************************************************************************/ +/** +* +* Handles the SVCall exception. +* +**/ +/******************************************************************************/ +void SVCHandler( void ) {} + +/******************************************************************************* +* +* PendSVC +* +*******************************************************************************/ +/** +* +* Handles the PendSVC exception. +* +**/ +/******************************************************************************/ +void PendSVC( void ) {} + +/******************************************************************************* +* +* DummyHandler +* +*******************************************************************************/ +/** +* +* Default handling for the IRQ-Exception +* +**/ +/******************************************************************************/ +void DummyHandler ( void ) {} + +/******************************************************************************* +* +* TIM2_IRQHandler +* +*******************************************************************************/ +/** +* +* Handles the TIM2 global interrupt request. +* +**/ +/******************************************************************************/ +void TIM2_IRQHandler( void ) + { + #ifdef TIMING_ANALYSIS //to debug with a scope + GPIO_WriteBit( GPIOA, GPIO_Pin_7, Bit_RESET ); + #endif + + /* Clear TIM2 update interrupt */ + TIM_ClearITPendingBit( TIM2, TIM_IT_Update ); + + MEMS_Handler(); + + #ifdef TIMING_ANALYSIS //to debug with a scope + GPIO_WriteBit( GPIOA, GPIO_Pin_7, Bit_SET ); + #endif + } + +/******************************************************************************* +* +* TIM3_IRQHandler +* +*******************************************************************************/ +/** +* +* Handles the TIM3 global interrupt request. +* +**/ +/******************************************************************************/ +void TIM3_IRQHandler( void ) +{ + u16 capture = 0; + + if( TIM_GetITStatus( TIM3, TIM_IT_CC3 ) != RESET ) + { + capture = TIM_GetCapture3( TIM3 ); + + TIM_SetCompare3( TIM3, capture + CCR_Val + 1 ); + TIM_ClearITPendingBit( TIM3, TIM_IT_CC3 ); + } +} + +/******************************************************************************* +* +* TIM4_IRQHandler +* +*******************************************************************************/ +/** +* +* Handles the TIM4 global interrupt request. +* +**/ +/******************************************************************************/ +void TIM4_IRQHandler( void ) +{ + u16 BackLight_capture = 0; + + if( TIM_GetITStatus( TIM4, TIM_IT_CC2 ) != RESET ) + { + BackLight_capture = TIM_GetCapture2( TIM4 ); + + TIM_SetCompare2( TIM4, BackLight_capture + Current_CCR_BackLightStart + 1 ); + TIM_ClearITPendingBit( TIM4, TIM_IT_CC2 ); + } +} + diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/stm32f10x_conf.h b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/stm32f10x_conf.h new file mode 100644 index 000000000..27234fc73 --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/stm32f10x_conf.h @@ -0,0 +1,119 @@ +/******************** (C) COPYRIGHT 2007 STMicroelectronics ******************** +* File Name : stm32f10x_conf.h +* Author : MCD Application Team +* Date First Issued : 09/29/2006 +* Description : Library configuration file. +******************************************************************************** +* History: +* 02/05/2007: V0.1 +* 09/29/2006: V0.01 +******************************************************************************** +* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS +* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. +* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, +* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE +* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING +* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. +*******************************************************************************/ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F10x_CONF_H +#define __STM32F10x_CONF_H + +/* Includes ------------------------------------------------------------------*/ +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +/* Comment the line below to compile the library in release mode */ +//#define DEBUG 0 + +/* Comment the line below to disable the specific peripheral inclusion */ +/************************************* ADC ************************************/ +//#define _ADC +#define _ADC1 +#define _ADC2 + +/************************************* CAN ************************************/ +//#define _CAN + +/************************************* DMA ************************************/ +//#define _DMA +#define _DMA_Channel1 +#define _DMA_Channel2 +#define _DMA_Channel3 +#define _DMA_Channel4 +#define _DMA_Channel5 +#define _DMA_Channel6 +#define _DMA_Channel7 + +/************************************* EXTI ***********************************/ +//#define _EXTI + +/************************************* GPIO ***********************************/ +#define _GPIO +#define _GPIOA +#define _GPIOB +#define _GPIOC +#define _GPIOD +//#define _GPIOE +#define _AFIO + +/************************************* I2C ************************************/ +//#define _I2C +//#define _I2C1 +//#define _I2C2 + +/************************************* IWDG ***********************************/ +//#define _IWDG + +/************************************* NVIC ***********************************/ +#define _NVIC +#define _SCB + +/************************************* BKP ************************************/ +//#define _BKP + +/************************************* PWR ************************************/ +//#define _PWR + +/************************************* RCC ************************************/ +#define _RCC + +/************************************* RTC ************************************/ +//#define _RTC + +/************************************* SPI ************************************/ +#define _SPI +//#define _SPI1 +#define _SPI2 + +/************************************* SysTick ********************************/ +#define _SysTick + +/************************************* TIM1 ***********************************/ +//#define _TIM1 + +/************************************* TIM ************************************/ +#define _TIM +#define _TIM2 +#define _TIM3 +#define _TIM4 + +/************************************* USART **********************************/ +//#define _USART +//#define _USART1 +//#define _USART2 +//#define _USART3 + +/************************************* WWDG ***********************************/ +//#define _WWDG + +/* In the following line adjust the value of External High Speed oscillator (HSE) + used in your application */ +#define HSE_Value ((u32)12000000) /* Value of the External oscillator in Hz*/ + +/* Exported macro ------------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------- */ + +#endif /* __STM32F10x_CONF_H */ + +/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/ diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/stm32f10x_it.h b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/stm32f10x_it.h new file mode 100644 index 000000000..9fa5322b4 --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/stm32f10x_it.h @@ -0,0 +1,70 @@ +/********************* (C) COPYRIGHT 2007 RAISONANCE S.A.S. ******************** +* File Name : stm32f10x_it.c +* Author : IB/FL +* Date First Issued : 07/2007 +* Description : Interrupt handler for the CircleOS project. +* Revision : +*******************************************************************************/ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F10x_IT_H +#define __STM32F10x_IT_H + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f10x_lib.h" + +/* Exported functions ------------------------------------------------------- */ +void NMIException( void ); +void HardFaultException( void ); +void MemManageException( void ); +void BusFaultException( void ); +void UsageFaultException( void ); +void DebugMonitor( void ); +void SVCHandler( void ); +void PendSVC( void ); +void SysTickHandler( void ); +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 DMAChannel1_IRQHandler( void ); +void DMAChannel2_IRQHandler( void ); +void DMAChannel3_IRQHandler( void ); +void DMAChannel4_IRQHandler( void ); +void DMAChannel5_IRQHandler( void ); +void DMAChannel6_IRQHandler( void ); +void DMAChannel7_IRQHandler( void ); +void ADC_IRQHandler( void ); +void USB_HP_CAN_TX_IRQHandler( void ); +void USB_LP_CAN_RX0_IRQHandler( void ); +void CAN_RX1_IRQHandler( void ); +void CAN_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 TIM2_IRQHandler( void ); +void TIM3_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 ); + +#endif /* __STM32F10x_IT_H */ diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/stm32f10x_tim.c b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/stm32f10x_tim.c new file mode 100644 index 000000000..5fd374eb9 --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/ST_Code/stm32f10x_tim.c @@ -0,0 +1,2348 @@ +/******************** (C) COPYRIGHT 2007 STMicroelectronics ******************** +* File Name : stm32f10x_tim.c +* Author : MCD Application Team +* Date First Issued : 09/29/2006 +* Description : This file provides all the TIM firmware functions. +******************************************************************************** +* History: +* 04/02/2007: V0.2 +* 02/05/2007: V0.1 +* 09/29/2006: V0.01 +******************************************************************************** +* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS +* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. +* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, +* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE +* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING +* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. +*******************************************************************************/ + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f10x_tim.h" +#include "stm32f10x_rcc.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* ---------------------- TIM registers bit mask ------------------------ */ +#define CR1_CEN_Set ((u16)0x0001) +#define CR1_CEN_Reset ((u16)0x03FE) +#define CR1_UDIS_Set ((u16)0x0002) +#define CR1_UDIS_Reset ((u16)0x03FD) +#define CR1_URS_Set ((u16)0x0004) +#define CR1_URS_Reset ((u16)0x03FB) +#define CR1_OPM_Mask ((u16)0x03F7) +#define CR1_CounterMode_Mask ((u16)0x039F) +#define CR1_ARPE_Set ((u16)0x0080) +#define CR1_ARPE_Reset ((u16)0x037F) +#define CR1_CKD_Mask ((u16)0x00FF) + +#define CR2_CCDS_Set ((u16)0x0008) +#define CR2_CCDS_Reset ((u16)0x0007) +#define CR2_MMS_Mask ((u16)0x0080) +#define CR2_TI1S_Set ((u16)0x0080) +#define CR2_TI1S_Reset ((u16)0xFF70) + +#define SMCR_SMS_Mask ((u16)0xFFF0) +#define SMCR_ETR_Mask ((u16)0x00F7) +#define SMCR_TS_Mask ((u16)0xFF87) +#define SMCR_MSM_Mask ((u16)0xFF77) +#define SMCR_ECE_Set ((u16)0x4000) + +#define CCMR_CC13S_Mask ((u16)0x7F7C) +#define CCMR_CC24S_Mask ((u16)0x7C7F) +#define CCMR_TI13Direct_Set ((u16)0x0001) +#define CCMR_TI24Direct_Set ((u16)0x0100) +#define CCMR_OC13FE_Mask ((u16)0x7F7B) +#define CCMR_OC24FE_Mask ((u16)0x7B7F) +#define CCMR_OC13PE_Mask ((u16)0x7F77) +#define CCMR_OC24PE_Mask ((u16)0x777F) +#define CCMR_OCM13_Mask ((u16)0x7F0F) +#define CCMR_OCM24_Mask ((u16)0x0F7F) +#define CCMR_IC13PSC_Mask ((u16)0xFFF3) +#define CCMR_IC24PSC_Mask ((u16)0xF3FF) +#define CCMR_IC13F_Mask ((u16)0xFF0F) +#define CCMR_IC24F_Mask ((u16)0x0FFF) +#define CCER_CC1P_Mask ((u16)0xFFFD) + +#define CCER_CC2P_Mask ((u16)0xFFDF) +#define CCER_CC3P_Mask ((u16)0xFDFF) +#define CCER_CC4P_Mask ((u16)0xDFFF) + +#define CCRE_CC1E_Set ((u16)0x0001) +#define CCRE_CC1E_Reset ((u16)0xFFFE) +#define CCRE_CC1E_Mask ((u16)0xFFFE) + +#define CCRE_CC2E_Set ((u16)0x0010) +#define CCRE_CC2E_Reset ((u16)0xFFEF) +#define CCRE_CC2E_Mask ((u16)0xFFEF) + +#define CCRE_CC3E_Set ((u16)0x0100) +#define CCRE_CC3E_Reset ((u16)0xFEFF) + +#define CCRE_CC4E_Set ((u16)0x1000) +#define CCRE_CC4E_Reset ((u16)0xEFFF) +#define CCRE_CC4E_Mask ((u16)0xEFFF) + +#define DCR_DMA_Mask ((u16)0x0000) + +/* TIM private Masks */ +#define TIM_Period_Reset_Mask ((u16)0x0000) +#define TIM_Prescaler_Reset_Mask ((u16)0x0000) +#define TIM_Pulse_Reset_Mask ((u16)0x0000) +#define TIM_ICFilter_Mask ((u8)0x00) + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +static uc16 Tab_OCModeMask[4] = {0xFF00, 0x00FF, 0xFF00, 0x00FF}; +static uc16 Tab_PolarityMask[4] = {CCER_CC1P_Mask, CCER_CC2P_Mask, CCER_CC3P_Mask, CCER_CC4P_Mask}; + +/* Private function prototypes -----------------------------------------------*/ +static void PWMI_Config(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct); +static void TI1_Config(TIM_TypeDef* TIMx, u16 TIM_ICPolarity, u16 TIM_ICSelection, + u8 TIM_ICFilter); +static void TI2_Config(TIM_TypeDef* TIMx, u16 TIM_ICPolarity, u16 TIM_ICSelection, + u8 TIM_ICFilter); +static void TI3_Config(TIM_TypeDef* TIMx, u16 TIM_ICPolarity, u16 TIM_ICSelection, + u8 TIM_ICFilter); +static void TI4_Config(TIM_TypeDef* TIMx, u16 TIM_ICPolarity, u16 TIM_ICSelection, + u8 TIM_ICFilter); +static void ETR_Config(TIM_TypeDef* TIMx, u16 TIM_ExtTRGPrescaler, + u16 TIM_ExtTRGPolarity, u8 ExtTRGFilter); +/* Private functions ---------------------------------------------------------*/ + +/******************************************************************************* +* Function Name : TIM_DeInit +* Description : Deinitializes the TIMx peripheral registers to their default +* reset values. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_DeInit(TIM_TypeDef* TIMx) +{ + switch (*(u32*)&TIMx) + { + case TIM2_BASE: + RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, ENABLE); + RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, DISABLE); + break; + + case TIM3_BASE: + RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, ENABLE); + RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, DISABLE); + break; + + case TIM4_BASE: + RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM4, ENABLE); + RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM4, DISABLE); + break; + + default: + break; + } +} + +/******************************************************************************* +* Function Name : TIM_TimeBaseInit +* Description : Initializes the TIMx Time Base Unit peripheral according to +* the specified parameters in the TIM_TimeBaseInitStruct. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_TimeBaseInitStruct: pointer to a TIM_TimeBaseInitTypeDef +* structure that contains the configuration information for +* the specified TIM peripheral. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_TimeBaseInit(TIM_TypeDef* TIMx, TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct) +{ + /* Check the parameters */ + assert(IS_TIM_COUNTER_MODE(TIM_TimeBaseInitStruct->TIM_CounterMode)); + assert(IS_TIM_CKD_DIV(TIM_TimeBaseInitStruct->TIM_ClockDivision)); + + /* Set the Autoreload value */ + TIMx->ARR = TIM_TimeBaseInitStruct->TIM_Period ; + + /* Set the Prescaler value */ + TIMx->PSC = TIM_TimeBaseInitStruct->TIM_Prescaler; + + /* Select the Counter Mode and set the clock division */ + TIMx->CR1 &= CR1_CKD_Mask & CR1_CounterMode_Mask; + TIMx->CR1 |= (u32)TIM_TimeBaseInitStruct->TIM_ClockDivision | + TIM_TimeBaseInitStruct->TIM_CounterMode; +} +/******************************************************************************* +* Function Name : TIM_OCInit +* Description : Initializes the TIMx peripheral according to the specified +* parameters in the TIM_OCInitStruct. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure +* that contains the configuration information for the specified +* TIM peripheral. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_OCInit(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct) +{ + u32 tmpccmrx = 0, tmpccer = 0; + + /* Check the parameters */ + assert(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode)); + assert(IS_TIM_CHANNEL(TIM_OCInitStruct->TIM_Channel)); + assert(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity)); + + tmpccer = TIMx->CCER; + + if ((TIM_OCInitStruct->TIM_Channel == (u16)TIM_Channel_1) || + (TIM_OCInitStruct->TIM_Channel == (u16)TIM_Channel_2)) + { + tmpccmrx = TIMx->CCMR1; + + /* Reset the Output Compare Bits */ + tmpccmrx &= Tab_OCModeMask[TIM_OCInitStruct->TIM_Channel]; + + /* Set the Output Polarity level */ + tmpccer &= Tab_PolarityMask[TIM_OCInitStruct->TIM_Channel]; + + if (TIM_OCInitStruct->TIM_Channel == TIM_Channel_1) + { + /* Disable the Channel 1: Reset the CCE Bit */ + TIMx->CCER &= CCRE_CC1E_Reset; + + /* Select the Output Compare Mode */ + tmpccmrx |= TIM_OCInitStruct->TIM_OCMode; + + /* Set the Capture Compare Register value */ + TIMx->CCR1 = TIM_OCInitStruct->TIM_Pulse; + + /* Set the Capture Compare Enable Bit */ + tmpccer |= CCRE_CC1E_Set; + + /* Set the Capture Compare Polarity */ + tmpccer |= TIM_OCInitStruct->TIM_OCPolarity; + } + else /* TIM_Channel_2 */ + { + /* Disable the Channel 2: Reset the CCE Bit */ + TIMx->CCER &= CCRE_CC2E_Reset; + + /* Select the Output Compare Mode */ + tmpccmrx |= (u32)TIM_OCInitStruct->TIM_OCMode << 8; + + /* Set the Capture Compare Register value */ + TIMx->CCR2 = TIM_OCInitStruct->TIM_Pulse; + + /* Set the Capture Compare Enable Bit */ + tmpccer |= CCRE_CC2E_Set; + + /* Set the Capture Compare Polarity */ + tmpccer |= (u32)TIM_OCInitStruct->TIM_OCPolarity << 4; + } + + TIMx->CCMR1 = (u16)tmpccmrx; + } + else + { + if ((TIM_OCInitStruct->TIM_Channel == TIM_Channel_3) || + (TIM_OCInitStruct->TIM_Channel == TIM_Channel_4)) + { + tmpccmrx = TIMx->CCMR2; + + /* Reset the Output Compare Bits */ + tmpccmrx &= Tab_OCModeMask[TIM_OCInitStruct->TIM_Channel]; + + /* Set the Output Polarity level */ + tmpccer &= Tab_PolarityMask[TIM_OCInitStruct->TIM_Channel]; + + if (TIM_OCInitStruct->TIM_Channel == TIM_Channel_3) + { + /* Disable the Channel 3: Reset the CCE Bit */ + TIMx->CCER &= CCRE_CC3E_Reset; + + /* Select the Output Compare Mode */ + tmpccmrx |= TIM_OCInitStruct->TIM_OCMode; + + /* Set the Capture Compare Register value */ + TIMx->CCR3 = TIM_OCInitStruct->TIM_Pulse; + + /* Set the Capture Compare Enable Bit */ + tmpccer |= CCRE_CC3E_Set; + + /* Set the Capture Compare Polarity */ + tmpccer |= (u32)TIM_OCInitStruct->TIM_OCPolarity << 8; + } + else /* TIM_Channel_4 */ + { + /* Disable the Channel 4: Reset the CCE Bit */ + TIMx->CCER &= CCRE_CC4E_Reset; + + /* Select the Output Compare Mode */ + tmpccmrx |= (u32)TIM_OCInitStruct->TIM_OCMode << 8; + + /* Set the Capture Compare Register value */ + TIMx->CCR4 = TIM_OCInitStruct->TIM_Pulse; + + /* Set the Capture Compare Enable Bit */ + tmpccer |= CCRE_CC4E_Set; + + /* Set the Capture Compare Polarity */ + tmpccer |= (u32)TIM_OCInitStruct->TIM_OCPolarity << 12; + } + + TIMx->CCMR2 = (u16)tmpccmrx; + } + } + + TIMx->CCER = (u16)tmpccer; +} + +/******************************************************************************* +* Function Name : TIM_ICInit +* Description : Initializes the TIMx peripheral according to the specified +* parameters in the TIM_ICInitStruct. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure +* that contains the configuration information for the specified +* TIM peripheral. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_ICInit(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct) +{ + /* Check the parameters */ + assert(IS_TIM_IC_MODE(TIM_ICInitStruct->TIM_ICMode)); + assert(IS_TIM_CHANNEL(TIM_ICInitStruct->TIM_Channel)); + assert(IS_TIM_IC_POLARITY(TIM_ICInitStruct->TIM_ICPolarity)); + assert(IS_TIM_IC_SELECTION(TIM_ICInitStruct->TIM_ICSelection)); + assert(IS_TIM_IC_PRESCALER(TIM_ICInitStruct->TIM_ICPrescaler)); + assert(IS_TIM_IC_FILTER(TIM_ICInitStruct->TIM_ICFilter)); + + if (TIM_ICInitStruct->TIM_ICMode == TIM_ICMode_ICAP) + { + if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_1) + { + /* TI1 Configuration */ + TI1_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, + TIM_ICInitStruct->TIM_ICSelection, + TIM_ICInitStruct->TIM_ICFilter); + + /* Set the Input Capture Prescaler value */ + TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler); + } + else if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_2) + { + /* TI2 Configuration */ + TI2_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, + TIM_ICInitStruct->TIM_ICSelection, + TIM_ICInitStruct->TIM_ICFilter); + + /* Set the Input Capture Prescaler value */ + TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler); + } + else if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_3) + { + /* TI3 Configuration */ + TI3_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, + TIM_ICInitStruct->TIM_ICSelection, + TIM_ICInitStruct->TIM_ICFilter); + + /* Set the Input Capture Prescaler value */ + TIM_SetIC3Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler); + } + else /* TIM_Channel_4 */ + { + /* TI4 Configuration */ + TI4_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, + TIM_ICInitStruct->TIM_ICSelection, + TIM_ICInitStruct->TIM_ICFilter); + + /* Set the Input Capture Prescaler value */ + TIM_SetIC4Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler); + } + } + else + { + PWMI_Config(TIMx, TIM_ICInitStruct); + } +} + +/******************************************************************************* +* Function Name : TIM_TimeBaseStructInit +* Description : Fills each TIM_TimeBaseInitStruct member with its default value. +* Input : - TIM_TimeBaseInitStruct: pointer to a TIM_TimeBaseInitTypeDef +* structure which will be initialized. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_TimeBaseStructInit(TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct) +{ + /* Set the default configuration */ + TIM_TimeBaseInitStruct->TIM_Period = TIM_Period_Reset_Mask; + TIM_TimeBaseInitStruct->TIM_Prescaler = TIM_Prescaler_Reset_Mask; + TIM_TimeBaseInitStruct->TIM_ClockDivision = TIM_CKD_DIV1; + TIM_TimeBaseInitStruct->TIM_CounterMode = TIM_CounterMode_Up; +} + +/******************************************************************************* +* Function Name : TIM_OCStructInit +* Description : Fills each TIM_OCInitStruct member with its default value. +* Input : - TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure +* which will be initialized. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_OCStructInit(TIM_OCInitTypeDef* TIM_OCInitStruct) +{ + /* Set the default configuration */ + TIM_OCInitStruct->TIM_OCMode = TIM_OCMode_Timing; + TIM_OCInitStruct->TIM_Channel = TIM_Channel_1; + TIM_OCInitStruct->TIM_Pulse = TIM_Pulse_Reset_Mask; + TIM_OCInitStruct->TIM_OCPolarity = TIM_OCPolarity_High; +} + +/******************************************************************************* +* Function Name : TIM_ICStructInit +* Description : Fills each TIM_InitStruct member with its default value. +* Input : - TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure +* which will be initialized. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_ICStructInit(TIM_ICInitTypeDef* TIM_ICInitStruct) +{ + /* Set the default configuration */ + TIM_ICInitStruct->TIM_ICMode = TIM_ICMode_ICAP; + TIM_ICInitStruct->TIM_Channel = TIM_Channel_1; + TIM_ICInitStruct->TIM_ICPolarity = TIM_ICPolarity_Rising; + TIM_ICInitStruct->TIM_ICSelection = TIM_ICSelection_DirectTI; + TIM_ICInitStruct->TIM_ICPrescaler = TIM_ICPSC_DIV1; + TIM_ICInitStruct->TIM_ICFilter = TIM_ICFilter_Mask; +} + +/******************************************************************************* +* Function Name : TIM_Cmd +* Description : Enables or disables the specified TIM peripheral. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIMx peripheral. +* - Newstate: new state of the TIMx peripheral. +* This parameter can be: ENABLE or DISABLE. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_Cmd(TIM_TypeDef* TIMx, FunctionalState NewState) +{ + /* Check the parameters */ + assert(IS_FUNCTIONAL_STATE(NewState)); + + if (NewState != DISABLE) + { + /* Enable the TIM Counter */ + TIMx->CR1 |= CR1_CEN_Set; + } + else + { + /* Disable the TIM Counter */ + TIMx->CR1 &= CR1_CEN_Reset; + } +} + +/******************************************************************************* +* Function Name : TIM_ITConfig +* Description : Enables or disables the TIMx interrupts. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_IT: specifies the TIM interrupts sources to be enabled +* or disabled. +* This parameter can be any combination of the following values: +* - TIM_IT_Update: Timer update Interrupt +* - TIM_IT_CC1: Capture Compare 1 Interrupt +* - TIM_IT_CC2: Capture Compare 2 Interrupt +* - TIM_IT_CC3: Capture Compare 3 Interrupt +* - TIM_IT_CC4: Capture Compare 4 Interrupt +* - TIM_IT_Trigger: Trigger Interrupt +* - Newstate: new state of the specified TIMx interrupts. +* This parameter can be: ENABLE or DISABLE. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_ITConfig(TIM_TypeDef* TIMx, u16 TIM_IT, FunctionalState NewState) +{ + /* Check the parameters */ + assert(IS_TIM_IT(TIM_IT)); + assert(IS_FUNCTIONAL_STATE(NewState)); + + if (NewState != DISABLE) + { + /* Enable the Interrupt sources */ + TIMx->DIER |= TIM_IT; + } + else + { + /* Disable the Interrupt sources */ + TIMx->DIER &= (u16)(~TIM_IT); + } +} + +/******************************************************************************* +* Function Name : TIM_DMAConfig +* Description : Configures the TIMxÂ’s DMA interface. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_DMABase: DMA Base address. +* This parameter can be one of the following values: +* - TIM_DMABase_CR1, TIM_DMABase_CR2, TIM_DMABase_SMCR, +* TIM_DMABase_DIER, TIM_DMABase_SR, TIM_DMABase_EGR, +* TIM_DMABase_CCMR1, TIM_DMABase_CCMR2, TIM_DMABase_CCER, +* TIM_DMABase_CNT, TIM_DMABase_PSC, TIM_DMABase_ARR, +* TIM_DMABase_CCR1, TIM_DMABase_CCR2, TIM_DMABase_CCR3, +* TIM_DMABase_CCR4, TIM_DMABase_DCR. +* - TIM_DMABurstLength: DMA Burst length. +* This parameter can be one value between: +* TIM_DMABurstLength_1Byte and TIM_DMABurstLength_18Bytes. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_DMAConfig(TIM_TypeDef* TIMx, u16 TIM_DMABase, u16 TIM_DMABurstLength) +{ + u32 tmpdcr = 0; + + /* Check the parameters */ + assert(IS_TIM_DMA_BASE(TIM_DMABase)); + assert(IS_TIM_DMA_LENGTH(TIM_DMABurstLength)); + + tmpdcr = TIMx->DCR; + + /* Reset the DBA and the DBL Bits */ + tmpdcr &= DCR_DMA_Mask; + + /* Set the DMA Base and the DMA Burst Length */ + tmpdcr |= TIM_DMABase | TIM_DMABurstLength; + + TIMx->DCR = (u16)tmpdcr; +} + +/******************************************************************************* +* Function Name : TIM_DMACmd +* Description : Enables or disables the TIMxÂ’s DMA Requests. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_DMASources: specifies the DMA Request sources. +* This parameter can be any combination of the following values: +* - TIM_DMA_CC1: Capture Compare 1 DMA source +* - TIM_DMA_CC2: Capture Compare 2 DMA source +* - TIM_DMA_CC3: Capture Compare 3 DMA source +* - TIM_DMA_CC4: Capture Compare 4 DMA source +* - TIM_DMA_Trigger: Trigger DMA source +* - Newstate: new state of the DMA Request sources. +* This parameter can be: ENABLE or DISABLE. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_DMACmd(TIM_TypeDef* TIMx, u16 TIM_DMASource, FunctionalState Newstate) +{ + u32 tmpdier = 0; + + /* Check the parameters */ + assert(IS_TIM_DMA_SOURCE(TIM_DMASource)); + assert(IS_FUNCTIONAL_STATE(Newstate)); + + tmpdier = TIMx->DIER; + + if (Newstate != DISABLE) + { + /* Enable the DMA sources */ + tmpdier |= TIM_DMASource; + } + else + { + /* Disable the DMA sources */ + tmpdier &= (u16)(~TIM_DMASource); + } + TIMx->DIER = (u16)tmpdier; +} + +/******************************************************************************* +* Function Name : TIM_InternalClockConfig +* Description : Configures the TIMx interrnal Clock +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_InternalClockConfig(TIM_TypeDef* TIMx) +{ + /* Disable slave mode to clock the prescaler directly with the internal clock */ + TIMx->SMCR &= SMCR_SMS_Mask; +} +/******************************************************************************* +* Function Name : TIM_ITRxExternalClockConfig +* Description : Configures the TIMx Internal Trigger as External Clock +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_ITRSource: Trigger source. +* This parameter can be one of the following values: +* - TIM_TS_ITR0: Internal Trigger 0 +* - TIM_TS_ITR1: Internal Trigger 1 +* - TIM_TS_ITR2: Internal Trigger 2 +* - TIM_TS_ITR3: Internal Trigger 3 +* Output : None +* Return : None +*******************************************************************************/ +void TIM_ITRxExternalClockConfig(TIM_TypeDef* TIMx, u16 TIM_InputTriggerSource) +{ + /* Check the parameters */ + assert(IS_TIM_INTERNAL_TRIGGER_SELECTION(TIM_InputTriggerSource)); + + /* Select the Internal Trigger */ + TIM_SelectInputTrigger(TIMx, TIM_InputTriggerSource); + + /* Select the External clock mode1 */ + TIMx->SMCR |= TIM_SlaveMode_External1; +} +/******************************************************************************* +* Function Name : TIM_TIxExternalClockConfig +* Description : Configures the TIMx Trigger as External Clock +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_TIxExternalCLKSource: Trigger source. +* This parameter can be one of the following values: +* - TIM_TS_TI1F_ED: TI1 Edge Detector +* - TIM_TS_TI1FP1: Filtered Timer Input 1 +* - TIM_TS_TI2FP2: Filtered Timer Input 2 +* - TIM_ICPolarity: specifies the TIx Polarity. +* This parameter can be: +* - TIM_ICPolarity_Rising +* - TIM_ICPolarity_Falling +* - ICFilter : specifies the filter value. +* This parameter must be a value between 0x0 and 0xF. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_TIxExternalClockConfig(TIM_TypeDef* TIMx, u16 TIM_TIxExternalCLKSource, + u16 TIM_ICPolarity, u8 ICFilter) +{ + /* Check the parameters */ + assert(IS_TIM_TIX_TRIGGER_SELECTION(TIM_TIxExternalCLKSource)); + assert(IS_TIM_IC_POLARITY(TIM_ICPolarity)); + assert(IS_TIM_IC_FILTER(ICFilter)); + + /* Configure the Timer Input Clock Source */ + if (TIM_TIxExternalCLKSource == TIM_TIxExternalCLK1Source_TI2) + { + TI2_Config(TIMx, TIM_ICPolarity, TIM_ICSelection_DirectTI, ICFilter); + } + else + { + TI1_Config(TIMx, TIM_ICPolarity, TIM_ICSelection_DirectTI, ICFilter); + } + + /* Select the Trigger source */ + TIM_SelectInputTrigger(TIMx, TIM_TIxExternalCLKSource); + + /* Select the External clock mode1 */ + TIMx->SMCR |= TIM_SlaveMode_External1; +} + +/******************************************************************************* +* Function Name : TIM_ETRClockMode1Config +* Description : Configures the External clock Mode1 +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_ExtTRGPrescaler: The external Trigger Prescaler. +* It can be one of the following values: +* - TIM_ExtTRGPSC_OFF +* - TIM_ExtTRGPSC_DIV2 +* - TIM_ExtTRGPSC_DIV4 +* - TIM_ExtTRGPSC_DIV8. +* - TIM_ExtTRGPolarity: The external Trigger Polarity. +* It can be one of the following values: +* - TIM_ExtTRGPolarity_Inverted +* - TIM_ExtTRGPolarity_NonInverted +* - ExtTRGFilter: External Trigger Filter. +* This parameter must be a value between 0x00 and 0x0F +* Output : None +* Return : None +*******************************************************************************/ +void TIM_ETRClockMode1Config(TIM_TypeDef* TIMx, u16 TIM_ExtTRGPrescaler, u16 TIM_ExtTRGPolarity, + u8 ExtTRGFilter) +{ + /* Check the parameters */ + assert(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler)); + assert(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity)); + + /* Configure the ETR Clock source */ + ETR_Config(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter); + + /* Select the External clock mode1 */ + TIMx->SMCR &= SMCR_SMS_Mask; + TIMx->SMCR |= TIM_SlaveMode_External1; + + /* Select the Trigger selection : ETRF */ + TIMx->SMCR &= SMCR_TS_Mask; + TIMx->SMCR |= TIM_TS_ETRF; +} + +/******************************************************************************* +* Function Name : TIM_ETRClockMode2Config +* Description : Configures the External clock Mode2 +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_ExtTRGPrescaler: The external Trigger Prescaler. +* It can be one of the following values: +* - TIM_ExtTRGPSC_OFF +* - TIM_ExtTRGPSC_DIV2 +* - TIM_ExtTRGPSC_DIV4 +* - TIM_ExtTRGPSC_DIV8 +* - TIM_ExtTRGPolarity: The external Trigger Polarity. +* It can be one of the following values: +* - TIM_ExtTRGPolarity_Inverted +* - TIM_ExtTRGPolarity_NonInverted +* - ExtTRGFilter: External Trigger Filter. +* This parameter must be a value between 0x00 and 0x0F +* Output : None +* Return : None +*******************************************************************************/ +void TIM_ETRClockMode2Config(TIM_TypeDef* TIMx, u16 TIM_ExtTRGPrescaler, + u16 TIM_ExtTRGPolarity, u8 ExtTRGFilter) +{ + /* Check the parameters */ + assert(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler)); + assert(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity)); + + /* Configure the ETR Clock source */ + ETR_Config(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter); + + /* Enable the External clock mode2 */ + TIMx->SMCR |= SMCR_ECE_Set; +} +/******************************************************************************* +* Function Name : TIM_SelectInputTrigger +* Description : Selects the Input Trigger source +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_InputTriggerSource: The Input Trigger source. +* This parameter can be one of the following values: +* - TIM_TS_ITR0: Internal Trigger 0 +* - TIM_TS_ITR1: Internal Trigger 1 +* - TIM_TS_ITR2: Internal Trigger 2 +* - TIM_TS_ITR3: Internal Trigger 3 +* - TIM_TS_TI1F_ED: TI1 Edge Detector +* - TIM_TS_TI1FP1: Filtered Timer Input 1 +* - TIM_TS_TI2FP2: Filtered Timer Input 2 +* - TIM_TS_ETRF: External Trigger input +* Output : None +* Return : None +*******************************************************************************/ +void TIM_SelectInputTrigger(TIM_TypeDef* TIMx, u16 TIM_InputTriggerSource) +{ + u32 tmpsmcr = 0; + + /* Check the parameters */ + assert(IS_TIM_TRIGGER_SELECTION(TIM_InputTriggerSource)); + + tmpsmcr = TIMx->SMCR; + + /* Select the Tgigger Source */ + tmpsmcr &= SMCR_TS_Mask; + tmpsmcr |= TIM_InputTriggerSource; + + TIMx->SMCR = (u16)tmpsmcr; +} + +/******************************************************************************* +* Function Name : TIM_PrescalerConfig +* Description : Configures the TIMx Prescaler. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - Prescaler: specifies the Prescaler Register value +* - TIM_PSCReloadMode: specifies the TIM Prescaler Reload mode +* This parameter can be one of the following values: +* - TIM_PSCReloadMode_Update: The Prescaler is loaded at +* the update event. +* - TIM_PSCReloadMode_Immediate: The Prescaler is loaded +* immediatly. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_PrescalerConfig(TIM_TypeDef* TIMx, u16 Prescaler, u16 TIM_PSCReloadMode) +{ + /* Check the parameters */ + assert(IS_TIM_PRESCALER_RELOAD(TIM_PSCReloadMode)); + + /* Set the Prescaler value */ + TIMx->PSC = Prescaler; + + /* Set or reset the UG Bit */ + if (TIM_PSCReloadMode == TIM_PSCReloadMode_Immediate) + { + TIMx->EGR |= TIM_EventSource_Update; + } + else + { + TIMx->EGR &= TIM_EventSource_Update; + } +} + +/******************************************************************************* +* Function Name : TIM_CounterModeConfig +* Description : Specifies the TIMx Counter Mode to be used. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_CounterMode: specifies the Counter Mode to be used +* This parameter can be one of the following values: +* - TIM_CounterMode_Up: TIM Up Counting Mode +* - TIM_CounterMode_Down: TIM Down Counting Mode +* - TIM_CounterMode_CenterAligned1: TIM Center Aligned Mode1 +* - TIM_CounterMode_CenterAligned2: TIM Center Aligned Mode2 +* - TIM_CounterMode_CenterAligned3: TIM Center Aligned Mode3 +* Output : None +* Return : None +*******************************************************************************/ +void TIM_CounterModeConfig(TIM_TypeDef* TIMx, u16 TIM_CounterMode) +{ + u32 tmpcr1 = 0; + + /* Check the parameters */ + assert(IS_TIM_COUNTER_MODE(TIM_CounterMode)); + + tmpcr1 = TIMx->CR1; + + /* Reset the CMS and DIR Bits */ + tmpcr1 &= CR1_CounterMode_Mask; + + /* Set the Counter Mode */ + tmpcr1 |= TIM_CounterMode; + + TIMx->CR1 = (u16)tmpcr1; +} + +/******************************************************************************* +* Function Name : TIM_ForcedOC1Config +* Description : Forces the TIMx output 1 waveform to active or inactive level. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_ForcedAction: specifies the forced Action to be set to +* the output waveform. +* This parameter can be one of the following values: +* - TIM_ForcedAction_Active: Force active level on OC1REF +* - TIM_ForcedAction_InActive: Force inactive level on +* OC1REF. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_ForcedOC1Config(TIM_TypeDef* TIMx, u16 TIM_ForcedAction) +{ + u32 tmpccmr1 = 0; + + /* Check the parameters */ + assert(IS_TIM_FORCED_ACTION(TIM_ForcedAction)); + + tmpccmr1 = TIMx->CCMR1; + + /* Reset the OCM Bits */ + tmpccmr1 &= CCMR_OCM13_Mask; + + /* Configure The Forced output Mode */ + tmpccmr1 |= TIM_ForcedAction; + + TIMx->CCMR1 = (u16)tmpccmr1; +} + +/******************************************************************************* +* Function Name : TIM_ForcedOC2Config +* Description : Forces the TIMx output 2 waveform to active or inactive level. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_ForcedAction: specifies the forced Action to be set to +* the output waveform. +* This parameter can be one of the following values: +* - TIM_ForcedAction_Active: Force active level on OC2REF +* - TIM_ForcedAction_InActive: Force inactive level on +* OC2REF. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_ForcedOC2Config(TIM_TypeDef* TIMx, u16 TIM_ForcedAction) +{ + u32 tmpccmr1 = 0; + + /* Check the parameters */ + assert(IS_TIM_FORCED_ACTION(TIM_ForcedAction)); + + tmpccmr1 = TIMx->CCMR1; + + /* Reset the OCM Bits */ + tmpccmr1 &= CCMR_OCM24_Mask; + + /* Configure The Forced output Mode */ + tmpccmr1 |= (u16)(TIM_ForcedAction << 8); + + TIMx->CCMR1 = (u16)tmpccmr1; +} + +/******************************************************************************* +* Function Name : TIM_ForcedOC3Config +* Description : Forces the TIMx output 3 waveform to active or inactive level. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_ForcedAction: specifies the forced Action to be set to +* the output waveform. +* This parameter can be one of the following values: +* - TIM_ForcedAction_Active: Force active level on OC3REF +* - TIM_ForcedAction_InActive: Force inactive level on +* OC3REF. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_ForcedOC3Config(TIM_TypeDef* TIMx, u16 TIM_ForcedAction) +{ + u32 tmpccmr2 = 0; + + /* Check the parameters */ + assert(IS_TIM_FORCED_ACTION(TIM_ForcedAction)); + + tmpccmr2 = TIMx->CCMR2; + + /* Reset the OCM Bits */ + tmpccmr2 &= CCMR_OCM13_Mask; + + /* Configure The Forced output Mode */ + tmpccmr2 |= TIM_ForcedAction; + + TIMx->CCMR2 = (u16)tmpccmr2; +} + +/******************************************************************************* +* Function Name : TIM_ForcedOC4Config +* Description : Forces the TIMx output 4 waveform to active or inactive level. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_ForcedAction: specifies the forced Action to be set to +* the output waveform. +* This parameter can be one of the following values: +* - TIM_ForcedAction_Active: Force active level on OC4REF +* - TIM_ForcedAction_InActive: Force inactive level on +* OC4REF. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_ForcedOC4Config(TIM_TypeDef* TIMx, u16 TIM_ForcedAction) +{ + u32 tmpccmr2 = 0; + + /* Check the parameters */ + assert(IS_TIM_FORCED_ACTION(TIM_ForcedAction)); + + tmpccmr2 = TIMx->CCMR2; + + /* Reset the OCM Bits */ + tmpccmr2 &= CCMR_OCM24_Mask; + + /* Configure The Forced output Mode */ + tmpccmr2 |= (u16)(TIM_ForcedAction << 8); + + TIMx->CCMR2 = (u16)tmpccmr2; +} + +/******************************************************************************* +* Function Name : TIM_ARRPreloadConfig +* Description : Enables or disables TIMx peripheral Preload register on ARR. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - Newstate: new state of the TIMx peripheral Preload register +* This parameter can be: ENABLE or DISABLE. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_ARRPreloadConfig(TIM_TypeDef* TIMx, FunctionalState Newstate) +{ + u32 tmpcr1 = 0; + + /* Check the parameters */ + assert(IS_FUNCTIONAL_STATE(Newstate)); + + tmpcr1 = TIMx->CR1; + + if (Newstate != DISABLE) + { + /* Set the ARR Preload Bit */ + tmpcr1 |= CR1_ARPE_Set; + } + else + { + /* Reset the ARR Preload Bit */ + tmpcr1 &= CR1_ARPE_Reset; + } + + TIMx->CR1 = (u16)tmpcr1; +} + +/******************************************************************************* +* Function Name : TIM_SelectCCDMA +* Description : Selects the TIMx peripheral Capture Compare DMA source. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - Newstate: new state of the Capture Compare DMA source +* This parameter can be: ENABLE or DISABLE. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_SelectCCDMA(TIM_TypeDef* TIMx, FunctionalState Newstate) +{ + u32 tmpcr2 = 0; + + /* Check the parameters */ + assert(IS_FUNCTIONAL_STATE(Newstate)); + + tmpcr2 = TIMx->CR2; + + if (Newstate != DISABLE) + { + /* Set the CCDS Bit */ + tmpcr2 |= CR2_CCDS_Set; + } + else + { + /* Reset the CCDS Bit */ + tmpcr2 &= CR2_CCDS_Reset; + } + + TIMx->CR2 = (u16)tmpcr2; +} + +/******************************************************************************* +* Function Name : TIM_OC1PreloadConfig +* Description : Enables or disables the TIMx peripheral Preload register on CCR1. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_OCPreload: new state of the TIMx peripheral Preload +* register +* This parameter can be one of the following values: +* - TIM_OCPreload_Enable +* - TIM_OCPreload_Disable +* Output : None +* Return : None +*******************************************************************************/ +void TIM_OC1PreloadConfig(TIM_TypeDef* TIMx, u16 TIM_OCPreload) +{ + u32 tmpccmr1 = 0; + + /* Check the parameters */ + assert(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload)); + + tmpccmr1 = TIMx->CCMR1; + + /* Reset the OCPE Bit */ + tmpccmr1 &= CCMR_OC13PE_Mask; + + /* Enable or Disable the Output Compare Preload feature */ + tmpccmr1 |= TIM_OCPreload; + + TIMx->CCMR1 = (u16)tmpccmr1; +} + +/******************************************************************************* +* Function Name : TIM_OC2PreloadConfig +* Description : Enables or disables the TIMx peripheral Preload register on CCR2. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_OCPreload: new state of the TIMx peripheral Preload +* register +* This parameter can be one of the following values: +* - TIM_OCPreload_Enable +* - TIM_OCPreload_Disable +* Output : None +* Return : None +*******************************************************************************/ +void TIM_OC2PreloadConfig(TIM_TypeDef* TIMx, u16 TIM_OCPreload) +{ + u32 tmpccmr1 = 0; + + /* Check the parameters */ + assert(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload)); + + tmpccmr1 = TIMx->CCMR1; + + /* Reset the OCPE Bit */ + tmpccmr1 &= CCMR_OC24PE_Mask; + + /* Enable or Disable the Output Compare Preload feature */ + tmpccmr1 |= (u16)(TIM_OCPreload << 8); + + TIMx->CCMR1 = (u16)tmpccmr1; +} + +/******************************************************************************* +* Function Name : TIM_OC3PreloadConfig +* Description : Enables or disables the TIMx peripheral Preload register on CCR3. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_OCPreload: new state of the TIMx peripheral Preload +* register +* This parameter can be one of the following values: +* - TIM_OCPreload_Enable +* - TIM_OCPreload_Disable +* Output : None +* Return : None +*******************************************************************************/ +void TIM_OC3PreloadConfig(TIM_TypeDef* TIMx, u16 TIM_OCPreload) +{ + u32 tmpccmr2 = 0; + + /* Check the parameters */ + assert(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload)); + + tmpccmr2 = TIMx->CCMR2; + + /* Reset the OCPE Bit */ + tmpccmr2 &= CCMR_OC13PE_Mask; + + /* Enable or Disable the Output Compare Preload feature */ + tmpccmr2 |= TIM_OCPreload; + + TIMx->CCMR2 = (u16)tmpccmr2; +} + +/******************************************************************************* +* Function Name : TIM_OC4PreloadConfig +* Description : Enables or disables the TIMx peripheral Preload register on CCR4. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_OCPreload: new state of the TIMx peripheral Preload +* register +* This parameter can be one of the following values: +* - TIM_OCPreload_Enable +* - TIM_OCPreload_Disable +* Output : None +* Return : None +*******************************************************************************/ +void TIM_OC4PreloadConfig(TIM_TypeDef* TIMx, u16 TIM_OCPreload) +{ + u32 tmpccmr2 = 0; + + /* Check the parameters */ + assert(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload)); + + tmpccmr2 = TIMx->CCMR2; + + /* Reset the OCPE Bit */ + tmpccmr2 &= CCMR_OC24PE_Mask; + + /* Enable or Disable the Output Compare Preload feature */ + tmpccmr2 |= (u16)(TIM_OCPreload << 8); + + TIMx->CCMR2 = (u16)tmpccmr2; +} + +/******************************************************************************* +* Function Name : TIM_OC1FastConfig +* Description : Configures the TIMx Output Compare 1 Fast feature. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_OCFast: new state of the Output Compare Fast Enable Bit. +* This parameter can be one of the following values: +* - TIM_OCFast_Enable +* - TIM_OCFast_Disable +* Output : None +* Return : None +*******************************************************************************/ +void TIM_OC1FastConfig(TIM_TypeDef* TIMx, u16 TIM_OCFast) +{ + u32 tmpccmr1 = 0; + + /* Check the parameters */ + assert(IS_TIM_OCFAST_STATE(TIM_OCFast)); + + tmpccmr1 = TIMx->CCMR1; + + /* Reset the OCFE Bit */ + tmpccmr1 &= CCMR_OC13FE_Mask; + + /* Enable or Disable the Output Compare Fast Bit */ + tmpccmr1 |= TIM_OCFast; + + TIMx->CCMR1 = (u16)tmpccmr1; +} + +/******************************************************************************* +* Function Name : TIM_OC2FastConfig +* Description : Configures the TIMx Output Compare 2 Fast feature. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_OCFast: new state of the Output Compare Fast Enable Bit. +* This parameter can be one of the following values: +* - TIM_OCFast_Enable +* - TIM_OCFast_Disable +* Output : None +* Return : None +*******************************************************************************/ +void TIM_OC2FastConfig(TIM_TypeDef* TIMx, u16 TIM_OCFast) +{ + u32 tmpccmr1 = 0; + + /* Check the parameters */ + assert(IS_TIM_OCFAST_STATE(TIM_OCFast)); + + tmpccmr1 = TIMx->CCMR1; + + /* Reset the OCFE Bit */ + tmpccmr1 &= CCMR_OC24FE_Mask; + + /* Enable or Disable the Output Compare Fast Bit */ + tmpccmr1 |= (u16)(TIM_OCFast << 8); + + TIMx->CCMR1 = (u16)tmpccmr1; +} + +/******************************************************************************* +* Function Name : TIM_OC3FastConfig +* Description : Configures the TIMx Output Compare 3 Fast feature. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_OCFast: new state of the Output Compare Fast Enable Bit. +* This parameter can be one of the following values: +* - TIM_OCFast_Enable +* - TIM_OCFast_Disable +* Output : None +* Return : None +*******************************************************************************/ +void TIM_OC3FastConfig(TIM_TypeDef* TIMx, u16 TIM_OCFast) +{ + u32 tmpccmr2 = 0; + + /* Check the parameters */ + assert(IS_TIM_OCFAST_STATE(TIM_OCFast)); + + tmpccmr2 = TIMx->CCMR2; + + /* Reset the OCFE Bit */ + tmpccmr2 &= CCMR_OC13FE_Mask; + + /* Enable or Disable the Output Compare Fast Bit */ + tmpccmr2 |= TIM_OCFast; + + TIMx->CCMR2 = (u16)tmpccmr2; +} + +/******************************************************************************* +* Function Name : TIM_OC4FastConfig +* Description : Configures the TIMx Output Compare 4 Fast feature. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_OCFast: new state of the Output Compare Fast Enable Bit. +* This parameter can be one of the following values: +* - TIM_OCFast_Enable +* - TIM_OCFast_Disable +* Output : None +* Return : None +*******************************************************************************/ +void TIM_OC4FastConfig(TIM_TypeDef* TIMx, u16 TIM_OCFast) +{ + u32 tmpccmr2 = 0; + + /* Check the parameters */ + assert(IS_TIM_OCFAST_STATE(TIM_OCFast)); + + tmpccmr2 = TIMx->CCMR2; + + /* Reset the OCFE Bit */ + tmpccmr2 &= CCMR_OC24FE_Mask; + + /* Enable or Disable the Output Compare Fast Bit */ + tmpccmr2 |= (u16)(TIM_OCFast << 8); + + TIMx->CCMR2 = (u16)tmpccmr2; +} + +/******************************************************************************* +* Function Name : TIM_UpdateDisableConfig +* Description : Enables or Disables the TIMx Update event. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - Newstate: new state of the TIMx peripheral Preload register +* This parameter can be: ENABLE or DISABLE. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_UpdateDisableConfig(TIM_TypeDef* TIMx, FunctionalState Newstate) +{ + u32 tmpcr1 = 0; + + /* Check the parameters */ + assert(IS_FUNCTIONAL_STATE(Newstate)); + + tmpcr1 = TIMx->CR1; + + if (Newstate != DISABLE) + { + /* Set the Update Disable Bit */ + tmpcr1 |= CR1_UDIS_Set; + } + else + { + /* Reset the Update Disable Bit */ + tmpcr1 &= CR1_UDIS_Reset; + } + + TIMx->CR1 = (u16)tmpcr1; +} + +/******************************************************************************* +* Function Name : TIM_EncoderInterfaceConfig +* Description : Configures the TIMx Encoder Interface. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_EncoderMode: specifies the TIMx Encoder Mode. +* This parameter can be one of the following values: +* - TIM_EncoderMode_TI1: Counter counts on TI1FP1 edge +* depending on TI2FP2 level. +* - TIM_EncoderMode_TI2: Counter counts on TI2FP2 edge +* depending on TI1FP1 level. +* - TIM_EncoderMode_TI12: Counter counts on both TI1FP1 and +* TI2FP2 edges depending on the level of the other input. +* - TIM_IC1Polarity: specifies the IC1 Polarity +* This parmeter can be one of the following values: +* - TIM_ICPolarity_Falling +* - TIM_ICPolarity_Rising +* - TIM_IC2Polarity: specifies the IC2 Polarity +* This parmeter can be one of the following values: +* - TIM_ICPolarity_Falling +* - TIM_ICPolarity_Rising +* Output : None +* Return : None +*******************************************************************************/ +void TIM_EncoderInterfaceConfig(TIM_TypeDef* TIMx, u16 TIM_EncoderMode, + u16 TIM_IC1Polarity, u16 TIM_IC2Polarity) +{ + u32 tmpsmcr = 0; + u32 tmpccmr1 = 0; + u32 tmpccer = 0; + + /* Check the parameters */ + assert(IS_TIM_ENCODER_MODE(TIM_EncoderMode)); + assert(IS_TIM_IC_POLARITY(TIM_IC1Polarity)); + assert(IS_TIM_IC_POLARITY(TIM_IC2Polarity)); + + tmpsmcr = TIMx->SMCR; + tmpccmr1 = TIMx->CCMR1; + tmpccer = TIMx->CCER; + + /* Set the encoder Mode */ + tmpsmcr &= SMCR_SMS_Mask; + tmpsmcr |= TIM_EncoderMode; + + /* Select the Capture Compare 1 and the Capture Compare 2 as input */ + tmpccmr1 &= CCMR_CC13S_Mask & CCMR_CC24S_Mask; + tmpccmr1 |= CCMR_TI13Direct_Set | CCMR_TI24Direct_Set; + + /* Set the TI1 and the TI2 Polarities */ + tmpccer &= CCER_CC1P_Mask & CCER_CC2P_Mask; + tmpccer |= (TIM_IC1Polarity | (u16)((u16)TIM_IC2Polarity << 4)); + + TIMx->SMCR = (u16)tmpsmcr; + + TIMx->CCMR1 = (u16)tmpccmr1; + + TIMx->CCER = (u16)tmpccer; +} + +/******************************************************************************* +* Function Name : TIM_GenerateEvent +* Description : Configures the TIMx event to be generate by software. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_EventSource: specifies the event source. +* This parameter can be one or more of the following values: +* - TIM_EventSource_Update: Timer update Event source +* - TIM_EventSource_CC1: Timer Capture Compare 1 Event source +* - TIM_EventSource_CC2: Timer Capture Compare 2 Event source +* - TIM_EventSource_CC3: Timer Capture Compare 3 Event source +* - TIM_EventSource_CC4: Timer Capture Compare 4 Event source +* - TIM_EventSource_Trigger: Timer Trigger Event source +* Output : None +* Return : None +*******************************************************************************/ +void TIM_GenerateEvent(TIM_TypeDef* TIMx, u16 TIM_EventSource) +{ + /* Check the parameters */ + assert(IS_TIM_EVENT_SOURCE(TIM_EventSource)); + + /* Set the event sources */ + TIMx->EGR |= TIM_EventSource; +} + +/******************************************************************************* +* Function Name : TIM_OC1PolarityConfig +* Description : Configures the TIMx channel 1 polarity. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_OCPolarity: specifies the OC1 Polarity +* This parmeter can be one of the following values: +* - TIM_OCPolarity_High: Output Compare active high +* - TIM_OCPolarity_Low: Output Compare active low +* Output : None +* Return : None +*******************************************************************************/ +void TIM_OC1PolarityConfig(TIM_TypeDef* TIMx, u16 TIM_OCPolarity) +{ + u32 tmpccer = 0; + + /* Check the parameters */ + assert(IS_TIM_OC_POLARITY(TIM_OCPolarity)); + + tmpccer = TIMx->CCER; + + /* Set or Reset the CC1P Bit */ + tmpccer &= CCER_CC1P_Mask; + tmpccer |= TIM_OCPolarity; + + TIMx->CCER = (u16)tmpccer; +} + +/******************************************************************************* +* Function Name : TIM_OC2PolarityConfig +* Description : Configures the TIMx channel 2 polarity. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_OCPolarity: specifies the OC2 Polarity +* This parmeter can be one of the following values: +* - TIM_OCPolarity_High: Output Compare active high +* - TIM_OCPolarity_Low: Output Compare active low +* Output : None +* Return : None +*******************************************************************************/ +void TIM_OC2PolarityConfig(TIM_TypeDef* TIMx, u16 TIM_OCPolarity) +{ + u32 tmpccer = 0; + + /* Check the parameters */ + assert(IS_TIM_OC_POLARITY(TIM_OCPolarity)); + + tmpccer = TIMx->CCER; + + /* Set or Reset the CC2P Bit */ + tmpccer &= CCER_CC2P_Mask; + tmpccer |= (u16)((u16)TIM_OCPolarity << 4); + + TIMx->CCER = (u16)tmpccer; +} + +/******************************************************************************* +* Function Name : TIM_OC3PolarityConfig +* Description : Configures the TIMx channel 3 polarity. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_OCPolarity: specifies the OC3 Polarity +* This parmeter can be one of the following values: +* - TIM_OCPolarity_High: Output Compare active high +* - TIM_OCPolarity_Low: Output Compare active low +* Output : None +* Return : None +*******************************************************************************/ +void TIM_OC3PolarityConfig(TIM_TypeDef* TIMx, u16 TIM_OCPolarity) +{ + u32 tmpccer = 0; + + /* Check the parameters */ + assert(IS_TIM_OC_POLARITY(TIM_OCPolarity)); + + tmpccer = TIMx->CCER; + + /* Set or Reset the CC3P Bit */ + tmpccer &= CCER_CC3P_Mask; + tmpccer |= (u16)((u16)TIM_OCPolarity << 8); + + TIMx->CCER = (u16)tmpccer; +} + +/******************************************************************************* +* Function Name : TIM_OC4PolarityConfig +* Description : Configures the TIMx channel 4 polarity. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_OCPolarity: specifies the OC4 Polarity +* This parmeter can be one of the following values: +* - TIM_OCPolarity_High: Output Compare active high +* - TIM_OCPolarity_Low: Output Compare active low +* Output : None +* Return : None +*******************************************************************************/ +void TIM_OC4PolarityConfig(TIM_TypeDef* TIMx, u16 TIM_OCPolarity) +{ + u32 tmpccer = 0; + + /* Check the parameters */ + assert(IS_TIM_OC_POLARITY(TIM_OCPolarity)); + + tmpccer = TIMx->CCER; + + /* Set or Reset the CC4P Bit */ + tmpccer &= CCER_CC4P_Mask; + tmpccer |= (u16)((u16)TIM_OCPolarity << 12); + + TIMx->CCER = (u16)tmpccer; +} + +/******************************************************************************* +* Function Name : TIM_UpdateRequestConfig +* Description : Configures the TIMx Update Request Interrupt source. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_UpdateSource: specifies the Update source. +* This parameter can be one of the following values: +* - TIM_UpdateSource_Regular +* - TIM_UpdateSource_Global +* Output : None +* Return : None +*******************************************************************************/ +void TIM_UpdateRequestConfig(TIM_TypeDef* TIMx, u16 TIM_UpdateSource) +{ + u32 tmpcr1 = 0; + + /* Check the parameters */ + assert(IS_TIM_UPDATE_SOURCE(TIM_UpdateSource)); + + tmpcr1 = TIMx->CR1; + + if (TIM_UpdateSource == TIM_UpdateSource_Regular) + { + /* Set the URS Bit */ + tmpcr1 |= CR1_URS_Set; + } + else + { + /* Reset the URS Bit */ + tmpcr1 &= CR1_URS_Reset; + } + TIMx->CR1 = (u16)tmpcr1; +} + +/******************************************************************************* +* Function Name : TIM_SelectHallSensor +* Description : Enables or disables the TIMxÂ’s Hall sensor interface. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - Newstate: new state of the TIMx Hall sensor interface. +* This parameter can be: ENABLE or DISABLE. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_SelectHallSensor(TIM_TypeDef* TIMx, FunctionalState Newstate) +{ + /* Check the parameters */ + assert(IS_FUNCTIONAL_STATE(Newstate)); + + if (Newstate != DISABLE) + { + /* Set the TI1S Bit */ + TIMx->CR2 |= CR2_TI1S_Set; + } + else + { + /* Reset the TI1S Bit */ + TIMx->CR2 &= CR2_TI1S_Reset; + } +} + +/******************************************************************************* +* Function Name : TIM_SelectOnePulseMode +* Description : Selects the TIMxÂ’s One Pulse Mode. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_OPMode: specifies the OPM Mode to be used. +* This parameter can be one of the following values: +* - TIM_OPMode_Single +* - TIM_OPMode_Repetitive +* Output : None +* Return : None +*******************************************************************************/ +void TIM_SelectOnePulseMode(TIM_TypeDef* TIMx, u16 TIM_OPMode) +{ + u32 tmpcr1 = 0; + + /* Check the parameters */ + assert(IS_TIM_OPM_MODE(TIM_OPMode)); + + tmpcr1 = TIMx->CR1; + + /* Reset the OPM Bit */ + tmpcr1 &= CR1_OPM_Mask; + + /* Configure the OPM Mode */ + tmpcr1 |= TIM_OPMode; + + TIMx->CR1 = (u16)tmpcr1; +} + +/******************************************************************************* +* Function Name : TIM_SelectOutputTrigger +* Description : Selects the TIMx Trigger Output Mode. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_TRGOSource: specifies the Trigger Output source. +* This paramter can be one of the following values: +* - TIM_TRGOSource_Reset +* - TIM_TRGOSource_Enable +* - TIM_TRGOSource_Update +* - TIM_TRGOSource_OC1 +* - TIM_TRGOSource_OC1Ref +* - TIM_TRGOSource_OC2Ref +* - TIM_TRGOSource_OC3Ref +* - TIM_TRGOSource_OC4Ref +* Output : None +* Return : None +*******************************************************************************/ +void TIM_SelectOutputTrigger(TIM_TypeDef* TIMx, u16 TIM_TRGOSource) +{ + u32 tmpcr2 = 0; + + /* Check the parameters */ + assert(IS_TIM_TRGO_SOURCE(TIM_TRGOSource)); + + tmpcr2 = TIMx->CR2; + /* Reset the MMS Bits */ + tmpcr2 &= CR2_MMS_Mask; + + /* Select the TRGO source */ + tmpcr2 |= TIM_TRGOSource; + + TIMx->CR2 = (u16)tmpcr2; +} + +/******************************************************************************* +* Function Name : TIM_SelectSlaveMode +* Description : Selects the TIMx Slave Mode. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_SlaveMode: specifies the Timer Slave Mode. +* This paramter can be one of the following values: +* - TIM_SlaveMode_Reset +* - TIM_SlaveMode_Gated +* - TIM_SlaveMode_Trigger +* - TIM_SlaveMode_External1 +* Output : None +* Return : None +*******************************************************************************/ +void TIM_SelectSlaveMode(TIM_TypeDef* TIMx, u16 TIM_SlaveMode) +{ + u32 tmpsmcr = 0; + + /* Check the parameters */ + assert(IS_TIM_SLAVE_MODE(TIM_SlaveMode)); + + tmpsmcr = TIMx->SMCR; + + /* Reset the SMS Bits */ + tmpsmcr &= SMCR_SMS_Mask; + + /* Select the Slave Mode */ + tmpsmcr |= TIM_SlaveMode; + + TIMx->SMCR = (u16)tmpsmcr; +} + +/******************************************************************************* +* Function Name : TIM_SelectMasterSlaveMode +* Description : Sets or Resets the TIMx Master/Slave Mode. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_MasterSlaveMode: specifies the Timer Master Slave Mode. +* This paramter can be one of the following values: +* - TIM_MasterSlaveMode_Enable: synchronization between the +* current timer and its slaves (through TRGO). +* - TIM_MasterSlaveMode_Disable: No action +* Output : None +* Return : None +*******************************************************************************/ +void TIM_SelectMasterSlaveMode(TIM_TypeDef* TIMx, u16 TIM_MasterSlaveMode) +{ + u32 tmpsmcr = 0; + + /* Check the parameters */ + assert(IS_TIM_MSM_STATE(TIM_MasterSlaveMode)); + + tmpsmcr = TIMx->SMCR; + + /* Set or Reset the MSM Bit */ + tmpsmcr &= SMCR_MSM_Mask; + tmpsmcr |= TIM_MasterSlaveMode; + + TIMx->SMCR = (u16)tmpsmcr; +} + +/******************************************************************************* +* Function Name : TIM_SetAutoreload +* Description : Sets the TIMx Autoreload Register value +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - Autoreload: specifies the Autoreload register new value. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_SetAutoreload(TIM_TypeDef* TIMx, u16 Autoreload) +{ + /* Set the Autoreload Register value */ + TIMx->ARR = Autoreload; +} + +/******************************************************************************* +* Function Name : TIM_SetCompare1 +* Description : Sets the TIMx Capture Compare1 Register value +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - Compare1: specifies the Capture Compare1 register new value. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_SetCompare1(TIM_TypeDef* TIMx, u16 Compare1) +{ + /* Set the Capture Compare1 Register value */ + TIMx->CCR1 = Compare1; +} + +/******************************************************************************* +* Function Name : TIM_SetCompare2 +* Description : Sets the TIMx Capture Compare2 Register value +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - Compare2: specifies the Capture Compare2 register new value. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_SetCompare2(TIM_TypeDef* TIMx, u16 Compare2) +{ + /* Set the Capture Compare2 Register value */ + TIMx->CCR2 = Compare2; +} + +/******************************************************************************* +* Function Name : TIM_SetCompare3 +* Description : Sets the TIMx Capture Compare3 Register value +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - Compare3: specifies the Capture Compare3 register new value. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_SetCompare3(TIM_TypeDef* TIMx, u16 Compare3) +{ + /* Set the Capture Compare3 Register value */ + TIMx->CCR3 = Compare3; +} + +/******************************************************************************* +* Function Name : TIM_SetCompare4 +* Description : Sets the TIMx Capture Compare4 Register value +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - Compare4: specifies the Capture Compare4 register new value. +* Output : None +* Return : None +*******************************************************************************/ +void TIM_SetCompare4(TIM_TypeDef* TIMx, u16 Compare4) +{ + /* Set the Capture Compare4 Register value */ + TIMx->CCR4 = Compare4; +} + +/******************************************************************************* +* Function Name : TIM_SetIC1Prescaler +* Description : Sets the TIMx Input Capture 1 prescaler. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_IC1Prescaler: specifies the Input Capture1 prescaler +* new value. +* This parameter can be one of the following values: +* - TIM_ICPSC_DIV1: no prescaler +* - TIM_ICPSC_DIV2: capture is done once every 2 events +* - TIM_ICPSC_DIV4: capture is done once every 4 events +* - TIM_ICPSC_DIV8: capture is done once every 8 events +* Output : None +* Return : None +*******************************************************************************/ +void TIM_SetIC1Prescaler(TIM_TypeDef* TIMx, u16 TIM_IC1Prescaler) +{ + u32 tmpccmr1 = 0; + + /* Check the parameters */ + assert(IS_TIM_IC_PRESCALER(TIM_IC1Prescaler)); + + tmpccmr1 = TIMx->CCMR1; + + /* Reset the IC1PSC Bits */ + tmpccmr1 &= CCMR_IC13PSC_Mask; + + /* Set the IC1PSC value */ + tmpccmr1 |= TIM_IC1Prescaler; + + TIMx->CCMR1 = (u16)tmpccmr1; +} + +/******************************************************************************* +* Function Name : TIM_SetIC2Prescaler +* Description : Sets the TIMx Input Capture 2 prescaler. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_IC2Prescaler: specifies the Input Capture2 prescaler +* new value. +* This parameter can be one of the following values: +* - TIM_ICPSC_DIV1: no prescaler +* - TIM_ICPSC_DIV2: capture is done once every 2 events +* - TIM_ICPSC_DIV4: capture is done once every 4 events +* - TIM_ICPSC_DIV8: capture is done once every 8 events +* Output : None +* Return : None +*******************************************************************************/ +void TIM_SetIC2Prescaler(TIM_TypeDef* TIMx, u16 TIM_IC2Prescaler) +{ + u32 tmpccmr1 = 0; + + /* Check the parameters */ + assert(IS_TIM_IC_PRESCALER(TIM_IC2Prescaler)); + + tmpccmr1 = TIMx->CCMR1; + + /* Reset the IC2PSC Bits */ + tmpccmr1 &= CCMR_IC24PSC_Mask; + + /* Set the IC2PSC value */ + tmpccmr1 |= (u16)((u16)TIM_IC2Prescaler << 8); + + TIMx->CCMR1 = (u16)tmpccmr1; +} + +/******************************************************************************* +* Function Name : TIM_SetIC3Prescaler +* Description : Sets the TIMx Input Capture 3 prescaler. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_IC3Prescaler: specifies the Input Capture3 prescaler +* new value. +* This parameter can be one of the following values: +* - TIM_ICPSC_DIV1: no prescaler +* - TIM_ICPSC_DIV2: capture is done once every 2 events +* - TIM_ICPSC_DIV4: capture is done once every 4 events +* - TIM_ICPSC_DIV8: capture is done once every 8 events +* Output : None +* Return : None +*******************************************************************************/ +void TIM_SetIC3Prescaler(TIM_TypeDef* TIMx, u16 TIM_IC3Prescaler) +{ + u32 tmpccmr2 = 0; + + /* Check the parameters */ + assert(IS_TIM_IC_PRESCALER(TIM_IC3Prescaler)); + + tmpccmr2 = TIMx->CCMR2; + + /* Reset the IC3PSC Bits */ + tmpccmr2 &= CCMR_IC13PSC_Mask; + + /* Set the IC3PSC value */ + tmpccmr2 |= TIM_IC3Prescaler; + + TIMx->CCMR2 = (u16)tmpccmr2; +} + +/******************************************************************************* +* Function Name : TIM_SetIC4Prescaler +* Description : Sets the TIMx Input Capture 4 prescaler. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_IC4Prescaler: specifies the Input Capture4 prescaler +* new value. +* This parameter can be one of the following values: +* - TIM_ICPSC_DIV1: no prescaler +* - TIM_ICPSC_DIV2: capture is done once every 2 events +* - TIM_ICPSC_DIV4: capture is done once every 4 events +* - TIM_ICPSC_DIV8: capture is done once every 8 events +* Output : None +* Return : None +*******************************************************************************/ +void TIM_SetIC4Prescaler(TIM_TypeDef* TIMx, u16 TIM_IC4Prescaler) +{ + u32 tmpccmr2 = 0; + + /* Check the parameters */ + assert(IS_TIM_IC_PRESCALER(TIM_IC4Prescaler)); + + tmpccmr2 = TIMx->CCMR2; + + /* Reset the IC4PSC Bits */ + tmpccmr2 &= CCMR_IC24PSC_Mask; + + /* Set the IC4PSC value */ + tmpccmr2 |= (u16)((u16)TIM_IC4Prescaler << 8); + + TIMx->CCMR2 = (u16)tmpccmr2; +} + +/******************************************************************************* +* Function Name : TIM_SetClockDivision +* Description : Sets the TIMx Clock Division value. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_CKD: specifies the clock division value. +* This parameter can be one of the following value: +* - TIM_CKD_DIV1: TDTS = Tck_tim +* - TIM_CKD_DIV2: TDTS = 2*Tck_tim +* - TIM_CKD_DIV4: TDTS = 4*Tck_tim +* Output : None +* Return : None +*******************************************************************************/ +void TIM_SetClockDivision(TIM_TypeDef* TIMx, u16 TIM_CKD) +{ + u32 tmpcr1 = 0; + + /* Check the parameters */ + assert(IS_TIM_CKD_DIV(TIM_CKD)); + + tmpcr1 = TIMx->CR1; + + /* Reset the CKD Bits */ + tmpcr1 &= CR1_CKD_Mask; + + /* Set the CKD value */ + tmpcr1 |= TIM_CKD; + + TIMx->CR1 = (u16)tmpcr1; +} + +/******************************************************************************* +* Function Name : TIM_GetCapture1 +* Description : Gets the TIMx Input Capture 1 value. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* Output : None +* Return : Capture Compare 1 Register value. +*******************************************************************************/ +u16 TIM_GetCapture1(TIM_TypeDef* TIMx) +{ + /* Get the Capture 1 Register value */ + return TIMx->CCR1; +} + +/******************************************************************************* +* Function Name : TIM_GetCapture2 +* Description : Gets the TIMx Input Capture 2 value. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* Output : None +* Return : Capture Compare 2 Register value. +*******************************************************************************/ +u16 TIM_GetCapture2(TIM_TypeDef* TIMx) +{ + /* Get the Capture 2 Register value */ + return TIMx->CCR2; +} + +/******************************************************************************* +* Function Name : TIM_GetCapture3 +* Description : Gets the TIMx Input Capture 3 value. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* Output : None +* Return : Capture Compare 3 Register value. +*******************************************************************************/ +u16 TIM_GetCapture3(TIM_TypeDef* TIMx) +{ + /* Get the Capture 3 Register value */ + return TIMx->CCR3; +} + +/******************************************************************************* +* Function Name : TIM_GetCapture4 +* Description : Gets the TIMx Input Capture 4 value. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* Output : None +* Return : Capture Compare 4 Register value. +*******************************************************************************/ +u16 TIM_GetCapture4(TIM_TypeDef* TIMx) +{ + /* Get the Capture 4 Register value */ + return TIMx->CCR4; +} + +/******************************************************************************* +* Function Name : TIM_GetCounter +* Description : Gets the TIMx Counter value. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* Output : None +* Return : Counter Register value. +*******************************************************************************/ +u16 TIM_GetCounter(TIM_TypeDef* TIMx) +{ + /* Get the Counter Register value */ + return TIMx->CNT; +} + +/******************************************************************************* +* Function Name : TIM_GetPrescaler +* Description : Gets the TIMx Prescaler value. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* Output : None +* Return : Prescaler Register value. +*******************************************************************************/ +u16 TIM_GetPrescaler(TIM_TypeDef* TIMx) +{ + /* Get the Prescaler Register value */ + return TIMx->PSC; +} + +/******************************************************************************* +* Function Name : TIM_GetFlagStatus +* Description : Checks whether the specified TIMx flag is set or not. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_FLAG: specifies the flag to check. +* This parameter can be one of the following values: +* - TIM_FLAG_Update: Timer update Flag +* - TIM_FLAG_CC1: Timer Capture Compare 1 Flag +* - TIM_FLAG_CC2: Timer Capture Compare 2 Flag +* - TIM_FLAG_CC3: Timer Capture Compare 3 Flag +* - TIM_FLAG_CC4: Timer Capture Compare 4 Flag +* - TIM_FLAG_Trigger: Timer Trigger Flag +* - TIM_FLAG_CC1OF: Timer Capture Compare 1 overcapture Flag +* - TIM_FLAG_CC2OF: Timer Capture Compare 2 overcapture Flag +* - TIM_FLAG_CC3OF: Timer Capture Compare 3 overcapture Flag +* - TIM_FLAG_CC4OF: Timer Capture Compare 4 overcapture Flag +* Output : None +* Return : The new state of TIM_FLAG (SET or RESET). +*******************************************************************************/ +FlagStatus TIM_GetFlagStatus(TIM_TypeDef* TIMx, u16 TIM_FLAG) +{ + FlagStatus bitstatus = RESET; + + /* Check the parameters */ + assert(IS_TIM_GET_FLAG(TIM_FLAG)); + + if ((TIMx->SR & TIM_FLAG) != (u16)RESET ) + { + bitstatus = SET; + } + else + { + bitstatus = RESET; + } + return bitstatus; +} + +/******************************************************************************* +* Function Name : TIM_ClearFlag +* Description : Clears the TIMx's pending flags. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_FLAG: specifies the flag bit to clear. +* This parameter can be any combination of the following values: +* - TIM_FLAG_Update: Timer update Flag +* - TIM_FLAG_CC1: Timer Capture Compare 1 Flag +* - TIM_FLAG_CC2: Timer Capture Compare 2 Flag +* - TIM_FLAG_CC3: Timer Capture Compare 3 Flag +* - TIM_FLAG_CC4: Timer Capture Compare 4 Flag +* - TIM_FLAG_Trigger: Timer Trigger Flag +* - TIM_FLAG_CC1OF: Timer Capture Compare 1 overcapture Flag +* - TIM_FLAG_CC2OF: Timer Capture Compare 2 overcapture Flag +* - TIM_FLAG_CC3OF: Timer Capture Compare 3 overcapture Flag +* - TIM_FLAG_CC4OF: Timer Capture Compare 4 overcapture Flag +* Output : None +* Return : None +*******************************************************************************/ +void TIM_ClearFlag(TIM_TypeDef* TIMx, u16 TIM_FLAG) +{ + /* Check the parameters */ + assert(IS_TIM_CLEAR_FLAG(TIM_FLAG)); + + /* Clear the flags */ + TIMx->SR &= (u16)~TIM_FLAG; +} + +/******************************************************************************* +* Function Name : TIM_GetITStatus +* Description : Checks whether the TIMx interrupt has occurred or not. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_IT: specifies the TIM interrupt source to check. +* This parameter can be one of the following values: +* - TIM_IT_Update: Timer update Interrupt source +* - TIM_IT_CC1: Timer Capture Compare 1 Interrupt source +* - TIM_IT_CC2: Timer Capture Compare 2 Interrupt source +* - TIM_IT_CC3: Timer Capture Compare 3 Interrupt source +* - TIM_IT_CC4: Timer Capture Compare 4 Interrupt source +* - TIM_IT_Trigger: Timer Trigger Interrupt source +* Output : None +* Return : The new state of the TIM_IT(SET or RESET). +*******************************************************************************/ +ITStatus TIM_GetITStatus(TIM_TypeDef* TIMx, u16 TIM_IT) +{ + ITStatus bitstatus = RESET; + + u16 itstatus = 0x0, itenable = 0x0; + + /* Check the parameters */ + assert(IS_TIM_GET_IT(TIM_IT)); + + itstatus = TIMx->SR & TIM_IT; + + itenable = TIMx->DIER & TIM_IT; + + if ((itstatus != (u16)RESET) && (itenable != (u16)RESET)) + { + bitstatus = SET; + } + else + { + bitstatus = RESET; + } + return bitstatus; +} + +/******************************************************************************* +* Function Name : TIM_ClearITPendingBit +* Description : Clears the TIMx's interrupt pending bits. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_IT: specifies the pending bit to clear. +* This parameter can be any combination of the following values: +* - TIM_IT_Update: Timer update Interrupt source +* - TIM_IT_CC1: Timer Capture Compare 1 Interrupt source +* - TIM_IT_CC2: Timer Capture Compare 2 Interrupt source +* - TIM_IT_CC3: Timer Capture Compare 3 Interrupt source +* - TIM_IT_CC4: Timer Capture Compare 4 Interrupt source +* - TIM_IT_Trigger: Timer Trigger Interrupt source +* Output : None +* Return : None +*******************************************************************************/ +void TIM_ClearITPendingBit(TIM_TypeDef* TIMx, u16 TIM_IT) +{ + /* Check the parameters */ + assert(IS_TIM_IT(TIM_IT)); + + /* Clear the IT pending Bit */ + TIMx->SR &= (u16)~TIM_IT; +} + +/******************************************************************************* +* Function Name : PWMInput_Config +* Description : Configures the TIM peripheral according to the specified +* parameters in the TIM_ICInitStruct to measure an external PWM +* signal. +* Input : - TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure +* that contains the configuration information for the specified +* TIM peripheral. +* Output : None +* Return : None +*******************************************************************************/ +static void PWMI_Config(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct) +{ + u8 ICPolarity = TIM_ICPolarity_Rising; + u8 ICSelection = TIM_ICSelection_DirectTI; + + /* Select the Opposite Input Polarity */ + if (TIM_ICInitStruct->TIM_ICPolarity == TIM_ICPolarity_Rising) + { + ICPolarity = TIM_ICPolarity_Falling; + } + else + { + ICPolarity = TIM_ICPolarity_Rising; + } + + /* Select the Opposite Input */ + if (TIM_ICInitStruct->TIM_ICSelection == TIM_ICSelection_DirectTI) + { + ICSelection = TIM_ICSelection_IndirectTI; + } + else + { + ICSelection = TIM_ICSelection_DirectTI; + } + + if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_1) + { + /* TI1 Configuration */ + TI1_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection, + TIM_ICInitStruct->TIM_ICFilter); + + /* Set the Input Capture Prescaler value */ + TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler); + + /* TI2 Configuration */ + TI2_Config(TIMx, ICPolarity, ICSelection, TIM_ICInitStruct->TIM_ICFilter); + + /* Set the Input Capture Prescaler value */ + TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler); + } + else + { + /* TI1 Configuration */ + TI2_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection, + TIM_ICInitStruct->TIM_ICFilter); + + /* Set the Input Capture Prescaler value */ + TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler); + + /* TI2 Configuration */ + TI1_Config(TIMx, ICPolarity, ICSelection, TIM_ICInitStruct->TIM_ICFilter); + + /* Set the Input Capture Prescaler value */ + TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler); + } +} + +/******************************************************************************* +* Function Name : TI1_Config +* Description : Configure the TI1 as Input. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_ICPolarity : The Input Polarity. +* This parameter can be one of the following values: +* - TIM_ICPolarity_Rising +* - TIM_ICPolarity_Falling +* - TIM_ICSelection: specifies the input to be used. +* This parameter can be one of the following values: +* - TIM_ICSelection_DirectTI: TIM Input 1 is selected to +* be connected to IC1. +* - TIM_ICSelection_IndirectTI: TIM Input 1 is selected to +* be connected to IC2. +* - TIM_ICSelection_TRGI: TIM Input 1 is selected to be +* connected to TRGI. +* - TIM_ICFilter: Specifies the Input Capture Filter. +* This parameter must be a value between 0x00 and 0x0F. +* Output : None +* Return : None +*******************************************************************************/ +static void TI1_Config(TIM_TypeDef* TIMx, u16 TIM_ICPolarity, u16 TIM_ICSelection, + u8 TIM_ICFilter) +{ + u32 tmpccmr1 = 0, tmpccer = 0; + + tmpccmr1 = TIMx->CCMR1; + tmpccer = TIMx->CCER; + + /* Disable the Channel 1: Reset the CCE Bit */ + TIMx->CCER &= CCRE_CC1E_Reset; + + /* Select the Input and set the filter */ + tmpccmr1 &= CCMR_CC13S_Mask & CCMR_IC13F_Mask; + tmpccmr1 |= TIM_ICSelection | (u16)((u16)TIM_ICFilter << 4); + + /* Select the Polarity and set the CCE Bit */ + tmpccer &= CCER_CC1P_Mask & CCRE_CC1E_Mask; + tmpccer |= TIM_ICPolarity | CCRE_CC1E_Set; + + TIMx->CCMR1 = 0x0000; + TIMx->CCMR1 = (u16)tmpccmr1; + TIMx->CCER = (u16)tmpccer; +} + +/******************************************************************************* +* Function Name : TI2_Config +* Description : Configure the TI2 as Input. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_ICPolarity : The Input Polarity. +* This parameter can be one of the following values: +* - TIM_ICPolarity_Rising +* - TIM_ICPolarity_Falling +* - TIM_ICSelection: specifies the input to be used. +* This parameter can be one of the following values: +* - TIM_ICSelection_DirectTI: TIM Input 2 is selected to +* be connected to IC2. +* - TIM_ICSelection_IndirectTI: TIM Input 2 is selected to +* be connected to IC1. +* - TIM_ICSelection_TRGI: TIM Input 2 is selected to be +* connected to TRGI. +* - TIM_ICFilter: Specifies the Input Capture Filter. +* This parameter must be a value between 0x00 and 0x0F. +* Output : None +* Return : None +*******************************************************************************/ +static void TI2_Config(TIM_TypeDef* TIMx, u16 TIM_ICPolarity, u16 TIM_ICSelection, + u8 TIM_ICFilter) +{ + u32 tmpccmr1 = 0, tmpccer = 0, tmp = 0; + + tmpccmr1 = TIMx->CCMR1; + tmpccer = TIMx->CCER; + tmp = (u16)((u16)TIM_ICPolarity << 4); + + /* Disable the Channel 2: Reset the CCE Bit */ + TIMx->CCER &= CCRE_CC2E_Reset; + + /* Select the Input and set the filter */ + tmpccmr1 &= CCMR_CC24S_Mask & CCMR_IC24F_Mask; + tmpccmr1 |= (u16)((u16)TIM_ICFilter << 12); + tmpccmr1 |= (u16)((u16)TIM_ICSelection << 8); + + /* Select the Polarity and set the CCE Bit */ + tmpccer &= CCER_CC2P_Mask & CCRE_CC2E_Mask; + tmpccer |= tmp | CCRE_CC2E_Set; + + TIMx->CCMR1 = (u16)tmpccmr1 ; + TIMx->CCER = (u16)tmpccer; +} + +/******************************************************************************* +* Function Name : TI3_Config +* Description : Configure the TI3 as Input. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_ICPolarity : The Input Polarity. +* This parameter can be one of the following values: +* - TIM_ICPolarity_Rising +* - TIM_ICPolarity_Falling +* - TIM_ICSelection: specifies the input to be used. +* This parameter can be one of the following values: +* - TIM_ICSelection_DirectTI: TIM Input 3 is selected to +* be connected to IC3. +* - TIM_ICSelection_IndirectTI: TIM Input 3 is selected to +* be connected to IC4. +* - TIM_ICSelection_TRGI: TIM Input 3 is selected to be +* connected to TRGI. +* - TIM_ICFilter: Specifies the Input Capture Filter. +* This parameter must be a value between 0x00 and 0x0F. +* Output : None +* Return : None +*******************************************************************************/ +static void TI3_Config(TIM_TypeDef* TIMx, u16 TIM_ICPolarity, u16 TIM_ICSelection, + u8 TIM_ICFilter) +{ + u32 tmpccmr2 = 0, tmpccer = 0, tmp = 0; + + tmpccmr2 = TIMx->CCMR2; + tmpccer = TIMx->CCER; + tmp = (u16)((u16)TIM_ICPolarity << 8); + + /* Disable the Channel 3: Reset the CCE Bit */ + TIMx->CCER &= CCRE_CC3E_Reset; + + /* Select the Input and set the filter */ + tmpccmr2 &= CCMR_CC13S_Mask & CCMR_IC13F_Mask; + tmpccmr2 |= TIM_ICSelection | (u16)((u16)TIM_ICFilter << 4); + + /* Select the Polarity and set the CCE Bit */ + tmpccer &= CCER_CC1P_Mask & CCRE_CC1E_Mask; + tmpccer |= tmp | CCRE_CC3E_Set; + + TIMx->CCMR2 = (u16)tmpccmr2; + TIMx->CCER = (u16)tmpccer; +} + +/******************************************************************************* +* Function Name : TI4_Config +* Description : Configure the TI1 as Input. +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_ICPolarity : The Input Polarity. +* This parameter can be one of the following values: +* - TIM_ICPolarity_Rising +* - TIM_ICPolarity_Falling +* - TIM_ICSelection: specifies the input to be used. +* This parameter can be one of the following values: +* - TIM_ICSelection_DirectTI: TIM Input 4 is selected to +* be connected to IC4. +* - TIM_ICSelection_IndirectTI: TIM Input 4 is selected to +* be connected to IC3. +* - TIM_ICSelection_TRGI: TIM Input 4 is selected to be +* connected to TRGI. +* - TIM_ICFilter: Specifies the Input Capture Filter. +* This parameter must be a value between 0x00 and 0x0F. +* Output : None +* Return : None +*******************************************************************************/ +static void TI4_Config(TIM_TypeDef* TIMx, u16 TIM_ICPolarity, u16 TIM_ICSelection, + u8 TIM_ICFilter) +{ + u32 tmpccmr2 = 0, tmpccer = 0, tmp = 0; + + tmpccmr2 = TIMx->CCMR2; + tmpccer = TIMx->CCER; + tmp = (u16)((u16)TIM_ICPolarity << 12); + + /* Disable the Channel 4: Reset the CCE Bit */ + TIMx->CCER &= CCRE_CC4E_Reset; + + /* Select the Input and set the filter */ + tmpccmr2 &= CCMR_CC24S_Mask & CCMR_IC24F_Mask; + tmpccmr2 |= (u16)((u16)TIM_ICSelection << 8) | (u16)((u16)TIM_ICFilter << 12); + + /* Select the Polarity and set the CCE Bit */ + tmpccer &= CCER_CC4P_Mask & CCRE_CC4E_Mask; + tmpccer |= tmp | CCRE_CC4E_Set; + + TIMx->CCMR2 = (u16)tmpccmr2; + TIMx->CCER = (u16)tmpccer ; +} + +/******************************************************************************* +* Function Name : ETR_Config +* Description : Configure the External Trigger +* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral. +* - TIM_ExtTRGPrescaler: The external Trigger Prescaler. +* This parameter can be one of the following values: +* - TIM_ExtTRGPSC_OFF +* - TIM_ExtTRGPSC_DIV2 +* - TIM_ExtTRGPSC_DIV4 +* - TIM_ExtTRGPSC_DIV8 +* - TIM_ExtTRGPolarity: The external Trigger Polarity. +* This parameter can be one of the following values: +* - TIM_ExtTRGPolarity_Inverted +* - TIM_ExtTRGPolarity_NonInverted +* - ExtTRGFilter: External Trigger Filter. +* This parameter must be a value between 0x00 and 0x0F. +* Output : None +* Return : None +*******************************************************************************/ +static void ETR_Config(TIM_TypeDef* TIMx, u16 TIM_ExtTRGPrescaler, u16 TIM_ExtTRGPolarity, + u8 ExtTRGFilter) +{ + u32 tmpsmcr = 0; + + tmpsmcr = TIMx->SMCR; + + /* Set the Prescaler, the Filter value and the Polarity */ + tmpsmcr &= SMCR_ETR_Mask; + tmpsmcr |= TIM_ExtTRGPrescaler | TIM_ExtTRGPolarity | (u16)((u16)ExtTRGFilter << 8); + + TIMx->SMCR = (u16)tmpsmcr; +} +/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/ diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/bitmap.h b/Demo/CORTEX_STM32F103_Primer_GCC/bitmap.h new file mode 100644 index 000000000..2d0c5d062 --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/bitmap.h @@ -0,0 +1,3361 @@ +/* + FreeRTOS.org V4.6.1 - Copyright (C) 2003-2007 Richard Barry. + + This file is part of the FreeRTOS.org distribution. + + FreeRTOS.org is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FreeRTOS.org is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FreeRTOS.org; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + A special exception to the GPL can be applied should you wish to distribute + a combined work that includes FreeRTOS.org, without being obliged to provide + the source code for any proprietary components. See the licensing section + of http://www.FreeRTOS.org for full details of how and when the exception + can be applied. + + *************************************************************************** + See http://www.FreeRTOS.org for documentation, latest information, license + and contact details. Please ensure to read the configuration and relevant + port sections of the online documentation. + + Also see http://www.SafeRTOS.com a version that has been certified for use + in safety critical systems, plus commercial licensing, development and + support options. + *************************************************************************** +*/ + +/* FreeRTOS.org Logo as a 16bit bitmap. */ + +#ifndef BITMAP_H +#define BITMAP_H + +const unsigned short pucImage[] = +{ +0xffff, +0xffff, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xffff, +0xffff, +0xffff, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xffff, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xc318, +0x0842, +0x8210, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0c63, +0xffff, +0x0842, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0x0000, +0x8631, +0x38c6, +0x38c6, +0x38c6, +0x38c6, +0xfbde, +0xffff, +0xbad6, +0x38c6, +0xcb5a, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x3ce7, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0x0000, +0x0842, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0x4529, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0842, +0x0000, +0x8210, +0x0842, +0x0842, +0x0842, +0x0842, +0x718c, +0xffff, +0x8e73, +0xb6b5, +0xffff, +0x0c63, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0c63, +0xffff, +0x0842, +0x0c63, +0xffff, +0x0c63, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0c63, +0xffff, +0x0c63, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x031a, +0xe73c, +0x2b5f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x294e, +0xa73c, +0xc108, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x4000, +0x452b, +0x6845, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x2845, +0x031a, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x8422, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x8631, +0x38c6, +0x38c6, +0x38c6, +0xf7bd, +0x38c6, +0x38c6, +0x8631, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x8108, +0xa94d, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0422, +0x0000, +0x0000, +0x0000, +0x0000, +0xc319, +0x2c67, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xe94d, +0xc210, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xc210, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x4211, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0842, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0xffff, +0x0842, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x6a56, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0109, +0x0000, +0x0000, +0x0000, +0x431a, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xeb5e, +0x0211, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe94d, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x2634, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0421, +0x3084, +0x3084, +0x3084, +0xb294, +0xffff, +0xf7bd, +0x8210, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x8422, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x6c67, +0x294e, +0x2a56, +0x2a56, +0x2a56, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0xc108, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x2c67, +0x2a56, +0x2a56, +0xac67, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x6a56, +0x4108, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x052b, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xb294, +0xffff, +0x494a, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0xa94d, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xe94d, +0x4000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xc422, +0x2845, +0x0000, +0x0000, +0x0000, +0xa94d, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xec67, +0x452b, +0x0000, +0x0000, +0x0000, +0x8108, +0x2845, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x852b, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x4108, +0xac67, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0211, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0c63, +0x38c6, +0x494a, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x2c67, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x852b, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x8108, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x673c, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xaa56, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xeb5e, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x694d, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xa73c, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x8210, +0xf39c, +0xbef7, +0xffff, +0x75ad, +0x0421, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0xaa56, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x2a56, +0x4000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0423, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xc108, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x8422, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0211, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x431a, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xc108, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x38c6, +0xffff, +0xffff, +0xffff, +0xffff, +0x79ce, +0x4108, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0xea55, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x2c67, +0x452b, +0x0211, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe844, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x6a56, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x4000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x8422, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x4108, +0x6b5f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x452b, +0x0422, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x8631, +0xffff, +0x38c6, +0xf7bd, +0xf7bd, +0xb294, +0xffff, +0x494a, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x452b, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xab5e, +0x852b, +0xc108, +0x0000, +0x0000, +0x0000, +0x0000, +0x294e, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xe844, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xeb5e, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x8633, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x8633, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0c63, +0xffff, +0x0842, +0x34a5, +0xf39c, +0x4108, +0xffff, +0x0c63, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x294e, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xec67, +0x8633, +0x0000, +0x0000, +0x0000, +0x2a56, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x2634, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x2a56, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x2634, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xa844, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x8a52, +0xffff, +0x8631, +0x34a5, +0xf7bd, +0xf39c, +0xffff, +0x494a, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x4000, +0xa73c, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xec67, +0x273c, +0x0000, +0x0000, +0xe94d, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x673c, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xaa56, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x273c, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0109, +0x6a56, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x4529, +0xffff, +0x0c63, +0x34a5, +0xffff, +0xffff, +0xb6b5, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xc108, +0x8633, +0x2a56, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xec67, +0xc210, +0x0000, +0xa94d, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xa94d, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x6c67, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x052b, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x4000, +0xeb5e, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xa94d, +0x273c, +0x8422, +0x0422, +0x2845, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0842, +0x4529, +0xcf7b, +0xb6b5, +0x0c63, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xc108, +0x052b, +0xeb5e, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0423, +0x0000, +0xc633, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x2b5f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0211, +0xec67, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x031a, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x052b, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xa94d, +0x0000, +0x0000, +0x0000, +0x0000, +0x273c, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0xc318, +0xc318, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x4108, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x273c, +0x0000, +0x0422, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0422, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xa73c, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x4000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe73c, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x4633, +0x0000, +0x0000, +0x0000, +0x0000, +0x2634, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0421, +0xbad6, +0xffff, +0xffff, +0x3ce7, +0x0842, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x2b5f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xc633, +0x0000, +0x4000, +0x6c67, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xeb5e, +0x8108, +0x0000, +0x0000, +0x0000, +0x0000, +0x8211, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x6845, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe94d, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xe94d, +0x0000, +0x0000, +0x0000, +0x0000, +0x273c, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0000, +0xfbde, +0xffff, +0xffff, +0xffff, +0xffff, +0x3ce7, +0x8210, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x2634, +0xa94d, +0x452b, +0x0422, +0x031a, +0x0422, +0xc422, +0xea55, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xc319, +0x0000, +0x0000, +0x452b, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x2b5f, +0x4633, +0x031a, +0x0422, +0x673c, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xec67, +0x8319, +0x0000, +0x0422, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x8108, +0x0000, +0xa73c, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x6a56, +0x273c, +0x031a, +0x0422, +0x2845, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0842, +0xffff, +0x34a5, +0xb6b5, +0x34a5, +0x8e73, +0xffff, +0xcb5a, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x2845, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x6a56, +0x0000, +0x0000, +0x0000, +0x0000, +0x6845, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xc633, +0x0000, +0x0000, +0x2634, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0211, +0x0000, +0x8319, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x0c63, +0xffff, +0x8631, +0x34a5, +0xf39c, +0x4108, +0xffff, +0x0c63, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0xe94d, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xeb5e, +0x0109, +0x0000, +0x0000, +0x0000, +0x0000, +0x4108, +0xe94d, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xc633, +0x0000, +0x0000, +0x0000, +0x273c, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0211, +0x0000, +0x0000, +0x273c, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0x8a52, +0xffff, +0xc739, +0x34a5, +0xbad6, +0x38c6, +0xffff, +0x8631, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x6a56, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x673c, +0x8000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xc422, +0x2b5f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xe94d, +0xc319, +0x0000, +0x0000, +0x0000, +0x0000, +0x2634, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0211, +0x0000, +0x0000, +0x0000, +0x8422, +0x6a56, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0xed6f, +0x0000, +0xc318, +0xffff, +0x8e73, +0x34a5, +0xffff, +0xffff, +0x718c, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0422, +0xc633, +0x273c, +0xa73c, +0xe844, +0x2634, +0xc633, +0x031a, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x8319, +0x052b, +0x273c, +0x2845, +0xa844, +0x2634, +0x8422, +0x0211, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0211, +0x031a, +0x0422, +0x031a, +0x0422, +0x031a, +0x0422, +0x031a, +0x0422, +0x031a, +0x0422, +0x031a, +0x0422, +0x031a, +0x0422, +0x4000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x8108, +0x0422, +0x031a, +0x0422, +0x031a, +0x0422, +0x031a, +0x0422, +0x031a, +0x0422, +0x031a, +0x4211, +0x0000, +0x0000, +0x0000, +0x0000, +0x8a52, +0x3084, +0xc739, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0x0000, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xffff, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xffff, +0xffff, +0xffff, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xe006, +0xffff, +0xffff +}; + +#define bmpBITMAP_WIDTH 92 +#define bmpBITMAP_HEIGHT 36 + +#endif diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/main.c b/Demo/CORTEX_STM32F103_Primer_GCC/main.c new file mode 100644 index 000000000..fbb16cb74 --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/main.c @@ -0,0 +1,465 @@ +/* + FreeRTOS.org V4.6.1 - Copyright (C) 2003-2007 Richard Barry. + + This file is part of the FreeRTOS.org distribution. + + FreeRTOS.org is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FreeRTOS.org is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FreeRTOS.org; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + A special exception to the GPL can be applied should you wish to distribute + a combined work that includes FreeRTOS.org, without being obliged to provide + the source code for any proprietary components. See the licensing section + of http://www.FreeRTOS.org for full details of how and when the exception + can be applied. + + *************************************************************************** + See http://www.FreeRTOS.org for documentation, latest information, license + and contact details. Please ensure to read the configuration and relevant + port sections of the online documentation. + + Also see http://www.SafeRTOS.com a version that has been certified for use + in safety critical systems, plus commercial licensing, development and + support options. + *************************************************************************** +*/ + +/* + * Creates all the demo application tasks, then starts the scheduler. The WEB + * documentation provides more details of the standard demo application tasks. + * In addition to the standard demo tasks, the following tasks and tests are + * defined and/or created within this file: + * + * "Fast Interrupt Test" - A high frequency periodic interrupt is generated + * using a free running timer to demonstrate the use of the + * configKERNEL_INTERRUPT_PRIORITY configuration constant. The interrupt + * service routine measures the number of processor clocks that occur between + * each interrupt - and in so doing measures the jitter in the interrupt timing. + * The maximum measured jitter time is latched in the ulMaxJitter variable, and + * displayed on the LCD by the 'Check' task as described below. The + * fast interrupt is configured and handled in the timertest.c source file. + * + * "LCD" task - the LCD task is a 'gatekeeper' task. It is the only task that + * is permitted to access the display directly. Other tasks wishing to write a + * message to the LCD send the message on a queue to the LCD task instead of + * accessing the LCD themselves. The LCD task just blocks on the queue waiting + * for messages - waking and displaying the messages as they arrive. Messages + * can either be a text string to display, or an instruction to update MEMS + * input. The MEMS input is used to display a ball that can be moved around + * LCD by tilting the STM32 Primer. 45% is taken as the neutral position. + * + * "Check" task - This only executes every five seconds but has the highest + * priority so is guaranteed to get processor time. Its main function is to + * check that all the standard demo tasks are still operational. Should any + * unexpected behaviour within a demo task be discovered the 'check' task will + * write an error to the LCD (via the LCD task). If all the demo tasks are + * executing with their expected behaviour then the check task writes PASS + * along with the max jitter time to the LCD (again via the LCD task), as + * described above. + * + * Tick Hook - A tick hook is provided just for demonstration purposes. In + * this case it is used to periodically send an instruction to updated the + * MEMS input to the LCD task. + * + */ + +/* CircleOS includes. Some of the CircleOS peripheral functionality is +utilised, although CircleOS itself is not used. */ +#include "circle.h" + +/* Standard includes. */ +#include + +/* Scheduler includes. */ +#include "FreeRTOS.h" +#include "Task.h" +#include "Queue.h" + +/* Demo app includes. */ +#include "BlockQ.h" +#include "blocktim.h" +#include "GenQTest.h" +#include "partest.h" +#include "QPeek.h" + +/* The bitmap used to display the FreeRTOS.org logo is stored in 16bit format +and therefore takes up a large proportion of the Flash space. Setting this +parameter to 0 excludes the bitmap from the build, freeing up Flash space for +extra code. */ +#define mainINCLUDE_BITMAP 1 + +#if mainINCLUDE_BITMAP == 1 + #include "bitmap.h" +#endif + +/* Task priorities. */ +#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 ) +#define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 ) +#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 ) +#define mainGEN_Q_PRIORITY ( tskIDLE_PRIORITY + 0 ) +#define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 ) + +/* Splash screen related constants. */ +#define mainBITMAP_Y ( 38 ) +#define mainBITMAP_X ( 18 ) +#define mainURL_Y ( 8 ) +#define mainURL_X ( 78 ) +#define mainSPLASH_SCREEN_DELAY ( 2000 / portTICK_RATE_MS ) + +/* Text drawing related constants. */ +#define mainLCD_CHAR_HEIGHT ( 13 ) +#define mainLCD_MAX_Y ( 110 ) + +/* The maximum number of message that can be waiting for display at any one +time. */ +#define mainLCD_QUEUE_SIZE ( 3 ) + +/* The check task uses the sprintf function so requires a little more stack. */ +#define mainCHECK_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE + 50 ) + +/* The LCD task calls some of the CircleOS functions (for MEMS and LCD access), +these can require a larger stack. */ +#define configLCD_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE + 50 ) + +/* Dimensions the buffer into which the jitter time is written. */ +#define mainMAX_MSG_LEN 25 + +/* The time between cycles of the 'check' task. */ +#define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS ) + +/* The period at which the MEMS input should be updated. */ +#define mainMEMS_DELAY ( ( portTickType ) 100 / portTICK_RATE_MS ) + +/* The rate at which the flash task toggles the LED. */ +#define mainFLASH_DELAY ( ( portTickType ) 1000 / portTICK_RATE_MS ) + +/* The number of nano seconds between each processor clock. */ +#define mainNS_PER_CLOCK ( ( unsigned portLONG ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) ) + +/* The two types of message that can be sent to the LCD task. */ +#define mainUPDATE_BALL_MESSAGE ( 0 ) +#define mainWRITE_STRING_MESSAGE ( 1 ) + +/* Type of the message sent to the LCD task. */ +typedef struct +{ + portBASE_TYPE xMessageType; + signed char *pcMessage; +} xLCDMessage; + +/*-----------------------------------------------------------*/ + +/* + * Configure the clocks, GPIO and other peripherals as required by the demo. + */ +static void prvSetupHardware( void ); + +/* + * The LCD is written two by more than one task so is controlled by a + * 'gatekeeper' task. This is the only task that is actually permitted to + * access the LCD directly. Other tasks wanting to display a message send + * the message to the gatekeeper. + */ +static void prvLCDTask( void *pvParameters ); + +/* + * Checks the status of all the demo tasks then prints a message to the + * display. The message will be either PASS - and include in brackets the + * maximum measured jitter time (as described at the to of the file), or a + * message that describes which of the standard demo tasks an error has been + * discovered in. + * + * Messages are not written directly to the terminal, but passed to prvLCDTask + * via a queue. + * + * The check task also receives instructions to update the MEMS input, which + * in turn can also lead to the LCD being updated. + */ +static void prvCheckTask( void *pvParameters ); + +/* + * Configures the timers and interrupts for the fast interrupt test as + * described at the top of this file. + */ +extern void vSetupTimerTest( void ); + +/* + * A cut down version of sprintf() used to percent the HUGE GCC library + * equivalent from being included in the binary image. + */ +extern int sprintf(char *out, const char *format, ...); + +/* + * Simple toggle the LED periodically for timing verification. + */ +static void prvFlashTask( void *pvParameters ); + +/*-----------------------------------------------------------*/ + +/* The queue used to send messages to the LCD task. */ +xQueueHandle xLCDQueue; + +/*-----------------------------------------------------------*/ + +int main( void ) +{ + #ifdef DEBUG + debug(); + #endif + + prvSetupHardware(); + + /* Create the queue used by the LCD task. Messages for display on the LCD + are received via this queue. */ + xLCDQueue = xQueueCreate( mainLCD_QUEUE_SIZE, sizeof( xLCDMessage ) ); + + /* Start the standard demo tasks. */ + vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY ); + vCreateBlockTimeTasks(); + vStartGenericQueueTasks( mainGEN_Q_PRIORITY ); + vStartQueuePeekTasks(); + vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY ); + + /* Start the tasks defined within this file/specific to this demo. */ + xTaskCreate( prvCheckTask, ( signed portCHAR * ) "Check", mainCHECK_TASK_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL ); + xTaskCreate( prvLCDTask, ( signed portCHAR * ) "LCD", configLCD_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); + xTaskCreate( prvFlashTask, ( signed portCHAR * ) "Flash", configMINIMAL_STACK_SIZE, NULL, mainFLASH_TASK_PRIORITY, NULL ); + + /* Configure the timers used by the fast interrupt timer test. */ + vSetupTimerTest(); + + /* Start the scheduler. */ + vTaskStartScheduler(); + + /* Will only get here if there was not enough heap space to create the + idle task. */ + return 0; +} +/*-----------------------------------------------------------*/ + +void prvLCDTask( void *pvParameters ) +{ +xLCDMessage xMessage; +portCHAR cY = mainLCD_CHAR_HEIGHT; +const portCHAR * const pcString = "www.FreeRTOS.org"; +const portCHAR * const pcBlankLine = " "; + + DRAW_Init(); + + #if mainINCLUDE_BITMAP == 1 + DRAW_SetImage( pucImage, mainBITMAP_Y, mainBITMAP_X, bmpBITMAP_HEIGHT, bmpBITMAP_WIDTH ); + #endif + + LCD_SetScreenOrientation( V9 ); + DRAW_DisplayString( mainURL_Y, mainURL_X, pcString, strlen( pcString ) ); + vTaskDelay( mainSPLASH_SCREEN_DELAY ); + LCD_FillRect( 0, 0, CHIP_SCREEN_WIDTH, CHIP_SCREEN_HEIGHT, RGB_WHITE ); + + for( ;; ) + { + /* Wait for a message to arrive that requires displaying. */ + while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS ); + + /* Check the message type. */ + if( xMessage.xMessageType == mainUPDATE_BALL_MESSAGE ) + { + /* Read the MEMS and update the ball display on the LCD if required. */ + MEMS_Handler(); + POINTER_Handler(); + } + else + { + /* A text string was sent. First blank off the old text string, then + draw the new text on the next line down. */ + DRAW_DisplayString( 0, cY, pcBlankLine, strlen( pcBlankLine ) ); + + cY -= mainLCD_CHAR_HEIGHT; + if( cY <= ( mainLCD_CHAR_HEIGHT - 1 ) ) + { + /* Wrap the line onto which we are going to write the text. */ + cY = mainLCD_MAX_Y; + } + + /* Display the message. */ + DRAW_DisplayString( 0, cY, xMessage.pcMessage, strlen( xMessage.pcMessage ) ); + } + } +} +/*-----------------------------------------------------------*/ + +static void prvCheckTask( void *pvParameters ) +{ +portTickType xLastExecutionTime; +xLCDMessage xMessage; +static signed portCHAR cPassMessage[ mainMAX_MSG_LEN ]; +extern unsigned portSHORT usMaxJitter; + + /* Initialise the xLastExecutionTime variable on task entry. */ + xLastExecutionTime = xTaskGetTickCount(); + + /* Setup the message we are going to send to the LCD task. */ + xMessage.xMessageType = mainWRITE_STRING_MESSAGE; + xMessage.pcMessage = cPassMessage; + + for( ;; ) + { + /* Perform this check every mainCHECK_DELAY milliseconds. */ + vTaskDelayUntil( &xLastExecutionTime, mainCHECK_DELAY ); + + /* Has an error been found in any task? If so then point the text + we are going to send to the LCD task to an error message instead of + the PASS message. */ + if( xAreGenericQueueTasksStillRunning() != pdTRUE ) + { + xMessage.pcMessage = "ERROR IN GEN Q"; + } + if( xAreBlockingQueuesStillRunning() != pdTRUE ) + { + xMessage.pcMessage = "ERROR IN BLOCK Q"; + } + else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE ) + { + xMessage.pcMessage = "ERROR IN BLOCK TIME"; + } + else if( xArePollingQueuesStillRunning() != pdTRUE ) + { + xMessage.pcMessage = "ERROR IN POLL Q"; + } + else if( xAreQueuePeekTasksStillRunning() != pdTRUE ) + { + xMessage.pcMessage = "ERROR IN PEEK Q"; + } + else + { + /* No errors were found in any task, so send a pass message + with the max measured jitter time also included (as per the + fast interrupt test described at the top of this file and on + the online documentation page for this demo application). */ + sprintf( ( portCHAR * ) cPassMessage, "PASS [%uns]", ( ( unsigned portLONG ) usMaxJitter ) * mainNS_PER_CLOCK ); + } + + /* Send the message to the LCD gatekeeper for display. */ + xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY ); + } +} +/*-----------------------------------------------------------*/ + +void vApplicationTickHook( void ) +{ +static unsigned portLONG ulCallCount; +static const xLCDMessage xMemsMessage = { mainUPDATE_BALL_MESSAGE, NULL }; + + /* Periodically send a message to the LCD task telling it to update + the MEMS input, and then if necessary the LCD. */ + ulCallCount++; + if( ulCallCount >= mainMEMS_DELAY ) + { + ulCallCount = 0; + xQueueSendFromISR( xLCDQueue, &xMemsMessage, pdFALSE ); + } +} +/*-----------------------------------------------------------*/ + +static void prvSetupHardware( void ) +{ + /* Start with the clocks in their expected state. */ + RCC_DeInit(); + + /* Enable HSE (high speed external clock). */ + RCC_HSEConfig( RCC_HSE_ON ); + + /* Wait till HSE is ready. */ + while( RCC_GetFlagStatus( RCC_FLAG_HSERDY ) == RESET ) + { + } + + /* 2 wait states required on the flash. */ + *( ( unsigned portLONG * ) 0x40022000 ) = 0x02; + + /* HCLK = SYSCLK */ + RCC_HCLKConfig( RCC_SYSCLK_Div1 ); + + /* PCLK2 = HCLK */ + RCC_PCLK2Config( RCC_HCLK_Div1 ); + + /* PCLK1 = HCLK/2 */ + RCC_PCLK1Config( RCC_HCLK_Div2 ); + + /* PLLCLK = 12MHz * 6 = 72 MHz. */ + RCC_PLLConfig( RCC_PLLSource_HSE_Div1, RCC_PLLMul_6 ); + + /* Enable PLL. */ + RCC_PLLCmd( ENABLE ); + + /* Wait till PLL is ready. */ + while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) + { + } + + /* Select PLL as system clock source. */ + RCC_SYSCLKConfig( RCC_SYSCLKSource_PLLCLK ); + + /* Wait till PLL is used as system clock source. */ + while( RCC_GetSYSCLKSource() != 0x08 ) + { + } + + /* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE and AFIO clocks */ + RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC + | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE ); + + /* SPI2 Periph clock enable */ + RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE ); + + + /* Set the Vector Table base address at 0x08000000 */ + NVIC_SetVectorTable( NVIC_VectTab_FLASH, 0x0 ); + + NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 ); + + /* Configure HCLK clock as SysTick clock source. */ + SysTick_CLKSourceConfig( SysTick_CLKSource_HCLK ); + + /* Misc initialisation, including some of the CircleOS features. Note + that CircleOS itself is not used. */ + vParTestInitialise(); + MEMS_Init(); + POINTER_Init(); + POINTER_SetMode( POINTER_RESTORE_LESS ); +} +/*-----------------------------------------------------------*/ + +static void prvFlashTask( void *pvParameters ) +{ +portTickType xLastExecutionTime; + + /* Initialise the xLastExecutionTime variable on task entry. */ + xLastExecutionTime = xTaskGetTickCount(); + + for( ;; ) + { + /* Simple toggle the LED periodically. This just provides some timing + verification. */ + vTaskDelayUntil( &xLastExecutionTime, mainFLASH_DELAY ); + vParTestToggleLED( 0 ); + } +} +/*-----------------------------------------------------------*/ + +void starting_delay( unsigned long ul ) +{ + vTaskDelay( ( portTickType ) ul ); +} + + + diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/printf-stdarg.c b/Demo/CORTEX_STM32F103_Primer_GCC/printf-stdarg.c new file mode 100644 index 000000000..45a824384 --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/printf-stdarg.c @@ -0,0 +1,280 @@ +/* + Copyright 2001, 2002 Georges Menie (www.menie.org) + stdarg version contributed by Christian Ettinger + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + putchar is the only external dependency for this file, + if you have a working putchar, leave it commented out. + If not, uncomment the define below and + replace outbyte(c) by your own function call. + +#define putchar(c) outbyte(c) +*/ + +#include + +static void printchar(char **str, int c) +{ + extern int putchar(int c); + + if (str) { + **str = c; + ++(*str); + } + else (void)putchar(c); +} + +#define PAD_RIGHT 1 +#define PAD_ZERO 2 + +static int prints(char **out, const char *string, int width, int pad) +{ + register int pc = 0, padchar = ' '; + + if (width > 0) { + register int len = 0; + register const char *ptr; + for (ptr = string; *ptr; ++ptr) ++len; + if (len >= width) width = 0; + else width -= len; + if (pad & PAD_ZERO) padchar = '0'; + } + if (!(pad & PAD_RIGHT)) { + for ( ; width > 0; --width) { + printchar (out, padchar); + ++pc; + } + } + for ( ; *string ; ++string) { + printchar (out, *string); + ++pc; + } + for ( ; width > 0; --width) { + printchar (out, padchar); + ++pc; + } + + return pc; +} + +/* the following should be enough for 32 bit int */ +#define PRINT_BUF_LEN 12 + +static int printi(char **out, int i, int b, int sg, int width, int pad, int letbase) +{ + char print_buf[PRINT_BUF_LEN]; + register char *s; + register int t, neg = 0, pc = 0; + register unsigned int u = i; + + if (i == 0) { + print_buf[0] = '0'; + print_buf[1] = '\0'; + return prints (out, print_buf, width, pad); + } + + if (sg && b == 10 && i < 0) { + neg = 1; + u = -i; + } + + s = print_buf + PRINT_BUF_LEN-1; + *s = '\0'; + + while (u) { + t = u % b; + if( t >= 10 ) + t += letbase - '0' - 10; + *--s = t + '0'; + u /= b; + } + + if (neg) { + if( width && (pad & PAD_ZERO) ) { + printchar (out, '-'); + ++pc; + --width; + } + else { + *--s = '-'; + } + } + + return pc + prints (out, s, width, pad); +} + +static int print( char **out, const char *format, va_list args ) +{ + register int width, pad; + register int pc = 0; + char scr[2]; + + for (; *format != 0; ++format) { + if (*format == '%') { + ++format; + width = pad = 0; + if (*format == '\0') break; + if (*format == '%') goto out; + if (*format == '-') { + ++format; + pad = PAD_RIGHT; + } + while (*format == '0') { + ++format; + pad |= PAD_ZERO; + } + for ( ; *format >= '0' && *format <= '9'; ++format) { + width *= 10; + width += *format - '0'; + } + if( *format == 's' ) { + register char *s = (char *)va_arg( args, int ); + pc += prints (out, s?s:"(null)", width, pad); + continue; + } + if( *format == 'd' ) { + pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a'); + continue; + } + if( *format == 'x' ) { + pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a'); + continue; + } + if( *format == 'X' ) { + pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A'); + continue; + } + if( *format == 'u' ) { + pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a'); + continue; + } + if( *format == 'c' ) { + /* char are converted to int then pushed on the stack */ + scr[0] = (char)va_arg( args, int ); + scr[1] = '\0'; + pc += prints (out, scr, width, pad); + continue; + } + } + else { + out: + printchar (out, *format); + ++pc; + } + } + if (out) **out = '\0'; + va_end( args ); + return pc; +} + +int printf(const char *format, ...) +{ + va_list args; + + va_start( args, format ); + return print( 0, format, args ); +} + +int sprintf(char *out, const char *format, ...) +{ + va_list args; + + va_start( args, format ); + return print( &out, format, args ); +} + + +int snprintf( char *buf, unsigned int count, const char *format, ... ) +{ + va_list args; + + ( void ) count; + + va_start( args, format ); + return print( &buf, format, args ); +} + + +#ifdef TEST_PRINTF +int main(void) +{ + char *ptr = "Hello world!"; + char *np = 0; + int i = 5; + unsigned int bs = sizeof(int)*8; + int mi; + char buf[80]; + + mi = (1 << (bs-1)) + 1; + printf("%s\n", ptr); + printf("printf test\n"); + printf("%s is null pointer\n", np); + printf("%d = 5\n", i); + printf("%d = - max int\n", mi); + printf("char %c = 'a'\n", 'a'); + printf("hex %x = ff\n", 0xff); + printf("hex %02x = 00\n", 0); + printf("signed %d = unsigned %u = hex %x\n", -3, -3, -3); + printf("%d %s(s)%", 0, "message"); + printf("\n"); + printf("%d %s(s) with %%\n", 0, "message"); + sprintf(buf, "justif: \"%-10s\"\n", "left"); printf("%s", buf); + sprintf(buf, "justif: \"%10s\"\n", "right"); printf("%s", buf); + sprintf(buf, " 3: %04d zero padded\n", 3); printf("%s", buf); + sprintf(buf, " 3: %-4d left justif.\n", 3); printf("%s", buf); + sprintf(buf, " 3: %4d right justif.\n", 3); printf("%s", buf); + sprintf(buf, "-3: %04d zero padded\n", -3); printf("%s", buf); + sprintf(buf, "-3: %-4d left justif.\n", -3); printf("%s", buf); + sprintf(buf, "-3: %4d right justif.\n", -3); printf("%s", buf); + + return 0; +} + +/* + * if you compile this file with + * gcc -Wall $(YOUR_C_OPTIONS) -DTEST_PRINTF -c printf.c + * you will get a normal warning: + * printf.c:214: warning: spurious trailing `%' in format + * this line is testing an invalid % at the end of the format string. + * + * this should display (on 32bit int machine) : + * + * Hello world! + * printf test + * (null) is null pointer + * 5 = 5 + * -2147483647 = - max int + * char a = 'a' + * hex ff = ff + * hex 00 = 00 + * signed -3 = unsigned 4294967293 = hex fffffffd + * 0 message(s) + * 0 message(s) with % + * justif: "left " + * justif: " right" + * 3: 0003 zero padded + * 3: 3 left justif. + * 3: 3 right justif. + * -3: -003 zero padded + * -3: -3 left justif. + * -3: -3 right justif. + */ + +#endif + + diff --git a/Demo/CORTEX_STM32F103_Primer_GCC/timertest.c b/Demo/CORTEX_STM32F103_Primer_GCC/timertest.c new file mode 100644 index 000000000..98cc65435 --- /dev/null +++ b/Demo/CORTEX_STM32F103_Primer_GCC/timertest.c @@ -0,0 +1,170 @@ +/* + FreeRTOS.org V4.6.1 - Copyright (C) 2003-2007 Richard Barry. + + This file is part of the FreeRTOS.org distribution. + + FreeRTOS.org is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FreeRTOS.org is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FreeRTOS.org; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + A special exception to the GPL can be applied should you wish to distribute + a combined work that includes FreeRTOS.org, without being obliged to provide + the source code for any proprietary components. See the licensing section + of http://www.FreeRTOS.org for full details of how and when the exception + can be applied. + + *************************************************************************** + See http://www.FreeRTOS.org for documentation, latest information, license + and contact details. Please ensure to read the configuration and relevant + port sections of the online documentation. + + Also see http://www.SafeRTOS.com a version that has been certified for use + in safety critical systems, plus commercial licensing, development and + support options. + *************************************************************************** +*/ + +/* High speed timer test as described in main.c. */ + +/* Scheduler includes. */ +#include "FreeRTOS.h" + +/* Library includes. */ +#include "stm32f10x_lib.h" +#include "stm32f10x_tim.h" +#include "stm32f10x_map.h" + +/* The set frequency of the interrupt. Deviations from this are measured as +the jitter. */ +#define timerINTERRUPT_FREQUENCY ( ( unsigned portSHORT ) 20000 ) + +/* The expected time between each of the timer interrupts - if the jitter was +zero. */ +#define timerEXPECTED_DIFFERENCE_VALUE ( configCPU_CLOCK_HZ / timerINTERRUPT_FREQUENCY ) + +/* The highest available interrupt priority. */ +#define timerHIGHEST_PRIORITY ( 0 ) + +/* Misc defines. */ +#define timerMAX_32BIT_VALUE ( 0xffffffffUL ) +#define timerTIMER_1_COUNT_VALUE ( * ( ( unsigned long * ) ( TIMER1_BASE + 0x48 ) ) ) + +/* The number of interrupts to pass before we start looking at the jitter. */ +#define timerSETTLE_TIME 5 + +/*-----------------------------------------------------------*/ + +/* + * Configures the two timers used to perform the test. + */ +void vSetupTimerTest( void ); + +/* Interrupt handler in which the jitter is measured. */ +void vTimer2IntHandler( void ); + +/* Stores the value of the maximum recorded jitter between interrupts. */ +volatile unsigned portSHORT usMaxJitter = 0; + +/*-----------------------------------------------------------*/ + +void vSetupTimerTest( void ) +{ +unsigned long ulFrequency; +TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; +NVIC_InitTypeDef NVIC_InitStructure; + + + /* Enable timer clocks */ + RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM2, ENABLE ); + RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3, ENABLE ); + + /* Initialise data. */ + TIM_DeInit( TIM2 ); + TIM_DeInit( TIM3 ); + TIM_TimeBaseStructInit( &TIM_TimeBaseStructure ); + + /* Time base configuration for timer 2 - which generates the interrupts. */ + ulFrequency = configCPU_CLOCK_HZ / timerINTERRUPT_FREQUENCY; + TIM_TimeBaseStructure.TIM_Period = ( unsigned portSHORT ) ( ulFrequency & 0xffffUL ); + TIM_TimeBaseStructure.TIM_Prescaler = 0x0; + TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseInit( TIM2, &TIM_TimeBaseStructure ); + TIM_ARRPreloadConfig( TIM2, ENABLE ); + + + /* Configuration for timer 3 which is used as a high resolution time + measurement. */ + TIM_TimeBaseStructure.TIM_Period = ( unsigned portSHORT ) 0xffff; + TIM_TimeBaseInit( TIM3, &TIM_TimeBaseStructure ); + TIM_ARRPreloadConfig( TIM3, ENABLE ); + + /* Enable TIM2 IT. TIM3 does not generate an interrupt. */ + NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel; + NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = timerHIGHEST_PRIORITY; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init( &NVIC_InitStructure ); + TIM_ITConfig( TIM2, TIM_IT_Update, ENABLE ); + + /* Finally, enable both timers. */ + TIM_Cmd( TIM2, ENABLE ); + TIM_Cmd( TIM3, ENABLE ); +} +/*-----------------------------------------------------------*/ + +void vTimer2IntHandler( void ) +{ +static unsigned portSHORT usLastCount = 0, usSettleCount = 0, usMaxDifference = 0; +unsigned portSHORT usThisCount, usDifference; + + /* Capture the free running timer 3 value as we enter the interrupt. */ + usThisCount = TIM3->CNT; + + if( usSettleCount >= timerSETTLE_TIME ) + { + /* What is the difference between the timer value in this interrupt + and the value from the last interrupt. */ + usDifference = usThisCount - usLastCount; + + /* Store the difference in the timer values if it is larger than the + currently stored largest value. The difference over and above the + expected difference will give the 'jitter' in the processing of these + interrupts. */ + if( usDifference > usMaxDifference ) + { + usMaxDifference = usDifference; + usMaxJitter = usMaxDifference - timerEXPECTED_DIFFERENCE_VALUE; + } + } + else + { + /* Don't bother storing any values for the first couple of + interrupts. */ + usSettleCount++; + } + + /* Remember what the timer value was this time through, so we can calculate + the difference the next time through. */ + usLastCount = usThisCount; + + TIM_ClearITPendingBit( TIM2, TIM_IT_Update ); +} + + + + + + + + diff --git a/Source/include/portable.h b/Source/include/portable.h index 6c45fdf95..a00fdc3d4 100644 --- a/Source/include/portable.h +++ b/Source/include/portable.h @@ -153,6 +153,10 @@ #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" #endif +#ifdef GCC_ARMCM3 + #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" +#endif + #ifdef IAR_ARM_CM3 #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" #endif -- 2.39.5