diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2018-11-21 20:33:44 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2018-11-21 20:44:18 -0500 |
commit | 4bbd6310864b231f26c3c069052a610a2178a456 (patch) | |
tree | d21b5fe6c94ce1241c4464e7bb3c85136bd9b2e8 /src/lpc176x/gpio.c | |
parent | 9ba94ded9e9c48c81ddd10e9712619882e046fa1 (diff) | |
download | kutter-4bbd6310864b231f26c3c069052a610a2178a456.tar.gz kutter-4bbd6310864b231f26c3c069052a610a2178a456.tar.xz kutter-4bbd6310864b231f26c3c069052a610a2178a456.zip |
lpc176x: Add an enable_peripheral_clock() helper function
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/lpc176x/gpio.c')
-rw-r--r-- | src/lpc176x/gpio.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/lpc176x/gpio.c b/src/lpc176x/gpio.c index 49363d2a..5f5f9375 100644 --- a/src/lpc176x/gpio.c +++ b/src/lpc176x/gpio.c @@ -32,6 +32,20 @@ static LPC_GPIO_TypeDef * const digital_regs[] = { * General Purpose Input Output (GPIO) pins ****************************************************************/ +// Enable a peripheral clock +void +enable_peripheral_clock(uint32_t pclk) +{ + LPC_SC->PCONP |= 1<<pclk; + if (pclk < 16) { + uint32_t shift = pclk * 2; + LPC_SC->PCLKSEL0 = (LPC_SC->PCLKSEL0 & ~(0x3<<shift)) | (0x1<<shift); + } else { + uint32_t shift = (pclk - 16) * 2; + LPC_SC->PCLKSEL1 = (LPC_SC->PCLKSEL1 & ~(0x3<<shift)) | (0x1<<shift); + } +} + // Set the mode and extended function of a pin void gpio_peripheral(int bank, int pin, int func, int pullup) @@ -178,10 +192,9 @@ gpio_adc_setup(uint8_t pin) uint32_t prescal = DIV_ROUND_UP(CONFIG_CLOCK_FREQ*4, ADC_FREQ_MAX) - 1; uint32_t adcr = (1<<21) | ((prescal & 0xff) << 8); - if (!(LPC_SC->PCONP & (1<<12))) { + if (!(LPC_SC->PCONP & (1<<PCLK_ADC))) { // Power up ADC - LPC_SC->PCONP |= 1<<12; - LPC_SC->PCLKSEL0 = (LPC_SC->PCLKSEL0 & ~(0x3<<24)) | (0x1<<24); + enable_peripheral_clock(PCLK_ADC); LPC_ADC->ADCR = adcr; } |