/
analog_input_pin.c
58 lines (49 loc) · 1.41 KB
/
analog_input_pin.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @file pin.c
* @version 7.0.0
*
* @section License
* Copyright (C) 2014-2016, Erik Moqvist
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* This file is part of the Simba project.
*/
#include "simba.h"
int analog_input_pin_module_init(void)
{
return (adc_module_init());
}
int analog_input_pin_init(struct analog_input_pin_t *self_p,
struct pin_device_t *pin_p)
{
return (adc_init(&self_p->adc,
&adc_device[0],
pin_p,
ADC_REFERENCE_VCC,
1));
}
int analog_input_pin_read(struct analog_input_pin_t *self_p)
{
uint16_t sample;
if (adc_convert(&self_p->adc, &sample, 1) == 0) {
return (sample);
}
return (-1);
}
int analog_input_pin_read_isr(struct analog_input_pin_t *self_p)
{
uint16_t sample;
if (adc_convert_isr(&self_p->adc, &sample) == 0) {
return (sample);
}
return (-1);
}