-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtoolbox_settings.h
364 lines (333 loc) · 11.4 KB
/
toolbox_settings.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/**
* @file toolbox_settings.h
* @brief This file contains macros to be configured by users.
* @author Jaime Bronozo
*
* This is a header file used by all libraries as a configuration hub to
* allow library modification to be compressed into a single file.
* Library specific settings can be found here such as pinouts and
* function availability.
* Libraries can be included or excluded by
* commenting/uncommenting their respective disable macro.
*
* @date November 1, 2018
**************************************************************************/
/// @cond
#ifndef __TOOLBOX_SETTINGS_COMMON_H__
#define __TOOLBOX_SETTINGS_COMMON_H__
/// @endcond
/**
* @def FCY
*
* @brief Defines the instruction cycle frequency
*
* This macro is used for various functions across the library as a
* standard unit of measurement for the number of instruction cycles per
* second. This allows the usage of functions inside the library
* **libpic30.h** as well as various other library functions such as the
* delay functions.
*
* Set this value in unit of Hertz (Fosc/2 for PIC24F devices).
**************************************************************************/
#ifndef FCY
#define FCY 16000000
#endif
/// @cond
#include "xc.h"
#include "libpic30.h"
/// @endcond
/**
* @def delay_s(d)
* @param d Time in unit seconds.
*
* @brief Stalls execution of instructions in seconds.
*
* Functions as a definite time delay function wrapped around the
* **__delay32()** function. This converts the number seconds to stall to
* its equivalent cycle count.
*
* @note This function is dependent on the proper setting of Fcy
*
* @def delay_ms(d)
* @param d Time in unit milliseconds.
*
* @brief Stalls execution of instructions in milliseconds.
*
* Functions as a definite time delay function wrapped around the
* **__delay32()** function. This converts the number milliseconds to stall
* to its equivalent cycle count.
*
* @note This function is dependent on the proper setting of Fcy.
*
* @def delay_us(d)
* @param d Time in unit microseconds.
*
* @brief Stalls execution of instructions in microseconds/
*
* Functions as a definite time delay function wrapped around the
* **__delay32()** function. This converts the number microseconds to stall
* to its equivalent cycle count.
*
* @note This function is dependent on the proper setting of Fcy.
**************************************************************************/
#define delay_s(d) __delay32( (unsigned long) ((((unsigned long long) d)*(FCY))-2))
#define delay_ms(d) __delay32( (unsigned long) ((((unsigned long long) d)*(FCY)/1000ULL)-2))
#define delay_us(d) __delay32( (unsigned long) ((((unsigned long long) d)*(FCY)/1000000ULL)-2))
/**
* @def __PIN_ACCESS(x, y)
* @param x Term to be concatenated on by *y*.
* @param y Term to be concatenated to *x*.
*
* @brief Macro for concatenating pin value to function register.
*
* This function is a macro used to expand pin value settings to their
* respective prefix to access the respective special function registers
* associated with it.
*
* @note This is internally used by other macros and must not be used for
* other purposes.
*
* @def __PORTx(x)
* @param x Pin assigment macro to be used for digital reading.
*
* @brief Allows reading from a labeled pin macro.
*
* This macro appends the term *_PORT* to the pin value associated with
* the macro to form the _PORTx# term that refers to the specific pin
* for reading.
*
* @def __LATx(x)
* @param x Pin assignemnt macro to be used for digital writing.
*
* @brief Allows writing from a labeled pin macro.
*
* This macro appends the term *_LAT* to the pin value associated with
* the macro to form the _LATx# term that refers to the specific pin
* for writing.
*
* @def __TRISx(x)
* @param x Pin assignemnt macro to be used for pin direction
*
* @brief Allows pin direction assignemtn from a labelled pin macro.
*
* This macro appends the term *_TRIS* to the pin value associated with
* the macro to form the _TRISx# term that refers to the specific pin
* for I/O direction assignment.
**************************************************************************/
#define __PIN_ACCESS(x,y) x##y
#define __PORTx(x) __PIN_ACCESS(_R, x)
#define __LATx(x) __PIN_ACCESS(_LAT, x)
#define __TRISx(x) __PIN_ACCESS(_TRIS, x)
/**
* @def pinMode(x, y)
* @param x Pin value.
* @param y Pin data direction.
*
* @brief Macro for setting pin data direction.
*
* This function is a macro for setting the pin data direction. This works
* similarly to the Arduino library function of the same name. However,
* this requires the specification of the whole pin name instead of an
* arbitrary number to represent every pin.
*
* @def digitalWrite(x, y)
* @param x Pin value.
* @param y Pin output value.
*
* @brief Macro for setting pin output value.
*
* This function is a macro for setting the pin output value. This works
* similarly to the Arduino library function of the same name. However,
* this requires the specification of the whole pin name instead of an
* arbitrary number to represent every pin.
*
* @def digitalRead(x)
* @param x Pin value.
*
* @brief Macro for reading pin input value.
*
* This function is a macro for reading the pin input value. This works
* similarly to the Arduino library function of the same name. However,
* this requires the specification of the whole pin name instead of an
* arbitrary number to represent every pin.
**************************************************************************/
#define pinMode(x, y) __PIN_ACCESS(_TRIS, x) = (y)
#define digitalWrite(x, y) __PIN_ACCESS(_LAT, x) = (y)
#define digitalRead(x) __PIN_ACCESS(_R, x)
#define __I2C_ACCESS(x, y) I2C##x##y
#define __I2C_STAT(x) __I2C_ACCESS(x, STATbits)
#define __I2C_CON(x) __I2C_ACCESS(x, CONbits)
#define __I2C_BRG(x) __I2C_ACCESS(x, BRG)
#define __I2C_TRN(x) __I2C_ACCESS(x, TRN)
#define __I2C_RCV(x) __I2C_ACCESS(x, RCV)
/**
* @def __LIBLCD_DISABLED
*
* @brief Set to 1 to disable the lcd library
*
* Enables or disables the lcd library. Disabling using this option will
* automatically exclude compilation of lcd_generic.c and remove
* lcd_generic.h from inclusion in the main header PIC24_toolbox.h
**************************************************************************/
#define __LIBLCD_DISABLED 0
/**
* @page lcdlib Configuring the Generic LCD Library
* @tableofcontents
*
* This page describes the available settings to modify in the code
* section of the LCD library found in toolbox_settings.h.
*
* @section lcdpin Pin Configurations
*
* For proper 4-bit mode operation, the respective macros _DB4, _DB5,
* _DB6, and _DB7 must be set with the correct pin labels as well as the
* _RS and _E pins to allow register select and data entering. Proper
* configuration of this macros will make the library work after a call
* to lcd_begin().
*
* ```C
* #define _DB4 B0
* #define _DB5 B1
* ...
* #define _RS B4
* #define _E B5
* ```
*
* To not conflict with other macros that the user may define, all the
* lcd setting macros have been enclosed inside a conditional definition
* that only the lcd implementation files have access to.
*
* @section lcdoff Disabling the LCD library
*
* To exclude the library when not in use with the current project, set
* the macro __LIBLCD_DISABLED to 1 to exclude the library from
* compilation when not needed for your application
*
* ```C
* // #define __LIBLCD_DISABLED 0
* #define __LIBLCD_DISABLED 1
* ```
*
* @section lcdlim Limitations
*
* The LCD library is a work in progress and may not be functionally
* complete. For one, there are no functions for reading back the memory
* of the LCD as well as defining custom characters. Most of the functions,
* however, have been wrapped in easy to use functions that abstract lcd
* operations. This is also dependent on the proper definition of the macro
* Fcy for the delay functions used to wait for the lcd to be available
* for receiving commands.
**************************************************************************/
#ifdef __LIBLCD_SETTINGS
#define __LIBLCD_READ_EN 0
#define _DB4 B0
#define _DB5 B1
#define _DB6 B2
#define _DB7 B3
#define _RS B4
#define _E B5
#define _RW B7
#endif
/**
* @def __LIBKEYPAD_4x3_DISABLE
*
* @brief Set to 1 to disable the keypad library
*
* Enables or disables the keypad library. Disabling using this option
* will automatically exclude compilation of keypad_4x3.c and remove
* keypad_4x3.h from inclusion in the main header PIC24_toolbox.h
**************************************************************************/
#define __LIBKEYPAD_4x3_DISABLE 0
/**
* @page keypadlib Configuring the 4x3 Number Pad
* @tableofcontents
*
* This page describes the available settings to modify in the code section
*
* of the 4x3 Number Pad found in toolbox_settings.h.
*
* @section keypadpin Pin Configurations
*
* For proper library mapping, the respective macros _COL1, _COL2, _COL3,
* and _COL4 must be set to the proper pins connected to the column of the
* matrix while the macros _ROW1, _ROW2, _ROW3, and _ROW4 must be set to
* the proper pins connected to the rows of the matrix
*
* ```C
* #define _COL1 B7
* #define _COL2 B8
* ...
* #define _ROW3 B3
* #define _ROW4 B4
* ```
*
* The respective macros _CN_ROW1, _CN_ROW2, _CN_ROW3, and _CN_ROW4 must be
* set to the proper change notification pin number corresponding to the
* pin. This will ensure that the keypad will be instantaneously updated
* whenever a button is pressed or released.
*
* ```C
* #define _CN_ROW1 3
* #define _CN_ROW2 30
* #define _CN_ROW3 29
* #define _CN_ROW4 0
* ```
*
* @section keypadoff Disabling the Keypad library
*
* To exclude the library when not in use with the current project, set the
* macro __LIBKEYPAD_4x3_DISABLED to 1 to exclude the library from
* compilation when not needed for your application
*
* ```C
* // #define __LIBKEYPAD_4x3_DISABLED 0
* #define __LIBKEYPAD_4x3_DISABLED 1
* ```
*
* @section keypadlim Limitations
*
* This library has not been tested rigorously for errors. Bugs can be
* reported on [Github](https://github.com/bronozoj/PIC24_toolbox).
**************************************************************************/
#ifdef __LIBKEYPAD_4x3_SETTINGS
/**
* @def __LIBKEYPAD_4x3_CNISR
*
* @brief Set to 1 to auto-manage the change notification interrupt
*
* Enables or disables the automatic management of the change notification
* interrupt. If not used, the library can be configured to use the
* change notification interrupt by itself. If, however, other functions
* functions must integrate with it, the interrupt priority and enable
* must be manually set and the function keypad_update() be called inside
* the _CNInterrupt() function at least once.
**************************************************************************/
#define __LIBKEYPAD_4x3_CNISR 1
#define __CN_ACCESS(x,y) _CN##y##x
#define __CN_PUE(x) __CN_ACCESS(PUE, x)
#define __CN_IE(x) __CN_ACCESS(IE, x)
#define _COL1 B7
#define _COL2 B11
#define _COL3 B13
#define _ROW1 A1
#define _ROW2 A2
#define _ROW3 A3
#define _ROW4 A4
#define _CN_ROW1 3
#define _CN_ROW2 30
#define _CN_ROW3 29
#define _CN_ROW4 0
#endif
#endif
#define __LIBADCREAD_DISABLE 0
#ifdef __LIBADCREAD_SETTINGS
#define _SAMPLE_PERIOD 2
#define _ADC_PERIOD 1
#endif
#define __LIBEEPROM_I2C_DISABLE 0
#ifdef __LIBEEPROM_I2C_SETTINGS
#define _CLOCK_RATE 200//157
#define _I2C_NUM 1
#define _I2C_SDA B9
#define _I2C_SCL B8
#endif