Landtiger LPC1768 C BigLib 1
A self made, custom C library for the LandTiger board.
 
Loading...
Searching...
No Matches
adc_pm.h File Reference
#include "adc_pm_types.h"
#include "types.h"
#include <stdbool.h>

Go to the source code of this file.

Functions

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). More specifically, the ADC peripheral is wired to the channel 5 of the ADC. Hence, the library does not handle other channels.
 
void ADC_PMDeinit (void)
 
bool ADC_PMIsInitialized (void)
 
void ADC_PMGetSample (void)
 Retrieves a single sample from the PM, and triggers the interrupt.
 
void ADC_PMSetSampleReadyAction (ADC_PMInterruptHandler action)
 Sets the action to be executed when the conversion is done.
 
void ADC_PMUnsetSampleReadyAction (void)
 

Function Documentation

◆ ADC_PMDeinit()

void ADC_PMDeinit ( void  )

Definition at line 44 of file adc_pm.c.

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}
void ADC_PMGetSample(void)
Retrieves a single sample from the PM, and triggers the interrupt.
Definition adc_pm.c:55
_PRIVATE bool initialized
Definition adc_pm.c:11
void POWER_TurnOffPeripheral(u8 bit)
Turns off a peripheral.
Definition power.c:30
@ POW_PCADC
Definition power_types.h:17
RIT_Error RIT_RemoveJob(RIT_Job job)
Removes a job from the RIT interrupt handler job queue.
Definition rit_job.c:117

◆ ADC_PMGetSample()

void ADC_PMGetSample ( void  )

Retrieves a single sample from the PM, and triggers the interrupt.

Note
This function does NOT repetitively sample the PM. It only retrieves a single sample. This is because we are not handling the BURST mode of the ADC. In order to keep retrieving samples, the function must be called repeatedly.
As of now, only the basic conversion (001) is implemented.

Definition at line 55 of file adc_pm.c.

56{
57 SET_BIT(LPC_ADC->ADCR, 24); // Start conversion
58}
#define SET_BIT(reg, bit)
Definition types.h:26

◆ ADC_PMInit()

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). More specifically, the ADC peripheral is wired to the channel 5 of the ADC. Hence, the library does not handle other channels.

Parameters
optionsADC PM options from the ADC_PMConfig enum
clock_dividerThe clock divider to be used by the ADC (division is performed by clock_divider+1)
int_priorityThe priority of the ADC interrupt. If the priority is set to INT_PRIO_DEF, the default priority will be used.

Definition at line 13 of file adc_pm.c.

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}
#define ADC_CH5
Definition adc_pm.c:8
#define ADC_GLOBAL_INTEN
Definition adc_pm.c:9
@ 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_TurnOnPeripheral(u8 bit)
Turns on a peripheral.
Definition power.c:25
RIT_Error RIT_EnableJob(RIT_Job job)
Include this job in the RIT handler queue.
Definition rit_job.c:65
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 IS_DEF_PRIORITY(prio)
Definition types.h:42
#define IS_BETWEEN_EQ(value, low, hi)
Definition types.h:23
#define SET_BITS(reg, value, bit)
Definition types.h:29

◆ ADC_PMIsInitialized()

bool ADC_PMIsInitialized ( void  )

Definition at line 39 of file adc_pm.c.

40{
41 return initialized;
42}

◆ ADC_PMSetSampleReadyAction()

void ADC_PMSetSampleReadyAction ( ADC_PMInterruptHandler  action)

Sets the action to be executed when the conversion is done.

Todo:
This function is not implemented void ADC_PMDisableSampling();
Parameters
actionThe action to be executed when the conversion is done.

Definition at line 13 of file adc_pm_irq.c.

14{
15 done_action = action;
16}
_PRIVATE ADC_PMInterruptHandler done_action
Holds the handler that is executed when the conversion is done.
Definition adc_pm_irq.c:6

◆ ADC_PMUnsetSampleReadyAction()

void ADC_PMUnsetSampleReadyAction ( void  )

Definition at line 18 of file adc_pm_irq.c.

19{
20 done_action = NULL;
21}