Kinetis:Added PX4 ADC Driver.

PX4 Driver for Kinetis uisng just ADC1.

   On V3 HW RC00 the USB_VBUS_VALID on pin 36 of the MCU
   ADC0_SE16/ADC1_SE22 is bridged to pin 29 ADC1_DP0 and read
   there. But because of missing schottky diodes on V3 HW RC00
   the signal is true (3.3V) when powered by the Power Module.
This commit is contained in:
David Sidrane
2017-09-29 10:13:51 -04:00
committed by Daniel Agar
parent 160f5cc67d
commit 1bc760c194
3 changed files with 146 additions and 122 deletions
+32 -20
View File
@@ -284,33 +284,45 @@ __BEGIN_DECLS
/*
* ADC channels
*
* These are the channel numbers of the ADCs of the microcontroller that can be used by the Px4 Firmware in the adc driver
* These are the channel numbers of the ADCs of the microcontroller that can be used by the Px4
* Firmware in the adc driver. ADC1 has 32 channels, with some a/b selection overlap
* in the AD4-AD7 range on the same ADC.
*
* Only ADC1 is used
* Bits 31:0 are ADC1 channels 31:0
*/
#define ADC_CHANNELS 1 << 0 // TBD
/* ADC defines to be used in sensors.cpp to read from a particular channel
*
* ADC0
* USB_VBUS_VALID 36 - ADC0_SE16 or ADC0_SE21
*
* ADC1
* AD1 35 - ADC1_SE16
* AD2 37 - ADC1_SE18
* AD3 39 - ADC1_SE23
* BAT_VSENS 85 PTB4 ADC1_SE10
* BAT_ISENS 86 PTB5 ADC1_SE11
* 5V_VSENS 87 PTB6 ADC1_SE12
* RSSI_IN 88 PTB7 ADC1_SE13
*
*/
#define ADC1(c) (((c) & 0x1f)) /* Define ADC number /Channel number */
/* ADC defines to be used in sensors.cpp to read from a particular channel */
#define ADC_USB_VBUS_VALID ADC1(0) /* USB_VBUS_VALID 29 - ADC1_DP0 (bridged on V3 RC00 HW from pin 36 ADC0_SE16 or ADC0_SE21) */
#define ADC_BATTERY_VOLTAGE_CHANNEL ADC1(10) /* BAT_VSENS 85 PTB4 ADC1_SE10 */
#define ADC_BATTERY_CURRENT_CHANNEL ADC1(11) /* BAT_ISENS 86 PTB5 ADC1_SE11 */
#define ADC_5V_RAIL_SENSE ADC1(12) /* 5V_VSENS 87 PTB6 ADC1_SE12 */
#define ADC_RSSI_IN ADC1(13) /* RSSI_IN 88 PTB7 ADC1_SE13 */
#define ADC_AD1 ADC1(16) /* AD1 35 - ADC1_SE16 */
#define ADC_AD2 ADC1(18) /* AD2 37 - ADC1_SE18 */
#define ADC_AD3 ADC1(23) /* AD3 39 - ADC1_SE23 */
/* Mask use to initialize the ADC driver */
#define ADC_CHANNELS ((1 << ADC_USB_VBUS_VALID) | \
(1 << ADC_BATTERY_VOLTAGE_CHANNEL) | \
(1 << ADC_BATTERY_CURRENT_CHANNEL) | \
(1 << ADC_5V_RAIL_SENSE) | \
(1 << ADC_RSSI_IN) | \
(1 << ADC_AD1) | \
(1 << ADC_AD2) | \
(1 << ADC_AD3))
/* GPIO that require Configuration */
#define GPIO_BAT_VSENS PIN_ADC1_SE10
#define GPIO_BAT_ISENS PIN_ADC1_SE11
#define GPIO_5V_VSENS PIN_ADC1_SE12
#define GPIO_RSSI_IN PIN_ADC1_SE13
#define ADC_BATTERY_VOLTAGE_CHANNEL 22
#define ADC_BATTERY_CURRENT_CHANNEL 21
#define ADC_5V_RAIL_SENSE 18
#define BOARD_BATTERY1_V_DIV (10.177939394f)
#define BOARD_BATTERY1_A_PER_V (15.391030303f)
@@ -213,14 +213,11 @@ kinetis_boardinitialize(void)
board_autoled_initialize();
/* configure ADC pins */
#if defined(GPIO_ADC1_IN2)
kinetis_pinconfig(GPIO_ADC1_IN2); /* BATT_VOLTAGE_SENS */
kinetis_pinconfig(GPIO_ADC1_IN3); /* BATT_CURRENT_SENS */
kinetis_pinconfig(GPIO_ADC1_IN4); /* VDD_5V_SENS */
kinetis_pinconfig(GPIO_ADC1_IN13); /* FMU_AUX_ADC_1 */
kinetis_pinconfig(GPIO_ADC1_IN14); /* FMU_AUX_ADC_2 */
kinetis_pinconfig(GPIO_ADC1_IN15); /* PRESSURE_SENS */
#endif
kinetis_pinconfig(GPIO_BAT_VSENS);
kinetis_pinconfig(GPIO_BAT_ISENS);
kinetis_pinconfig(GPIO_5V_VSENS);
kinetis_pinconfig(GPIO_RSSI_IN);
/* configure power supply control/sense pins */