Browse Source

separate from stm32

Juraj Ďuďák 2 years ago
parent
commit
3a42998796
2 changed files with 44 additions and 7 deletions
  1. 43 6
      Core/Src/main.c
  2. 1 1
      Modules/nbus

+ 43 - 6
Core/Src/main.c

@@ -68,7 +68,35 @@ static void MX_ADC_Init(void);
 
 /* Private user code ---------------------------------------------------------*/
 /* USER CODE BEGIN 0 */
+void uart_send(uint8_t *data, int n)
+{
+#if USE_USART_DMA_TX == 1
+		HAL_UART_Transmit_DMA(&huart2, data, n);
+#else
+		HAL_UART_Transmit(&huart2, data, n, 10);
+#endif
+}
+
+void led_on(){
+	HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_SET);
+}
+
+void led_off(){
+	HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);
+}
+
+void led_toggle(){
+	HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
+}
 
+void uart_receive_it(uint8_t *data, int n)
+{
+	HAL_UART_Receive_IT(&huart2, data, n);
+}
+
+void uart_abort_receive(){
+	HAL_UART_AbortReceive_IT(&huart2);
+}
 /* USER CODE END 0 */
 
 /**
@@ -117,16 +145,23 @@ int main(void)
   MX_RTC_Init();
 #endif
 
-  McuPin_typeDef Led;
-  Led.port = LD3_GPIO_Port;
-  Led.pin = LD3_Pin;
+  nBusPlatformInterface_t hw_platform ={
+		  uart_receive_it,
+		  uart_send,
+		  uart_abort_receive,
+		  led_on,
+		  led_off,
+		  led_toggle,
+  };
+
+
 
   Peripheral_typeDef periph;
-  periph.huart = &huart2;
+  //periph.huart = &huart2;
   periph.uart_timer = &htim22;
   periph.measure_timer = &htim21;	// TODO ?
   //periph.adc = NULL;
-  periph.led = &Led;
+  //periph.led = &Led;
 #if MODULE_MASTER == 1
   periph.rtc = &hrtc;
 #endif
@@ -135,13 +170,15 @@ int main(void)
   //nBusAppInterface_t *dummy = getDummyDriver();
 
 #if MODULE == MODULE_FSR
-  nbus_init(&periph, getMcuAdcDriver());
+  nbus_init(&periph, getMcuAdcDriver(), &hw_platform);
 #endif
 
 #if MODULE == MODULE_IMU
   nbus_init(&periph, getImuDriver());
 #endif
 
+  HAL_UART_RegisterCallback(&huart2, HAL_UART_RX_COMPLETE_CB_ID, nbus_cb_UART_RX);
+
   nbus_init_app(&hadc, NULL);
 
   nBus_MemoryDriver memory_ec20 = {

+ 1 - 1
Modules/nbus

@@ -1 +1 @@
-Subproject commit cc26f9a8466f7951c0d7fbeccb6376b693080bbf
+Subproject commit 80d063752f58ff0cfce21bff25d1df393bed5455