From f84b7309710d4fc32f3cb85228ff375797ae5db4 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Thu, 13 Jun 2024 01:07:28 +0100 Subject: [PATCH 1/2] Fix ADC config --- .../managed_helpers/ORGPAL_PALX.Adc.cs | 63 ++++++++++++------- .../target_system_device_adc_config.cpp | 23 +++---- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/targets/ChibiOS/ORGPAL_PALX/managed_helpers/ORGPAL_PALX.Adc.cs b/targets/ChibiOS/ORGPAL_PALX/managed_helpers/ORGPAL_PALX.Adc.cs index a786c09041..b24e3731d0 100644 --- a/targets/ChibiOS/ORGPAL_PALX/managed_helpers/ORGPAL_PALX.Adc.cs +++ b/targets/ChibiOS/ORGPAL_PALX/managed_helpers/ORGPAL_PALX.Adc.cs @@ -6,53 +6,70 @@ namespace nanoFramework.Targets.ORGPAL_PALX { /// - /// Enumeration of ADC channels available in ORGPAL_PALX + /// Enumeration of ADC channels available for the ORGPAL_PALX. /// + /// + /// Aligned to `target_system_device_adc_config.cpp` and must be kept inline. + /// public static class AdcChannels { - /// - /// Channel 0, exposed on A0, connected to PA6 (ADC1 - IN6) - /// - public const int Channel_0 = 0; /// - /// Channel 1, exposed on A1, connected to PA4 (ADC1 - IN4) + /// Channel 0, Thermistor port input. /// - public const int Channel_1 = 1; + /// + /// Connected to PA2 (ADC1 - IN2). + /// + public const int Channel0_ThermistorInput = 0; /// - /// Channel 2, exposed on A2, connected to PC2 (ADC1 - IN12) + /// Channel 1, Battery port input. /// - public const int Channel_2 = 2; + /// + /// Connected to PB0 (ADC1 - IN8). + /// + public const int Channel1_BatteryInput = 1; /// - /// Channel 3, exposed on A3, connected to PF10 (ADC1 - IN8) + /// Channel 2, 420mA Current sensor port input. /// - public const int Channel_3 = 3; + /// + /// Connected to PC2 (ADC1 - IN12). + /// + public const int Channel2_CurrentSensorInput = 2; /// - /// Channel 4, exposed on A4, connected to PF8 (ADC3 - IN6) + /// Channel 3, Onboard PCB temperature. /// - public const int Channel_4 = 4; + /// + /// Connected to PC3 (ADC1 - IN13). + /// + public const int Channel3_PcbTemperatureSensor = 3; - /// - /// Channel 5, exposed on A5, connected to PB8 (ADC3 - IN7) - /// - public const int Channel_5 = 5; /// - /// Channel 6, internal temperature sensor, connected to ADC1 + /// Channel 4. /// - public const int Channel_TemperatureSensor = 6; + /// + /// Internal MCU temperature sensor, connected to ADC1. + /// + public const int Channel4_McuTemperatureSensor = 4; /// - /// Channel 7, internal voltage reference, connected to ADC1 + /// Channel 5. /// - public const int Channel_VrefIn = 7; + /// + /// Internal voltage reference, connected to ADC1. + /// + public const int Channel5_InternalVoltageReference = 5; /// - /// Channel 8, connected to VBatt pin, ADC1 + /// Channel 6. /// - public const int Channel_Vbatt = 8; + /// + /// Internal VBATT pin, connected to ADC1. + /// + public const int Channel6_BatteryVoltage = 6; + } } diff --git a/targets/ChibiOS/ORGPAL_PALX/target_system_device_adc_config.cpp b/targets/ChibiOS/ORGPAL_PALX/target_system_device_adc_config.cpp index e480082ee1..1a01713e24 100644 --- a/targets/ChibiOS/ORGPAL_PALX/target_system_device_adc_config.cpp +++ b/targets/ChibiOS/ORGPAL_PALX/target_system_device_adc_config.cpp @@ -8,21 +8,16 @@ const NF_PAL_ADC_PORT_PIN_CHANNEL AdcPortPinConfig[] = { // ADC1 - {1, GPIOA, 3, ADC_CHANNEL_IN3}, - {1, GPIOA, 4, ADC_CHANNEL_IN4}, - {1, GPIOB, 0, ADC_CHANNEL_IN8}, - {1, GPIOB, 1, ADC_CHANNEL_IN9}, - {1, GPIOC, 2, ADC_CHANNEL_IN12}, - {1, GPIOC, 3, ADC_CHANNEL_IN13}, + {1, GPIOA, 2, ADC_CHANNEL_IN2}, // Channel 0, Thermistor port Input + {1, GPIOB, 0, ADC_CHANNEL_IN8}, // Channel 1, Battery port input. + {1, GPIOC, 2, ADC_CHANNEL_IN12}, // Channel 2, 420MA Current sensor port input. + {1, GPIOC, 3, ADC_CHANNEL_IN13}, // Channel 3, Onboard PCB temperature. - // ADC3 - {3, GPIOF, 8, ADC_CHANNEL_IN6}, - {3, GPIOF, 9, ADC_CHANNEL_IN7}, - - // these are the internal sources, available only at ADC1 - {1, NULL, 0, ADC_CHANNEL_SENSOR}, - {1, NULL, 0, ADC_CHANNEL_VREFINT}, - {1, NULL, 0, ADC_CHANNEL_VBAT}, + // These are the internal sources, available only at ADC1 + // and are added to the end. + {1, NULL, 0, ADC_CHANNEL_SENSOR}, // Channel 4, internal MCU temperature. + {1, NULL, 0, ADC_CHANNEL_VREFINT}, //Channel 5, internal MCU voltage reference + {1, NULL, 0, ADC_CHANNEL_VBAT}, // Channel 6, internal MCU vbat reference. }; const int AdcChannelCount = ARRAYSIZE(AdcPortPinConfig); From 61d4c51891bda240a742de1fd254d8380761fbba Mon Sep 17 00:00:00 2001 From: nfbot Date: Fri, 14 Jun 2024 14:14:25 +0100 Subject: [PATCH 2/2] Code style fixes (#18) Automated fixes for code style. --- .../ORGPAL_PALX/target_system_device_adc_config.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/targets/ChibiOS/ORGPAL_PALX/target_system_device_adc_config.cpp b/targets/ChibiOS/ORGPAL_PALX/target_system_device_adc_config.cpp index 1a01713e24..36616d2a63 100644 --- a/targets/ChibiOS/ORGPAL_PALX/target_system_device_adc_config.cpp +++ b/targets/ChibiOS/ORGPAL_PALX/target_system_device_adc_config.cpp @@ -8,16 +8,16 @@ const NF_PAL_ADC_PORT_PIN_CHANNEL AdcPortPinConfig[] = { // ADC1 - {1, GPIOA, 2, ADC_CHANNEL_IN2}, // Channel 0, Thermistor port Input - {1, GPIOB, 0, ADC_CHANNEL_IN8}, // Channel 1, Battery port input. + {1, GPIOA, 2, ADC_CHANNEL_IN2}, // Channel 0, Thermistor port Input + {1, GPIOB, 0, ADC_CHANNEL_IN8}, // Channel 1, Battery port input. {1, GPIOC, 2, ADC_CHANNEL_IN12}, // Channel 2, 420MA Current sensor port input. {1, GPIOC, 3, ADC_CHANNEL_IN13}, // Channel 3, Onboard PCB temperature. // These are the internal sources, available only at ADC1 // and are added to the end. - {1, NULL, 0, ADC_CHANNEL_SENSOR}, // Channel 4, internal MCU temperature. - {1, NULL, 0, ADC_CHANNEL_VREFINT}, //Channel 5, internal MCU voltage reference - {1, NULL, 0, ADC_CHANNEL_VBAT}, // Channel 6, internal MCU vbat reference. + {1, NULL, 0, ADC_CHANNEL_SENSOR}, // Channel 4, internal MCU temperature. + {1, NULL, 0, ADC_CHANNEL_VREFINT}, // Channel 5, internal MCU voltage reference + {1, NULL, 0, ADC_CHANNEL_VBAT}, // Channel 6, internal MCU vbat reference. }; const int AdcChannelCount = ARRAYSIZE(AdcPortPinConfig);