Commit bda6d4cf authored by Erik Strand's avatar Erik Strand

Remove call to pinPeripheral

parent 87cf858b
......@@ -25,22 +25,43 @@ static inline uint32_t mapResolution(uint32_t value, uint32_t from, uint32_t to)
return value << (to-from);
}
void init_pin_adc(uint32_t pin) {
uint8_t const pinPort = GetPort(pin);
uint8_t const pinNum = GetPin(pin);
// Preserve state of pullup/pulldown enable, clear the rest of the bits
uint8_t pinCfg = (PORT->Group[pinPort].PINCFG[pinNum].reg & PORT_PINCFG_PULLEN);
if ( pinNum & 1 ) // is pin odd?
{
// Get whole current setup for both odd and even pins and remove odd one, then set new muxing
uint32_t temp = (PORT->Group[pinPort].PMUX[pinNum >> 1].reg) & PORT_PMUX_PMUXE( 0xF ) ;
PORT->Group[pinPort].PMUX[pinNum >> 1].reg = temp|PORT_PMUX_PMUXO(PER_ANALOG) ;
}
else // even pin
{
// Get whole current setup for both odd and even pins and remove even one, then set new muxing
uint32_t temp = (PORT->Group[pinPort].PMUX[pinNum >> 1].reg) & PORT_PMUX_PMUXO( 0xF ) ;
PORT->Group[pinPort].PMUX[pinNum >> 1].reg = temp|PORT_PMUX_PMUXE(PER_ANALOG) ;
}
pinCfg |= PORT_PINCFG_PMUXEN; // Enable peripheral mux
// Set pin drive strength, enable/disable pull resistor, enable/disable INEN, and enable/disable the peripheral mux
PORT->Group[pinPort].PINCFG[pinNum].reg = (uint8_t)pinCfg ;
}
uint32_t bm_analogRead( uint32_t pin )
{
uint32_t valueRead = 0;
// pinPeripheral now handles disabling the DAC (if active)
if ( pinPeripheral(pin, PIO_ANALOG_ADC) == RET_STATUS_OK )
{
// Start conversion
ADC->SWTRIG.bit.START = 1;
syncADC();
// Start conversion
ADC->SWTRIG.bit.START = 1;
syncADC();
// Store the value
while (ADC->INTFLAG.bit.RESRDY == 0); // Waiting for conversion to complete
valueRead = ADC->RESULT.reg;
}
// Store the value
while (ADC->INTFLAG.bit.RESRDY == 0); // Waiting for conversion to complete
valueRead = ADC->RESULT.reg;
return mapResolution(valueRead, _ADCResolution, _readResolution);
}
......@@ -55,6 +76,10 @@ void setup() {
// Initialize the ADC
initADC();
// Everything seems to function if I don't do this, but I'm leaving it in until I have a chance
// to investigate what's happening.
init_pin_adc(SENSE_LINE_0);
// Selection for the positive ADC input
ADC->INPUTCTRL.bit.MUXPOS = GetADC(SENSE_LINE_0);
syncADC();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment