-
Notifications
You must be signed in to change notification settings - Fork 8
/
helper.h
200 lines (164 loc) · 4.13 KB
/
helper.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
* Arduino.h
*
* Created on: 25 f�vr. 2017
* Author: Vincent
*/
#ifndef LIBRARIES_ARDUINO_H_
#define LIBRARIES_ARDUINO_H_
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "nrf_drv_spi.h"
#include "nrf_drv_gpiote.h"
#include "nrf.h"
#include "nrf_delay.h"
#define boolean uint8_t
#define byte uint8_t
#define OUTPUT 0
#define INPUT 1
#define INPUT_PULLUP 2
#define INPUT_PULLDOWN 3
#define LOW 0
#define HIGH 1
#define _BV(bit) (1 << (bit))
////////// STRUCTURES
////////// FUNCTIONS
#ifdef __cplusplus
extern "C" {
#endif
/**
*
*/
void pwr_mgmt_run(void);
/**
*
*/
void init_timers_millis();
/**
* Delay of X milliseconds. Blocking function
* @param p_time Number of ms to wait for
*/
void delay(uint32_t p_time);
/** @brief configures a pin either as an input (see p_mode) or as an output (OUTPUT)
*
* @param p_pin Pin number.
* @param p_mode Either INPUT (NRF_GPIO_PIN_NOPULL), INPUT_PULLDOWN (NRF_GPIO_PIN_PULLDOWN), NRF_GPIO_PIN_PULLUP (NRF_GPIO_PIN_PULLUP)
*/
void pinMode(uint8_t p_pin, uint8_t p_mode);
/**
* @brief Reads a digital pin
* @param p_pin Pin number
* @return
*/
uint32_t digitalRead(uint8_t p_pin);
/** @brief Sets an output pin value
*
* @param p_pin Pin number
* @param p_mode Mode: either LOW or HIGH
*/
void digitalWrite(uint8_t p_pin, uint8_t p_mode);
/**
* @brief Attaches an interrupt to a pin.
*
* Polarity is NRF_GPIOTE_POLARITY_HITOLO and pin is configured with NRF_GPIO_PIN_PULLUP
*
* @param pin_ Pin number
* @param evt_handler Event function to be called on the interupt
*/
void attachInterrupt(nrf_drv_gpiote_pin_t pin_, nrf_drv_gpiote_evt_handler_t evt_handler);
/**
* Removes the interrupt from a pin
* @param pin_
*/
void detachInterrupt(nrf_drv_gpiote_pin_t pin_);
/**
* @brief Computes the 2 complement of a uint16_t value split in two uint8_t values
* @param msb MSB of the variable
* @param lsb LSB of the variable
* @return
*/
float compute2Complement16_t(uint8_t msb, uint8_t lsb);
/**
* @brief Computes the 2 complement of a uint24_t value split in three uint8_t values
* @param msb MSB of the variable
* @param csb Central byte of the variable
* @param lsb LSB of the variable
* @return
*/
float compute2Complement24_t(uint8_t msb, uint8_t csb, uint8_t lsb);
/** @brief Tests if a char is a digit (ie belongs to '0' to '9')
*
* @param c The input char to test
* @return True if it is, false otherwise
*/
bool is_digit(char c);
/** @brief Parses a char that describes part of a hex. to a decimal value
* exemple: 'F' will be parsed as 15
*
* @param a The input char
* @return An int containing the parsed value
*/
int from_hex(char a);
/** @brief Linear interpolation function
*
* Interpolates a value x1 from one interval B1 to another interval B2:
* b1_i-------------x1----b1_f
* becomes
* b2_i-------------x2----b2_f
* If x1 is out of B1, x2 will be out of B2
*
* @param val_ Value to interpolate
* @param b1_i Initial interval start
* @param b1_f Initial interval end
* @param b2_i Initial interval start
* @param b2_f Initial interval end
* @return x2
*/
float regFen(float val_, float b1_i, float b1_f, float b2_i, float b2_f);
/** @brief Linear interpolation function
*
* Interpolates a value x1 from one interval B1 to another interval B2:
* b1_i-------------x1----b1_f
* becomes
* b2_i-------------x2----b2_f
* The value of x2 i limited to B2:
* If x1 is out of B1, x2 will be at the limit of B2
*
* @param val_ Value to interpolate
* @param b1_i Initial interval start
* @param b1_f Initial interval end
* @param b2_i Initial interval start
* @param b2_f Initial interval end
* @return x2
*/
float regFenLim(float val_, float b1_i, float b1_f, float b2_i, float b2_f);
/**
*
* @param dest
* @param input
*/
void encode_uint16 (uint8_t* dest, uint16_t input);
/**
*
* @param dest
* @param input
*/
void encode_uint32 (uint8_t* dest, uint32_t input);
/**
*
* @param dest
* @return
*/
uint16_t decode_uint16 (uint8_t* dest);
/**
*
* @param dest
* @return
*/
uint32_t decode_uint32 (uint8_t* dest);
#ifdef __cplusplus
}
#endif
#endif /* LIBRARIES_ARDUINO_H_ */