I'm trying to understand initializing an ADC on the ARM Cortex M4 MK20DX256VLH7 on the Teensy 3.1. I'm curious about the terminology and relevant search terms as to what the symbols below mean. &= ~(3<<18)
, which I interpret as a bitwise AND on a bitwise NOT(3 bitwise left shift 18), means very little to me. I interpret what is inside the parenthetical as BIN 11
shifts to BIN 11000000000000000000
. I understand that there is a pointer dereference happening to PINMODE1 (which is a little fuzzy to me) and that it is initializing pin 25 on the chip as an ADC input? I am not at all confident in my ability to parse this. Please advise. Thank you for your time.
void ADC_Init (void) {
LPC_PINCON->PINMODE1 &= ~(3<<18); /* P0.25 */
LPC_PINCON->PINMODE1 |= (1<<18); /* has neither pull-up nor pull-down */
LPC_PINCON->PINSEL1 &= ~(3<<18); /* P0.25 is GPIO */
LPC_PINCON->PINSEL1 |= (1<<18); /* P0.25 is AD0.2 */
LPC_SC->PCONP |= (1<<12); /* Enable power to ADC block */
LPC_ADC->ADCR = (1<< 2) | /* select AD0.2 pin */
(4<< 8) | /* ADC clock is 25MHz/5 */
(1<<16) | /* Burst mode */
(1<<21); /* enable ADC */
// LPC_ADC->ADINTEN = (1<< 8); /* global enable interrupt */
// NVIC_EnableIRQ(ADC_IRQn); /* enable ADC Interrupt */
}