Landtiger LPC1768 C BigLib 1
A self made, custom C library for the LandTiger board.
 
Loading...
Searching...
No Matches
adc_pm.c
Go to the documentation of this file.
1#include "adc_pm.h"
2#include "power.h"
3#include "rit.h"
4
5#include <LPC17xx.h>
6
7// Since channels are not handled, types are not needed
8#define ADC_CH5 (1 << 5)
9#define ADC_GLOBAL_INTEN (1 << 8)
10
11_PRIVATE bool initialized = false;
12
13ADC_PMError ADC_PMInit(u8 options, u8 clock_divider, u8 int_priority)
14{
16
17 SET_BITS(LPC_PINCON->PINSEL3, 0x3, 30); // 11 -> ADC function for AD0.5
18 LPC_ADC->ADCR = (1 << 21) | (clock_divider << 8) | ADC_CH5; // Enable ADC, set clock divider, and set channel 5
19
20 LPC_ADC->ADINTEN = ADC_GLOBAL_INTEN;
21 NVIC_EnableIRQ(ADC_IRQn);
22
23 if (!IS_DEF_PRIORITY(int_priority) && IS_BETWEEN_EQ(int_priority, 0, 15))
24 NVIC_SetPriority(ADC_IRQn, int_priority);
25
26 if (options & ADC_PM_SAMPLE_WITH_RIT)
27 {
28 if (!RIT_IsEnabled())
29 return ADC_PM_RIT_UNINIT;
30
33 }
34
35 initialized = true;
36 return ADC_PM_ERR_OK;
37}
38
40{
41 return initialized;
42}
43
44void ADC_PMDeinit(void)
45{
47 RIT_RemoveJob(ADC_PMGetSample); // Won't do nothing if absent
48
49 NVIC_DisableIRQ(ADC_IRQn);
50 LPC_ADC->ADCR = 0;
51 LPC_ADC->ADINTEN = 0;
52 initialized = false;
53}
54
56{
57 SET_BIT(LPC_ADC->ADCR, 24); // Start conversion
58}
59
61{
62 CLR_BIT(LPC_ADC->ADCR, 24); // Stop conversion
63}
void ADC_PMSDisableSampling(void)
Definition adc_pm.c:60
void ADC_PMGetSample(void)
Retrieves a single sample from the PM, and triggers the interrupt.
Definition adc_pm.c:55
bool ADC_PMIsInitialized(void)
Definition adc_pm.c:39
#define ADC_CH5
Definition adc_pm.c:8
_PRIVATE bool initialized
Definition adc_pm.c:11
ADC_PMError ADC_PMInit(u8 options, u8 clock_divider, u8 int_priority)
Initializes the 12bit ADC peripheral, which on this board is wired to the Potentiometer (PM)....
Definition adc_pm.c:13
#define ADC_GLOBAL_INTEN
Definition adc_pm.c:9
void ADC_PMDeinit(void)
Definition adc_pm.c:44
ADC_PMError
Definition adc_pm_types.h:7
@ ADC_PM_ERR_OK
No error occurred.
Definition adc_pm_types.h:9
@ ADC_PM_RIT_UNINIT
The ADC was initialized with the SAMPLE_WITH_RIT option, but the RIT peripheral was not initialized.
@ ADC_PM_SAMPLE_WITH_RIT
void POWER_TurnOffPeripheral(u8 bit)
Turns off a peripheral.
Definition power.c:30
void POWER_TurnOnPeripheral(u8 bit)
Turns on a peripheral.
Definition power.c:25
@ POW_PCADC
Definition power_types.h:17
RIT_Error RIT_EnableJob(RIT_Job job)
Include this job in the RIT handler queue.
Definition rit_job.c:65
RIT_Error RIT_RemoveJob(RIT_Job job)
Removes a job from the RIT interrupt handler job queue.
Definition rit_job.c:117
RIT_Error RIT_AddJob(RIT_Job job, u8 multiplier_factor)
Definition rit_job.c:104
bool RIT_IsEnabled(void)
Returns whether the RIT is counting or not.
Definition rit.c:60
#define RIT_NO_DIVIDER
Tells the RIT that the specified job needs to be executed at exactly the interval of interrupts chose...
Definition rit_types.h:8
#define CLR_BIT(reg, bit)
Definition types.h:27
#define SET_BIT(reg, bit)
Definition types.h:26
#define IS_DEF_PRIORITY(prio)
Definition types.h:42
uint8_t u8
Definition types.h:8
#define _PRIVATE
Definition types.h:37
#define IS_BETWEEN_EQ(value, low, hi)
Definition types.h:23
#define SET_BITS(reg, value, bit)
Definition types.h:29