forked from zynthian/zyncoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzynrv112.h
109 lines (85 loc) · 2.99 KB
/
zynrv112.h
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* ******************************************************************
* ZYNTHIAN PROJECT: RV112 + ADS1115
*
* Library for reading RV112 infinite potentiometer using ADS1115.
*
* Copyright (C) 2015-2021 Fernando Moyano <jofemodo@zynthian.org>
*
* ******************************************************************
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program 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 General Public License for more details.
*
* For a full copy of the GNU General Public License see the LICENSE.txt file.
*
* ******************************************************************
*/
#ifndef ZYNRV112_H
#define ZYNRV112_H
#include <stdlib.h>
#include "zynads1115.h"
//-----------------------------------------------------------------------------
// ADS1115 data
//-----------------------------------------------------------------------------
#define ADS1115_VDD 3.3
#define MAX_NUM_ADS1115 2
//-----------------------------------------------------------------------------
// RV112 data
//-----------------------------------------------------------------------------
#define RV112_ADS1115_RANGE_100 (int)(0xFFFF*ADS1115_VDD/4.096)/2
#define RV112_ADS1115_RANGE_25 RV112_ADS1115_RANGE_100/4
#define RV112_ADS1115_RANGE_50 RV112_ADS1115_RANGE_100/2
#define RV112_ADS1115_RANGE_75 3*(RV112_ADS1115_RANGE_100/4)
//#define RV112_ADS1115_NOISE_DIV 32
#define RV112_ADS1115_NOISE_DIV 8
#define RV112_ADS1115_RAW_DIV 20
#define MAX_NUM_RV112 4
#define DVBUF_SIZE 10
#ifdef __cplusplus
extern "C" {
#endif
typedef struct rv112_st {
uint8_t enabled;
int32_t step;
int32_t value;
int8_t zpot_i;
// Next fields are RV112-specific
ads1115_t *ads1115_node;
uint16_t chA;
uint16_t chB;
int32_t valA;
int32_t valB;
uint8_t curseg;
int16_t lastdv;
int32_t valraw;
void *dvbuf;
int32_t dvavg;
} rv112_t;
//-----------------------------------------------------------------------------
// RV112's zynpot API
//-----------------------------------------------------------------------------
void init_rv112s();
void end_rv112s();
int get_num_rv112s();
int setup_rv112(uint8_t i, ads1115_t *ads1115, uint8_t reversed_chans);
int setup_behaviour_rv112(uint8_t i, int32_t step);
int32_t get_value_rv112(uint8_t i);
//-----------------------------------------------------------------------------
// RV112 specific functions
//-----------------------------------------------------------------------------
int16_t read_rv112(uint8_t i);
pthread_t init_poll_rv112();
//-----------------------------------------------------------------------------
#ifdef __cplusplus
}
#endif
//-----------------------------------------------------------------------------
#endif