Mercurial > ~darius > hgwebdir.cgi > stm32temp
comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/I2C/IOExpander/main.c @ 0:c59513fd84fb
Initial commit of STM32 test code.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 03 Oct 2011 21:19:15 +1030 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c59513fd84fb |
---|---|
1 /** | |
2 ****************************************************************************** | |
3 * @file I2C/IOExpander/main.c | |
4 * @author MCD Application Team | |
5 * @version V3.5.0 | |
6 * @date 08-April-2011 | |
7 * @brief Main program body | |
8 ****************************************************************************** | |
9 * @attention | |
10 * | |
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS | |
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE | |
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY | |
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING | |
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE | |
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. | |
17 * | |
18 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2> | |
19 ****************************************************************************** | |
20 */ | |
21 | |
22 /* Includes ------------------------------------------------------------------*/ | |
23 #include "main.h" | |
24 | |
25 /** @addtogroup STM32F10x_StdPeriph_Examples | |
26 * @{ | |
27 */ | |
28 | |
29 /** @addtogroup I2C_IOExpander | |
30 * @{ | |
31 */ | |
32 | |
33 /* Private typedef -----------------------------------------------------------*/ | |
34 /* Private define ------------------------------------------------------------*/ | |
35 #ifdef USE_STM3210C_EVAL | |
36 #define MESSAGE1 " STM3210C-EVAL " | |
37 #elif defined (USE_STM32100E_EVAL) | |
38 #define MESSAGE1 " STM32100E-EVAL " | |
39 #endif | |
40 | |
41 #define MESSAGE2 " Example on how to " | |
42 #define MESSAGE3 " use the IO Expander" | |
43 | |
44 /* Private macro -------------------------------------------------------------*/ | |
45 /* Private variables ---------------------------------------------------------*/ | |
46 /* Private function prototypes -----------------------------------------------*/ | |
47 /* Private functions ---------------------------------------------------------*/ | |
48 | |
49 /** | |
50 * @brief Main program. | |
51 * @param None | |
52 * @retval None | |
53 */ | |
54 int main(void) | |
55 { | |
56 /* Initialize LEDs and push-buttons mounted on STM3210X-EVAL board */ | |
57 STM_EVAL_LEDInit(LED1); | |
58 STM_EVAL_LEDInit(LED2); | |
59 STM_EVAL_LEDInit(LED3); | |
60 STM_EVAL_LEDInit(LED4); | |
61 | |
62 /* Initialize the LCD */ | |
63 #ifdef USE_STM3210C_EVAL | |
64 STM3210C_LCD_Init(); | |
65 #elif defined (USE_STM32100E_EVAL) | |
66 STM32100E_LCD_Init(); | |
67 #endif /* USE_STM3210C_EVAL */ | |
68 | |
69 /* Clear the LCD */ | |
70 LCD_Clear(White); | |
71 | |
72 /* Set the LCD Back Color */ | |
73 LCD_SetBackColor(Blue); | |
74 | |
75 /* Set the LCD Text Color */ | |
76 LCD_SetTextColor(White); | |
77 | |
78 /* Display messages on the LCD */ | |
79 LCD_DisplayStringLine(Line0, MESSAGE1); | |
80 LCD_DisplayStringLine(Line1, MESSAGE2); | |
81 LCD_DisplayStringLine(Line2, MESSAGE3); | |
82 | |
83 /* Configure the IO Expander */ | |
84 if (IOE_Config() == IOE_OK) | |
85 { | |
86 /* Display "IO Expander OK" on the LCD */ | |
87 LCD_DisplayStringLine(Line4, " IO Expander OK "); | |
88 } | |
89 else | |
90 { | |
91 LCD_DisplayStringLine(Line4, "IO Expander FAILED "); | |
92 LCD_DisplayStringLine(Line5, " Please Reset the "); | |
93 LCD_DisplayStringLine(Line6, " board and start "); | |
94 LCD_DisplayStringLine(Line7, " again "); | |
95 while(1); | |
96 } | |
97 | |
98 /* Draw a rectangle with the specifies parameters and Blue Color */ | |
99 LCD_SetTextColor(Blue); | |
100 LCD_DrawRect(180, 310, 40, 60); | |
101 | |
102 /* Draw a rectangle with the specifies parameters and Red Color */ | |
103 LCD_SetTextColor(Red); | |
104 LCD_DrawRect(180, 230, 40, 60); | |
105 | |
106 /* Draw a rectangle with the specifies parameters and Yellow Color */ | |
107 LCD_SetTextColor(Yellow); | |
108 LCD_DrawRect(180, 150, 40, 60); | |
109 | |
110 /* Draw a rectangle with the specifies parameters and Black Color */ | |
111 LCD_SetTextColor(Black); | |
112 LCD_DrawRect(180, 70, 40, 60); | |
113 | |
114 | |
115 #ifdef IOE_INTERRUPT_MODE | |
116 | |
117 #ifdef USE_STM32100E_EVAL | |
118 /* Enable the Touch Screen interrupts */ | |
119 IOE_ITConfig(IOE_ITSRC_TSC); | |
120 | |
121 #else | |
122 /* Enable the Touch Screen and Joystick interrupts */ | |
123 IOE_ITConfig(IOE_ITSRC_JOYSTICK | IOE_ITSRC_TSC); | |
124 #endif /* USE_STM32100E_EVAL */ | |
125 | |
126 #endif /* IOE_INTERRUPT_MODE */ | |
127 | |
128 /* Loop infinitely */ | |
129 while(1) | |
130 { | |
131 #ifdef IOE_POLLING_MODE | |
132 static TS_STATE* TS_State; | |
133 | |
134 #ifdef USE_STM3210C_EVAL | |
135 | |
136 static JOY_State_TypeDef JoyState = JOY_NONE; | |
137 | |
138 /* Get the Joytick State */ | |
139 JoyState = IOE_JoyStickGetState(); | |
140 | |
141 switch (JoyState) | |
142 { | |
143 /* None Joystick has been selected */ | |
144 case JOY_NONE: | |
145 LCD_DisplayStringLine(Line5, "JOY: ---- "); | |
146 break; | |
147 case JOY_UP: | |
148 LCD_DisplayStringLine(Line5, "JOY: UP "); | |
149 break; | |
150 case JOY_DOWN: | |
151 LCD_DisplayStringLine(Line5, "JOY: DOWN "); | |
152 break; | |
153 case JOY_LEFT: | |
154 LCD_DisplayStringLine(Line5, "JOY: LEFT "); | |
155 break; | |
156 case JOY_RIGHT: | |
157 LCD_DisplayStringLine(Line5, "JOY: RIGHT "); | |
158 break; | |
159 case JOY_CENTER: | |
160 LCD_DisplayStringLine(Line5, "JOY: CENTER "); | |
161 break; | |
162 default: | |
163 LCD_DisplayStringLine(Line5, "JOY: ERROR "); | |
164 break; | |
165 } | |
166 #endif /* USE_STM3210C_EVAL */ | |
167 | |
168 | |
169 /* Update the structure with the current position of the Touch screen */ | |
170 TS_State = IOE_TS_GetState(); | |
171 | |
172 if ((TS_State->TouchDetected) && (TS_State->Y < 220) && (TS_State->Y > 180)) | |
173 { | |
174 if ((TS_State->X > 10) && (TS_State->X < 70)) | |
175 { | |
176 /* Display LD4 on the LCD and turn on LED4 */ | |
177 LCD_DisplayStringLine(Line6, " LD4 "); | |
178 STM_EVAL_LEDOn(LED4); | |
179 } | |
180 else if ((TS_State->X > 90) && (TS_State->X < 150)) | |
181 { | |
182 /* Display LD3 on the LCD and turn on LED3 */ | |
183 LCD_DisplayStringLine(Line6, " LD3 "); | |
184 STM_EVAL_LEDOn(LED3); | |
185 } | |
186 else if ((TS_State->X > 170) && (TS_State->X < 230)) | |
187 { | |
188 /* Display LD2 on the LCD and turn on LED2 */ | |
189 LCD_DisplayStringLine(Line6, " LD2 "); | |
190 STM_EVAL_LEDOn(LED2); | |
191 } | |
192 else if ((TS_State->X > 250) && (TS_State->X < 310)) | |
193 { | |
194 /* Display LD1 on the LCD and turn on LED1 */ | |
195 LCD_DisplayStringLine(Line6, " LD1 "); | |
196 STM_EVAL_LEDOn(LED1); | |
197 } | |
198 | |
199 } | |
200 else | |
201 { | |
202 /* Turn off LED1..4 */ | |
203 STM_EVAL_LEDOff(LED1); | |
204 STM_EVAL_LEDOff(LED2); | |
205 STM_EVAL_LEDOff(LED3); | |
206 STM_EVAL_LEDOff(LED4); | |
207 } | |
208 | |
209 #endif /* IOE_POLLING_MODE */ | |
210 } | |
211 } | |
212 | |
213 #ifdef USE_FULL_ASSERT | |
214 | |
215 /** | |
216 * @brief Reports the name of the source file and the source line number | |
217 * where the assert_param error has occurred. | |
218 * @param file: pointer to the source file name | |
219 * @param line: assert_param error line source number | |
220 * @retval None | |
221 */ | |
222 void assert_failed(uint8_t* file, uint32_t line) | |
223 { | |
224 /* User can add his own implementation to report the file name and line number, | |
225 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | |
226 | |
227 LCD_DisplayStringLine(Line0, "assert_param error!!"); | |
228 | |
229 /* Infinite loop */ | |
230 while (1) | |
231 { | |
232 } | |
233 } | |
234 | |
235 #endif | |
236 | |
237 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ |