moberg_channel.h 1.76 KB
Newer Older
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
59
60
61
62
63
64
65
66
67
#ifndef __MOBERG_CHANNEL_H__
#define __MOBERG_CHANNEL_H__

#include <moberg.h>

enum moberg_channel_kind {
    chan_ANALOGIN,
    chan_ANALOGOUT,
    chan_DIGITALIN,
    chan_DIGITALOUT,
    chan_ENCODERIN
};

struct moberg_channel {
  struct moberg_channel_context *context;
  
  /* Use-count of channel, when it reaches zero, channel will be free'd */
  int (*up)(struct moberg_channel *channel);
  int (*down)(struct moberg_channel *channel);

  /* Channel open and close */
  int (*open)(struct moberg_channel *channel);
  int (*close)(struct moberg_channel *channel);

  /* I/O operations */
  enum moberg_channel_kind kind;
  union moberg_channel_action {
    struct {
      struct moberg_channel_analog_in *context;
      int (*read)(struct moberg_channel_analog_in *, double *value);
    } analog_in;
    struct  {
      struct moberg_channel_analog_out *context;
      int (*write)(struct moberg_channel_context *, double value);
    } analog_out;
    struct {
      struct moberg_channel_digital_in *context;
      int (*read)(struct moberg_channel_context *, int *value);
    } digital_in;
    struct  {
      struct moberg_channel_digital_out *context;
      int (*write)(struct moberg_channel_context *, int value);
    } digital_out;
    struct {
      struct moberg_channel_encoder_in *context;
      int (*read)(struct moberg_channel_context *, long *value);
    } encoder_in;
  } action;
};
  
struct moberg_channel_map {
  struct moberg_device *device;
  int (*map)(struct moberg_device* device,
             struct moberg_channel *channel);
};

struct moberg_channel_install {
  struct moberg *context;
  int (*channel)(struct moberg *context,
                 int index,
                 struct moberg_device* device,
                 struct moberg_channel *channel);
};



#endif