void (*adc_int_callback)(uint32_t) = NULL;
void ADC_Handler(void)
{
- volatile struct lpc_adc* adc = LPC_ADC;
+ volatile struct lpc_adc* adc = LPC_ADC_REGS;
uint32_t flags = adc->flags;
if (adc_int_callback != NULL) {
* This function reads the conversion value directly in the data register and
* always returns a value.
* Return 0 if the value is a new one and no overrun occured.
- * Return -1 if channel does not exist
+ * Return -EINVAL if channel does not exist
* Retuen 1 if the value is an old one
* Return 2 if an overrun occured
*/
int adc_get_value(uint16_t * val, uint8_t channel)
{
- struct lpc_adc* adc = LPC_ADC;
+ struct lpc_adc* adc = LPC_ADC_REGS;
uint32_t save_reg = 0;
if (channel >= NB_ADC_CHANNELS)
/* Start a conversion on the given channel (0 to 7) */
void adc_start_convertion_once(uint8_t channel, uint8_t seq_num, uint8_t use_int)
{
- struct lpc_adc* adc = LPC_ADC;
+ struct lpc_adc* adc = LPC_ADC_REGS;
uint32_t reg_val = 0;
if (channel >= NB_ADC_CHANNELS) {
}
/* Set conversion channel bit */
- reg_val = LPC_ADC_CHANNEL(channel);
+ reg_val = ADC_MCH(channel);
/* Use of interrupts for the specified channel ? */
if (use_int) {
/* Set interrupt Bit */
- adc->int_en = LPC_ADC_CHANNEL(channel);
+ adc->int_en = ADC_MCH(channel);
} else {
adc->int_en = 0;
}
/* Start burst conversions.
* channels is a bit mask of requested channels.
- * Use LPC_ADC_CHANNEL(x) (x = 0 .. 7) for channels selection.
+ * Use ADC_MCH(x) (x = 0 .. 7) for channels selection.
*/
void adc_start_burst_conversion(uint16_t channels, uint8_t seq_num)
{
- struct lpc_adc* adc = LPC_ADC;
+ struct lpc_adc* adc = LPC_ADC_REGS;
uint32_t reg_val = 0;
if (seq_num >= NB_ADC_SEQUENCES) {
}
/* Set conversion channel bits and burst mode */
- reg_val = (channels & LPC_ADC_CHANNEL_MASK);
+ reg_val = (channels & ADC_MCH_MASK);
reg_val |= LPC_ADC_BURST;
/* Do not use of interrupts in burst mode. */
}
void adc_stop_burst_conversion(uint8_t seq_num)
{
- struct lpc_adc* adc = LPC_ADC;
+ struct lpc_adc* adc = LPC_ADC_REGS;
if (seq_num >= NB_ADC_SEQUENCES) {
return;
}
void adc_prepare_conversion_on_event(uint16_t channels, uint8_t event, uint8_t seq_num,
uint8_t use_int, uint32_t mode)
{
- struct lpc_adc* adc = LPC_ADC;
+ struct lpc_adc* adc = LPC_ADC_REGS;
uint32_t reg_val = 0;
if (seq_num >= NB_ADC_SEQUENCES) {
}
/* Set conversion channel bits and burst mode */
- reg_val |= (channels & LPC_ADC_CHANNEL_MASK);
+ reg_val |= (channels & ADC_MCH_MASK);
/* Set conversion condition bits */
switch (event) {
case LPC_ADC_START_CONV_ADC_PINTRIG_0:
/* Software trigger of the given configured sequence */
void adc_trigger_sequence_conversion(uint8_t seq_num)
{
- struct lpc_adc* adc = LPC_ADC;
+ struct lpc_adc* adc = LPC_ADC_REGS;
if (seq_num >= NB_ADC_SEQUENCES) {
return;
*/
void adc_set_low_power(int lowpower_en)
{
- struct lpc_adc* adc = LPC_ADC;
+ struct lpc_adc* adc = LPC_ADC_REGS;
if (lowpower_en) {
adc->ctrl |= LPC_ADC_LOW_POWER_EN;
} else {
void adc_clk_update(void)
{
- struct lpc_adc* adc = LPC_ADC;
+ struct lpc_adc* adc = LPC_ADC_REGS;
uint32_t main_clock = get_main_clock();
uint32_t clkdiv = 0;
void adc_on(void (*adc_callback)(uint32_t))
{
struct lpc_sys_config* sys_config = LPC_SYS_CONFIG;
- struct lpc_adc* adc = LPC_ADC;
+ struct lpc_adc* adc = LPC_ADC_REGS;
/* Disable ADC Interrupts */
NVIC_DisableIRQ(ADC_SEQA_IRQ);
* This function reads the conversion value directly in the data register and
* always returns a value.
* Return 0 if the value is a new one and no overrun occured.
- * Return -1 if channel does not exist
+ * Return -EINVAL if channel does not exist
* Return 1 if the value is an old one.
* Return 2 if an overrun occured
*/
/* Start burst conversions.
* channels is a bit mask of requested channels.
- * Use LPC_ADC_CHANNEL(x) (x = 0 .. 11) for channels selection.
+ * Use ADC_MCH(x) (x = 0 .. 11) for channels selection.
*/
void adc_start_burst_conversion(uint16_t channels, uint8_t seq_num);
void adc_stop_burst_conversion(uint8_t seq_num);
volatile const uint32_t flags; /* 0x068 : A/D Flags Register (R/ ) */
volatile uint32_t trim; /* 0x06C : A/D Trim Register (R/W) */
};
-#define LPC_ADC ((struct lpc_adc *) LPC_ADC_BASE)
+#define LPC_ADC_REGS ((struct lpc_adc *) LPC_ADC_BASE)
/* ADC Control register bits */
#define LPC_ADC_CLK_MASK 0x0FF
#define LPC_ADC_LOW_POWER_EN (0x01 << 10)
#define LPC_ADC_CALIBRATION (0x01 << 30)
-/* LPC_ADC_CHANNEL_* are also used for interrupt register */
-#define LPC_ADC_CHANNEL_MASK (0xFFF << 0)
-#define LPC_ADC_CHANNEL(x) (0x01 << (x))
+/* ADC_MCH_* are also used for interrupt register */
+#define ADC_MCH_MASK (0xFFF << 0)
+#define ADC_MCH(x) (0x01 << (x))
#define LPC_ADC_START_CONV_EVENT(x) (((x) & 0x7) << 12)
#define LPC_ADC_START_EDGE_FALLING (0x0 << 18)
#define LPC_ADC_START_EDGE_RISING (0x1 << 18)
#define LPC_ADC_THRESHOLD_LEVEL_1 1
/* For more readability when selecting a channel number */
-#define LPC_ADC_NUM(x) (x)
+#define LPC_ADC(x) (x)