Skip to content

Fix ANALOGIN support for LPC55S69 #11127

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

Merged
merged 1 commit into from
Aug 20, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ void analogin_init(analogin_t *obj, PinName pin)

pinmap_pinout(pin, PinMap_ADC);

/* Need to ensure the pin is in input mode */
gpio_init(&gpio, pin);
gpio_dir(&gpio, PIN_INPUT);

reg = IOCON->PIO[port_number][pin_number];
/* Clear the DIGIMODE bit */
reg &= ~IOCON_PIO_DIGIMODE_MASK;

/* Clear the MODE & DIGIMODE bit */
reg &= ~(IOCON_PIO_DIGIMODE_MASK | IOCON_PIO_MODE_MASK);

/* For pins PIO0_9, PIO0_11, PIO0_12, PIO0_15, PIO0_18, PIO0_31, PIO1_0 and
PIO1_9, leave ASW bit at '0' in the related IOCON register. */
if (((port_number == 0) && ((pin_number == 9) || (pin_number == 11) || (pin_number == 12) ||
Expand All @@ -91,11 +97,8 @@ void analogin_init(analogin_t *obj, PinName pin)
/* Enable Analog Switch Input control */
reg |= IOCON_PIO_ASW_MASK;
}
IOCON->PIO[port_number][pin_number] = reg;

/* Need to ensure the pin is in input mode */
gpio_init(&gpio, pin);
gpio_dir(&gpio, PIN_INPUT);
IOCON->PIO[port_number][pin_number] = reg;
}

uint16_t analogin_read_u16(analogin_t *obj)
Expand All @@ -110,16 +113,30 @@ uint16_t analogin_read_u16(analogin_t *obj)
memset(&mLpadcCommandConfigStruct, 0, sizeof(mLpadcCommandConfigStruct));
memset(&mLpadcResultConfigStruct, 0, sizeof(mLpadcResultConfigStruct));

#if (defined(FSL_FEATURE_LPADC_FIFO_COUNT) && (FSL_FEATURE_LPADC_FIFO_COUNT == 2))
LPADC_DoResetFIFO0(adc_addrs[instance]);
LPADC_DoResetFIFO1(adc_addrs[instance]);
#else
LPADC_DoResetFIFO(adc_addrs[instance]);
#endif /* FSL_FEATURE_LPADC_FIFO_COUNT */

/* Set conversion CMD configuration. */
LPADC_GetDefaultConvCommandConfig(&mLpadcCommandConfigStruct);

/* Check if we should use the B channel */
if (obj->adc >> ADC_B_CHANNEL_SHIFT) {
mLpadcCommandConfigStruct.sampleChannelMode = kLPADC_SampleChannelSingleEndSideB;
}

mLpadcCommandConfigStruct.channelNumber = channel;
mLpadcCommandConfigStruct.conversionResoultuionMode = kLPADC_ConversionResolutionStandard;
LPADC_SetConvCommandConfig(adc_addrs[instance], LPADC_USER_CMDID, &mLpadcCommandConfigStruct);

/* Set trigger configuration. */
LPADC_GetDefaultConvTriggerConfig(&mLpadcTriggerConfigStruct);
mLpadcTriggerConfigStruct.targetCommandId = LPADC_USER_CMDID;
mLpadcTriggerConfigStruct.enableHardwareTrigger = false;
LPADC_SetConvTriggerConfig(adc_addrs[instance], 0U, &mLpadcTriggerConfigStruct); /* Configurate the trigger0. */
LPADC_SetConvTriggerConfig(adc_addrs[instance], 0U, &mLpadcTriggerConfigStruct); /* Configure the trigger0. */

LPADC_DoSoftwareTrigger(adc_addrs[instance], 1U); /* 1U is trigger0 mask. */

Expand All @@ -131,13 +148,13 @@ uint16_t analogin_read_u16(analogin_t *obj)
}
#endif /* FSL_FEATURE_LPADC_FIFO_COUNT */

return ((mLpadcResultConfigStruct.convValue) >> 3U);
return (mLpadcResultConfigStruct.convValue << 1);
}

float analogin_read(analogin_t *obj)
{
uint16_t value = analogin_read_u16(obj);
return (float)value * (1.0f / (float)0xFFFF);
return (float)value * (1.0f / (float)0xFFF0);
}

const PinMap *analogin_pinmap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,38 @@ typedef enum {
#define ADC_B_CHANNEL_SHIFT 5

typedef enum {
ADC0_SE0 = 0,
ADC0_SE1 = 1,
ADC0_SE2 = 2,
ADC0_SE3 = 3,
ADC0_SE4 = 4,
ADC0_SE5 = 5,
ADC0_SE6 = 6,
ADC0_SE7 = 7,
ADC0_SE8 = 8,
ADC0_SE9 = 9,
ADC0_SE10 = 10,
ADC0_SE11 = 11,
ADC0_SE12 = 12,
ADC0_SE13 = 13,
ADC0_SE14 = 14,
ADC0_SE15 = 15
ADC0_SE0 = 0,
ADC0_SE1 = 1,
ADC0_SE2 = 2,
ADC0_SE3 = 3,
ADC0_SE4 = 4,
ADC0_SE5 = 5,
ADC0_SE6 = 6,
ADC0_SE7 = 7,
ADC0_SE8 = 8,
ADC0_SE9 = 9,
ADC0_SE10 = 10,
ADC0_SE11 = 11,
ADC0_SE12 = 12,
ADC0_SE13 = 13,
ADC0_SE14 = 14,
ADC0_SE15 = 15,
ADC0_SE0_B = (1 << ADC_B_CHANNEL_SHIFT) | 0,
ADC0_SE1_B = (1 << ADC_B_CHANNEL_SHIFT) | 1,
ADC0_SE2_B = (1 << ADC_B_CHANNEL_SHIFT) | 2,
ADC0_SE3_B = (1 << ADC_B_CHANNEL_SHIFT) | 3,
ADC0_SE4_B = (1 << ADC_B_CHANNEL_SHIFT) | 4,
ADC0_SE5_B = (1 << ADC_B_CHANNEL_SHIFT) | 5,
ADC0_SE6_B = (1 << ADC_B_CHANNEL_SHIFT) | 6,
ADC0_SE7_B = (1 << ADC_B_CHANNEL_SHIFT) | 7,
ADC0_SE8_B = (1 << ADC_B_CHANNEL_SHIFT) | 8,
ADC0_SE9_B = (1 << ADC_B_CHANNEL_SHIFT) | 9,
ADC0_SE10_B = (1 << ADC_B_CHANNEL_SHIFT) | 10,
ADC0_SE11_B = (1 << ADC_B_CHANNEL_SHIFT) | 11,
ADC0_SE12_B = (1 << ADC_B_CHANNEL_SHIFT) | 12,
ADC0_SE13_B = (1 << ADC_B_CHANNEL_SHIFT) | 13,
ADC0_SE14_B = (1 << ADC_B_CHANNEL_SHIFT) | 14,
ADC0_SE15_B = (1 << ADC_B_CHANNEL_SHIFT) | 15
} ADCName;

typedef enum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ const PinMap PinMap_RTC[] = {

/************ADC***************/
const PinMap PinMap_ADC[] = {
{P0_23, ADC0_SE0, 0},
{P0_10, ADC0_SE1, 0},
{P0_31, ADC0_SE3, 0},
{P1_8, ADC0_SE4, 0},
{P2_0, ADC0_SE5, 0},
{P2_13, ADC0_SE6, 0},
{P2_11, ADC0_SE7, 0},
{P0_16, ADC0_SE8, 0},
{NC , NC , 0}
{P0_23, ADC0_SE0, 0},
{P0_10, ADC0_SE1, 0},
{P0_31, ADC0_SE3, 0},
{P1_8, ADC0_SE4, 0},
{P2_0, ADC0_SE5, 0},
{P2_13, ADC0_SE6, 0},
{P2_11, ADC0_SE7, 0},
{NC , NC , 0}
};

/************CAN***************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void ADC_ClockPower_Configuration(void)

/* Disable LDOGPADC power down */
POWER_DisablePD(kPDRUNCFG_PD_LDOGPADC);
RESET_PeripheralReset(kADC0_RST_SHIFT_RSTn);
}

void sdio_clock_setup(void)
Expand Down