PageRenderTime 58ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/peripherals-interrupts-and-timers/Lab3_STM32F4Cube_Base_project/Sources/main.c

https://bitbucket.org/adi_saha/microprocessor-systems
C | 259 lines | 64 code | 36 blank | 159 comment | 1 complexity | a0d89a2e241fb1a2e9d36e2bd452a4b8 MD5 | raw file
  1. /**
  2. ******************************************************************************
  3. * File Name : main.c
  4. * Description : Main program subroutine
  5. * Author : Aditya Saha & Habib Ahmed (Original template by Ashraf Suyyagh)
  6. * Version : 1.0.0
  7. * Date : January 14th, 2016
  8. ******************************************************************************
  9. */
  10. /* Includes */
  11. #include "stm32f4xx_hal.h"
  12. #include "supporting_functions.h"
  13. #include "sys_config.h"
  14. #include "MEMS_config.h"
  15. #include "7seg_display.h"
  16. #include "gpio_config.h"
  17. #include "keypad.h"
  18. #include "get_readings.h"
  19. #define DESIRED_ANGLE 40.0
  20. typedef int bool;
  21. #define true 1
  22. #define false 0
  23. /* BLUE LED = DECREASE ANGLE */
  24. /* ORANGE LED = INCREASE ANGLE */
  25. /* Function prototypes */
  26. void arm_abs_f32(float32_t *pSrc, float32_t *pDst, uint32_t blockSize);
  27. /* Global declarations */
  28. LIS3DSH_InitTypeDef LIS3DSH_InitStruct;
  29. LIS3DSH_DRYInterruptConfigTypeDef LIS3DSH_InterruptConfigStruct;
  30. GPIO_InitTypeDef GPIOE_Init;
  31. TIM_Base_InitTypeDef TIM_Base_InitStruct;
  32. TIM_HandleTypeDef TIM_HandleStruct;
  33. GPIO_InitTypeDef GPIOA_Init;
  34. GPIO_InitTypeDef GPIOE_Init;
  35. GPIO_InitTypeDef GPIOD_Init;
  36. GPIO_InitTypeDef GPIOC_Init;
  37. GPIO_InitTypeDef GPIOB_Init;
  38. volatile int interrupt, interrupt_2, interrupt_3, interrupt_4, interrupt_5, interrupt_6;
  39. int counter;
  40. float read_acc[] = {0, 0, 0};
  41. int parsed[] = {0, 0, 0, 0, 0};
  42. int displaying[] = {0, 0, 0, 0, 0};
  43. int sample_col, sample_row;
  44. int temp_col, temp_row;
  45. float output_x[] = {0};
  46. float output_y[] = {0};
  47. float output_z[] = {0};
  48. kalman_state kstate_x;
  49. kalman_state kstate_y;
  50. kalman_state kstate_z;
  51. float den_pitch, den_roll;
  52. float pitch, roll;
  53. float diff_in, diff_out;
  54. int main(void){
  55. //===========================================
  56. // bool flag = true;
  57. // int count = 0;
  58. // int sw = 0;
  59. // interrupt_4 = 0;
  60. //
  61. // __HAL_RCC_GPIOC_CLK_ENABLE();
  62. // __HAL_RCC_GPIOB_CLK_ENABLE();
  63. //
  64. // // row bits set as output
  65. // GPIOB_Init.Mode = GPIO_MODE_OUTPUT_PP;
  66. // GPIOB_Init.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14;
  67. // GPIOB_Init.Pull = GPIO_NOPULL;
  68. // GPIOB_Init.Speed = GPIO_SPEED_FREQ_HIGH;
  69. // HAL_GPIO_Init(GPIOB, &GPIOB_Init);
  70. //
  71. // // output row bits set to logic 0
  72. // HAL_GPIO_WritePin(GPIOB, GPIO_PIN_11, GPIO_PIN_RESET);
  73. // HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET);
  74. // HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
  75. // HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
  76. //
  77. // // column bits set to logic 1 during idle
  78. // GPIOC_Init.Mode = GPIO_MODE_INPUT;
  79. // GPIOC_Init.Pin = GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6;
  80. // GPIOC_Init.Pull = GPIO_PULLUP;
  81. // GPIOC_Init.Speed = GPIO_SPEED_FREQ_HIGH;
  82. // HAL_GPIO_Init(GPIOC, &GPIOC_Init);
  83. //===========================================
  84. // char char_1 = '\0';
  85. // char char_2 = '\0';
  86. // char char_3 = '\0';
  87. // char char_4 = '\0';
  88. char char_store[] = {'\0', '\0', '\0', '\0'};
  89. int i = 0;
  90. int lock = 0;
  91. float temp;
  92. /* MCU Configuration */
  93. HAL_Init();
  94. /* Configure the system clock, peripherals and timers */
  95. SystemClock_Config();
  96. MEMS_Init();
  97. MEMS_Start_IT();
  98. TIM3_Config();
  99. GPIO_Config();
  100. Reset(&kstate_x);
  101. Reset(&kstate_y);
  102. Reset(&kstate_z);
  103. counter = 0;
  104. interrupt = 0;
  105. interrupt_5 = 0;
  106. while (1){
  107. Get_Sensor_Data(DESIRED_ANGLE);
  108. // if((roll - alarm) <= 4)Display_Alarm();
  109. // Reset_Alarm();
  110. // if(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_4) == GPIO_PIN_RESET){
  111. // HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_SET);
  112. // interrupt_4 = 0;
  113. // while(interrupt_4 < 150);
  114. // if(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_4) == GPIO_PIN_RESET){
  115. // printf("1\n");
  116. // HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_SET);
  117. // }
  118. // }
  119. // sample_col = Get_Column();
  120. // sample_row = Get_Row();
  121. // if(sample_col != NULL && sample_row != NULL){
  122. // printf("gets here\n");
  123. // char_1 = Get_Key();
  124. // printf("%c\n", char_1);
  125. // }
  126. // if(lock == 0){
  127. // if(i == 0){
  128. // sample_col = Get_Column();
  129. // sample_row = Get_Row();
  130. // if(sample_col != NULL && sample_row != NULL && char_store[i] == '\0'){
  131. // char_store[i] = Get_Key();
  132. // printf("char_[%d] = %c entered\n", i, char_store[i]);
  133. // i++;
  134. // // printf("going here %d\n", i);
  135. // }
  136. // // while(interrupt_5 < 50);
  137. // }
  138. //
  139. // if(i == 1){
  140. // printf("inside1\n");
  141. // if(char_store[i-1] != '#'){
  142. // sample_col = Get_Column();
  143. // sample_row = Get_Row();
  144. // // printf("inside2\n");
  145. // if(sample_col != NULL && sample_row != NULL && char_store[i] == '\0'){
  146. // // printf("inside3\n");
  147. // char_store[i] = Get_Key();
  148. // printf("char_[%d] = %c entered\n", i, char_store[i]);
  149. // i++;
  150. // printf("going here %d\n", i);
  151. // }
  152. // } else{
  153. // i = 0;
  154. // char_store[i] = '\0';
  155. // }
  156. // // while(interrupt_5 < 100);
  157. // }
  158. //
  159. // if(i == 2){
  160. // if(char_store[i-1] != '#'){
  161. // sample_col = Get_Column();
  162. // sample_row = Get_Row();
  163. // if(sample_col != NULL && sample_row != NULL && char_store[i] == '\0'){
  164. // char_store[i] = Get_Key();
  165. // printf("char_[%d] = %c entered\n", i, char_store[i]);
  166. // i++;
  167. // printf("going here %d\n", i);
  168. // }
  169. // } else{
  170. // // temp = char_1 - '0';
  171. // // lock = 1;
  172. // // Get_Sensor_Data(temp);
  173. // printf("# entered\n");
  174. // }
  175. // // while(interrupt_5 < 150);
  176. // }
  177. //
  178. // else{
  179. // if(char_store[i-1] != '#'){
  180. // sample_col = Get_Column();
  181. // sample_row = Get_Row();
  182. // if(sample_col != NULL && sample_row != NULL && char_store[i] == '\0'){
  183. // char_store[i] = Get_Key();
  184. // printf("char_[%d] = %c entered\n", i, char_store[i]);
  185. // }
  186. // } else{
  187. // // temp = (char_1 - '0') * 10;
  188. // // temp = temp + (char_2 - '0');
  189. // // lock = 1;
  190. // // Get_Sensor_Data(temp);
  191. // printf("# entered\n");
  192. // }
  193. // // while(interrupt_5 < 200);
  194. //
  195. //
  196. // if(char_store[0] != '#'){
  197. // char_store[1] = '\0';
  198. // char_store[2] = '\0';
  199. // char_store[3] = '\0';
  200. // i = 0;
  201. // } else{
  202. // // temp = (char_1 - '0') * 100;
  203. // // temp = temp + ((char_2 - '0') * 10);
  204. // // temp = temp + (char_3 - '0');
  205. // // lock = 1;
  206. // // Get_Sensor_Data(temp);
  207. // printf("# entered\n");
  208. // }
  209. // // }
  210. // }
  211. }
  212. }
  213. #ifdef USE_FULL_ASSERT
  214. /**
  215. * @brief Reports the name of the source file and the source line number
  216. * where the assert_param error has occurred.
  217. * @param file: pointer to the source file name
  218. * @param line: assert_param error line source number
  219. * @retval None
  220. */
  221. void assert_failed(uint8_t* file, uint32_t line){
  222. }
  223. #endif