Skip to content

Commit 7bdbdbe

Browse files
Merge pull request #5703 from dave-wu/cog-adc-fix
AD: Fix ADC driver
2 parents 324e53b + fc48104 commit 7bdbdbe

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

targets/TARGET_Analog_Devices/TARGET_ADUCM302X/TARGET_ADUCM3029/api/analogin_api.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#include "pinmap.h"
4848
#include "PeripheralPins.h"
4949

50-
5150
#ifdef __cplusplus
5251
extern "C" {
5352
#endif
@@ -80,7 +79,10 @@ void analogin_init(analogin_t *obj, PinName pin)
8079
ADCName peripheral;
8180
uint32_t function, channel;
8281

83-
peripheral = (ADCName)pinmap_peripheral(pin, &PinMap_ADC[0]); // gives peripheral
82+
memset(obj, 0, sizeof(analogin_t) );
83+
memset( DeviceMemory, 0, sizeof( DeviceMemory ) );
84+
85+
peripheral = (ADCName)pinmap_peripheral(pin, &PinMap_ADC[0]); // gives peripheral
8486
MBED_ASSERT(peripheral != (ADCName)NC);
8587

8688
/* verify read function */
@@ -142,6 +144,7 @@ void analogin_init(analogin_t *obj, PinName pin)
142144

143145
/* Set the acquisition time. (Application need to change it based on the impedence) */
144146
adi_adc_SetAcquisitionTime(hDevice, obj->SampleCycles);
147+
145148
}
146149

147150
/** Read the input voltage, represented as a float in the range [0.0, 1.0]
@@ -165,6 +168,11 @@ uint16_t analogin_read_u16(analogin_t *obj)
165168
{
166169
ADI_ADC_HANDLE hDevice = obj->hDevice;
167170
ADI_ADC_BUFFER *pAdcBuffer;
171+
uint32_t ADCsample;
172+
173+
obj->UserBuffer.pDataBuffer = &ADCsample;
174+
obj->UserBuffer.nNumConversionPasses = 1;
175+
obj->UserBuffer.nBuffSize = 1;
168176

169177
/* Submit the buffer to the driver */
170178
adi_adc_SubmitBuffer(hDevice, &obj->UserBuffer);
@@ -178,8 +186,9 @@ uint16_t analogin_read_u16(analogin_t *obj)
178186
return( (uint16_t)( ((uint16_t *)pAdcBuffer->pDataBuffer)[(pAdcBuffer->nNumConversionPasses) - 1]) );
179187
}
180188

181-
/* Retrieve te active channel correspondoing to the input pin */
182-
static uint32_t adi_pin2channel(PinName pin) {
189+
/* Retrieve the active channel corresponding to the input pin */
190+
static uint32_t adi_pin2channel(PinName pin)
191+
{
183192

184193
uint32_t activech;
185194

targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/analogin_api.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ void analogin_init(analogin_t *obj, PinName pin)
7979
ADCName peripheral;
8080
uint32_t function, channel;
8181

82-
peripheral = (ADCName)pinmap_peripheral(pin, &PinMap_ADC[0]); // gives peripheral
82+
memset(obj, 0, sizeof(analogin_t) );
83+
memset( DeviceMemory, 0, sizeof( DeviceMemory ) );
84+
85+
peripheral = (ADCName)pinmap_peripheral(pin, &PinMap_ADC[0]); // gives peripheral
8386
MBED_ASSERT(peripheral != (ADCName)NC);
8487

8588
/* verify read function */
@@ -165,6 +168,11 @@ uint16_t analogin_read_u16(analogin_t *obj)
165168
{
166169
ADI_ADC_HANDLE hDevice = obj->hDevice;
167170
ADI_ADC_BUFFER *pAdcBuffer;
171+
uint32_t ADCsample;
172+
173+
obj->UserBuffer.pDataBuffer = &ADCsample;
174+
obj->UserBuffer.nNumConversionPasses = 1;
175+
obj->UserBuffer.nBuffSize = 1;
168176

169177
/* Submit the buffer to the driver */
170178
adi_adc_SubmitBuffer(hDevice, &obj->UserBuffer);
@@ -178,7 +186,7 @@ uint16_t analogin_read_u16(analogin_t *obj)
178186
return( (uint16_t)( ((uint16_t *)pAdcBuffer->pDataBuffer)[(pAdcBuffer->nNumConversionPasses) - 1]) );
179187
}
180188

181-
/* Retrieve te active channel correspondoing to the input pin */
189+
/* Retrieve the active channel corresponding to the input pin */
182190
static uint32_t adi_pin2channel(PinName pin)
183191
{
184192

0 commit comments

Comments
 (0)