Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PalX ADC config #2962

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 40 additions & 23 deletions targets/ChibiOS/ORGPAL_PALX/managed_helpers/ORGPAL_PALX.Adc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,70 @@
namespace nanoFramework.Targets.ORGPAL_PALX
{
/// <summary>
/// Enumeration of ADC channels available in ORGPAL_PALX
/// Enumeration of ADC channels available for the ORGPAL_PALX.
/// </summary>
/// <remarks>
/// Aligned to `target_system_device_adc_config.cpp` and must be kept inline.
/// </remarks>
public static class AdcChannels
{
/// <summary>
/// Channel 0, exposed on A0, connected to PA6 (ADC1 - IN6)
/// </summary>
public const int Channel_0 = 0;

/// <summary>
/// Channel 1, exposed on A1, connected to PA4 (ADC1 - IN4)
/// Channel 0, Thermistor port input.
/// </summary>
public const int Channel_1 = 1;
/// <remarks>
/// Connected to PA2 (ADC1 - IN2).
/// </remarks>
public const int Channel0_ThermistorInput = 0;

/// <summary>
/// Channel 2, exposed on A2, connected to PC2 (ADC1 - IN12)
/// Channel 1, Battery port input.
/// </summary>
public const int Channel_2 = 2;
/// <remarks>
/// Connected to PB0 (ADC1 - IN8).
/// </remarks>
public const int Channel1_BatteryInput = 1;

/// <summary>
/// Channel 3, exposed on A3, connected to PF10 (ADC1 - IN8)
/// Channel 2, 420mA Current sensor port input.
/// </summary>
public const int Channel_3 = 3;
/// <remarks>
/// Connected to PC2 (ADC1 - IN12).
/// </remarks>
public const int Channel2_CurrentSensorInput = 2;

/// <summary>
/// Channel 4, exposed on A4, connected to PF8 (ADC3 - IN6)
/// Channel 3, Onboard PCB temperature.
/// </summary>
public const int Channel_4 = 4;
/// <remarks>
/// Connected to PC3 (ADC1 - IN13).
/// </remarks>
public const int Channel3_PcbTemperatureSensor = 3;

/// <summary>
/// Channel 5, exposed on A5, connected to PB8 (ADC3 - IN7)
/// </summary>
public const int Channel_5 = 5;

/// <summary>
/// Channel 6, internal temperature sensor, connected to ADC1
/// Channel 4.
/// </summary>
public const int Channel_TemperatureSensor = 6;
/// <remarks>
/// Internal MCU temperature sensor, connected to ADC1.
/// </remarks>
public const int Channel4_McuTemperatureSensor = 4;

/// <summary>
/// Channel 7, internal voltage reference, connected to ADC1
/// Channel 5.
/// </summary>
public const int Channel_VrefIn = 7;
/// <remarks>
/// Internal voltage reference, connected to ADC1.
/// </remarks>
public const int Channel5_InternalVoltageReference = 5;

/// <summary>
/// Channel 8, connected to VBatt pin, ADC1
/// Channel 6.
/// </summary>
public const int Channel_Vbatt = 8;
/// <remarks>
/// Internal VBATT pin, connected to ADC1.
/// </remarks>
public const int Channel6_BatteryVoltage = 6;

}
}
23 changes: 9 additions & 14 deletions targets/ChibiOS/ORGPAL_PALX/target_system_device_adc_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);