Răsfoiți Sursa

fix:修复误删除文件

CN\guohui27 2 ani în urmă
părinte
comite
7f8cd35ed2
1 a modificat fișierele cu 194 adăugiri și 1 ștergeri
  1. 194 1
      User project/5.Api_rt/api_rt_adc.c

+ 194 - 1
User project/5.Api_rt/api_rt_adc.c

@@ -10,11 +10,39 @@ ApiRtAdc_Handle Adcs[3];
 
 void iRtAdc_Init(void)
 {
-
+    // ADC0 Regular
+    Adcs[0].AdcBase = ADC0;
+    Adcs[0].DmaBase = DMA0;
+    Adcs[0].DmaChannelBase = DMA_CH0;
+    for (int i = 0; i < ADC_RESULT_SIZE; i++)
+    {
+        Adcs[0].Results[i] = 0;
+    }
+    // ADC0 Injected
+    Adcs[1].AdcBase = ADC0;
+    for (int i = 1; i < ADC_RESULT_SIZE; i++)
+    {
+        Adcs[1].Results[i] = 0;
+    }
+    // ADC1 Injected
+    Adcs[2].AdcBase = ADC1;
+    for (int i = 0; i < ADC_RESULT_SIZE; i++)
+    {
+        Adcs[2].Results[i] = 0;
+    }
 
 };
 
+void iRtAdc_CompleteIsr(uint8_t devIndex)
+{
+    /* 处理同步采样的逻辑 */
+    iRtPwm_SyncSamplingAdcIsr(0);
 
+    if (Adcs[devIndex].CompleteISR.Action != 0)
+    {
+        Adcs[devIndex].CompleteISR.Action();
+    }
+}
 /* ========================================================================== */
 /* ============================== API Functions ============================= */
 /* ========================================================================== */
@@ -29,3 +57,168 @@ uint16_t* iAdc_GetResultPointer(uint8_t devIndex)
     return Adcs[devIndex].Results;
 }
 
+void iAdc_Enable(uint8_t devIndex)
+{
+    if(RESET == (ADC_CTL1(Adcs[devIndex].AdcBase) & ADC_CTL1_ADCON)){
+        ADC_CTL1(Adcs[devIndex].AdcBase) |= (uint32_t)ADC_CTL1_ADCON;
+    }   
+}
+
+void iAdc_Disable(uint8_t devIndex)
+{
+    ADC_CTL1(Adcs[devIndex].AdcBase) &= ~((uint32_t)ADC_CTL1_ADCON);
+}
+
+ApiAdc_Status iAdc_GetStatus(uint8_t devIndex)
+{
+     if (ADC_STAT(Adcs[devIndex].AdcBase) & ADC_STAT_EOC != 0)
+    {
+        return ApiAdc_End;
+    }
+    else
+    {
+        return ApiAdc_Converting;
+    }
+}
+
+void iAdc_Convert(uint8_t devIndex)
+{
+  //for regular only
+    ADC_CTL1(Adcs[devIndex].AdcBase) |= ADC_CTL1_SWRCST;
+}
+
+int8_t iAdc_ChannelGroupSwitch(uint8_t devIndex, uint8_t groupIndex)
+{
+    return 0;
+}
+
+void iAdc_EnableConversionInterrupt(uint8_t devIndex)
+{
+
+}
+
+void iAdc_EnableHardwareTrigger(uint8_t devIndex);
+void iAdc_DisableHardwareTrigger(uint8_t devIndex);void iAdc_Enable(uint8_t devIndex)
+{
+    if(RESET == (ADC_CTL1(Adcs[devIndex].AdcBase) & ADC_CTL1_ADCON)){
+        ADC_CTL1(Adcs[devIndex].AdcBase) |= (uint32_t)ADC_CTL1_ADCON;
+    }   
+}
+
+void iAdc_Disable(uint8_t devIndex)
+{
+    ADC_CTL1(Adcs[devIndex].AdcBase) &= ~((uint32_t)ADC_CTL1_ADCON);
+}
+
+ApiAdc_Status iAdc_GetStatus(uint8_t devIndex)
+{
+     if (ADC_STAT(Adcs[devIndex].AdcBase) & ADC_STAT_EOC != 0)
+    {
+        return ApiAdc_End;
+    }
+    else
+    {
+        return ApiAdc_Converting;
+    }
+}
+
+void iAdc_Convert(uint8_t devIndex)
+{
+  //for regular only
+    ADC_CTL1(Adcs[devIndex].AdcBase) |= ADC_CTL1_SWRCST;
+}
+
+int8_t iAdc_ChannelGroupSwitch(uint8_t devIndex, uint8_t groupIndex)
+{
+    return 0;
+}
+
+void iAdc_EnableConversionInterrupt(uint8_t devIndex)
+{
+
+}
+
+void iAdc_EnableHardwareTrigger(uint8_t devIndex);
+void iAdc_DisableHardwareTrigger(uint8_t devIndex);void iAdc_Enable(uint8_t devIndex)
+{
+    if(RESET == (ADC_CTL1(Adcs[devIndex].AdcBase) & ADC_CTL1_ADCON)){
+        ADC_CTL1(Adcs[devIndex].AdcBase) |= (uint32_t)ADC_CTL1_ADCON;
+    }   
+}
+
+void iAdc_Disable(uint8_t devIndex)
+{
+    ADC_CTL1(Adcs[devIndex].AdcBase) &= ~((uint32_t)ADC_CTL1_ADCON);
+}
+
+ApiAdc_Status iAdc_GetStatus(uint8_t devIndex)
+{
+     if (ADC_STAT(Adcs[devIndex].AdcBase) & ADC_STAT_EOC != 0)
+    {
+        return ApiAdc_End;
+    }
+    else
+    {
+        return ApiAdc_Converting;
+    }
+}
+
+void iAdc_Convert(uint8_t devIndex)
+{
+  //for regular only
+    ADC_CTL1(Adcs[devIndex].AdcBase) |= ADC_CTL1_SWRCST;
+}
+
+int8_t iAdc_ChannelGroupSwitch(uint8_t devIndex, uint8_t groupIndex)
+{
+    return 0;
+}
+
+void iAdc_EnableConversionInterrupt(uint8_t devIndex)
+{
+
+}
+
+void iAdc_EnableHardwareTrigger(uint8_t devIndex);
+void iAdc_DisableHardwareTrigger(uint8_t devIndex);void iAdc_Enable(uint8_t devIndex)
+{
+    if(RESET == (ADC_CTL1(Adcs[devIndex].AdcBase) & ADC_CTL1_ADCON)){
+        ADC_CTL1(Adcs[devIndex].AdcBase) |= (uint32_t)ADC_CTL1_ADCON;
+    }   
+}
+
+void iAdc_Disable(uint8_t devIndex)
+{
+    ADC_CTL1(Adcs[devIndex].AdcBase) &= ~((uint32_t)ADC_CTL1_ADCON);
+}
+
+ApiAdc_Status iAdc_GetStatus(uint8_t devIndex)
+{
+     if (ADC_STAT(Adcs[devIndex].AdcBase) & ADC_STAT_EOC != 0)
+    {
+        return ApiAdc_End;
+    }
+    else
+    {
+        return ApiAdc_Converting;
+    }
+}
+
+void iAdc_Convert(uint8_t devIndex)
+{
+  //for regular only
+    ADC_CTL1(Adcs[devIndex].AdcBase) |= ADC_CTL1_SWRCST;
+}
+
+int8_t iAdc_ChannelGroupSwitch(uint8_t devIndex, uint8_t groupIndex)
+{
+    return 0;
+}
+
+void iAdc_EnableConversionInterrupt(uint8_t devIndex)
+{
+
+}
+
+void iAdc_EnableHardwareTrigger(uint8_t devIndex);
+void iAdc_DisableHardwareTrigger(uint8_t devIndex);