flinklib
flinklib: flink C library for Linux
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ain.c
Go to the documentation of this file.
1 /*******************************************************************
2  * _________ _____ _____ ____ _____ ___ ____ *
3  * |_ ___ | |_ _| |_ _| |_ \|_ _| |_ ||_ _| *
4  * | |_ \_| | | | | | \ | | | |_/ / *
5  * | _| | | _ | | | |\ \| | | __'. *
6  * _| |_ _| |__/ | _| |_ _| |_\ |_ _| | \ \_ *
7  * |_____| |________| |_____| |_____|\____| |____||____| *
8  * *
9  *******************************************************************
10  * *
11  * flink userspace library, subdevice function "analog input" *
12  * *
13  *******************************************************************/
14 
24 #include "flinklib.h"
25 #include "types.h"
26 #include "error.h"
27 #include "log.h"
28 
29 #include <stdint.h>
30 
37 int flink_analog_in_get_resolution(flink_subdev* subdev, uint32_t* resolution){
38  uint32_t offset;
39  offset = HEADER_SIZE + SUBHEADER_SIZE;
40 
41  if(flink_read(subdev, offset, REGISTER_WITH, resolution) != REGISTER_WITH) {
42  libc_error();
43  return EXIT_ERROR;
44  }
45  return EXIT_SUCCESS;
46 }
47 
55 int flink_analog_in_get_value(flink_subdev* subdev, uint32_t channel, uint32_t* value){
56  uint32_t offset;
57 
58  dbg_print("Get Value of analog in for channel %d on subdevice %d\n", subdev->id, channel);
60  dbg_print(" --> calculated offset is 0x%x!\n", offset);
61 
62  if(flink_read(subdev, offset, REGISTER_WITH, value) != REGISTER_WITH) {
63  libc_error();
64  return EXIT_ERROR;
65  }
66  return EXIT_SUCCESS;
67 }
Data structures for flink devices and subdevices.
#define ANALOG_INPUT_FIRST_VALUE_OFFSET
Definition: flinklib.h:56
int flink_analog_in_get_value(flink_subdev *subdev, uint32_t channel, uint32_t *value)
Reads an analog input channel.
Definition: ain.c:55
#define EXIT_ERROR
Definition: flinklib.h:118
ssize_t flink_read(flink_subdev *subdev, uint32_t offset, uint8_t size, void *rdata)
Read from a flink subdevice.
Definition: lowlevel.c:71
Error handling.
#define REGISTER_WITH
Definition: flinklib.h:48
#define HEADER_SIZE
Definition: flinklib.h:49
#define EXIT_SUCCESS
Definition: flinklib.h:117
int flink_analog_in_get_resolution(flink_subdev *subdev, uint32_t *resolution)
Reads the resolution of a analog input subdevice.
Definition: ain.c:37
#define SUBHEADER_SIZE
Definition: flinklib.h:50
void libc_error(void)
Definition: error.c:56
Debug utilities.
#define dbg_print(fmt,...)
Definition: log.h:29