-
Notifications
You must be signed in to change notification settings - Fork 0
/
DmxDue.h
124 lines (94 loc) · 2.83 KB
/
DmxDue.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
/*
Copyright (c) 2014 Michel Vergeest. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define DMX1
//#define DMX2
//#define DMX3
//#define DMX4
#ifndef _DmxDue_
#define _DmxDue_
// Includes Atmel CMSIS
//#include <chip.h>
// Include Atmel CMSIS driver
#include <include/usart.h>
#include "HardwareSerial.h"
#define DMX_RX_MAX 512
#define DMX_TX_MAX 512
// State of receiving DMX Bytes
typedef enum {
IDLE, BREAK, DATA, RX_OFF
} dmxRxState_t;
typedef enum {
TX_DATA, TX_BREAK, TX_BREAK1, TX_BREAK2, TX_START, TX_DISABLE, TX_OFF
} dmxTxState_t;
//typedef void (*Fptr)();
extern "C" {
typedef void (*Fptr)();
}
class DmxDue {
protected:
uint8_t *_rx_buffer;
Usart *_pUsart;
IRQn_Type _dwIrq;
uint32_t _dwId;
private:
dmxRxState_t _rxState; // break condition detected.
uint16_t _rxCnt; // The next data byte is the start byte
uint16_t _rxLength;
// transmitter
dmxTxState_t _txState;
uint16_t _txCnt;
uint8_t *_tx_buffer;
Fptr _txReadyEvent;
Fptr _rxReadyEvent;
uint16_t _maxTxChannels;
void markAfterBreak();
public:
DmxDue(Usart* pUsart, IRQn_Type dwIrq, uint32_t dwId, uint8_t* pRx_buffer, uint8_t* pTx_buffer);
void begin();
void setInterruptPriority(uint32_t priority);
void IrqHandler(void);
uint8_t read(uint16_t channel);
uint16_t getRxLength();
//transmitter
void beginWrite();
void setBreakEvent(Fptr f);
// attach function that will be called when new data was received.
void setRxEvent(Fptr f);
// clear transmit buffer
void clrTxBuffer();
// write value to transmit buffer
void write(uint16_t channel , uint8_t value);
uint8_t getTx(uint16_t channel);
// set max transmit channels
void setTxMaxChannels(uint16_t maxChannels);
};
/*----------------------------------------------------------------------------
* Arduino objects - C++ only
*----------------------------------------------------------------------------*/
#ifdef __cplusplus
#ifdef DMX1
extern DmxDue DmxDue1;
#endif
#ifdef DMX2
extern DmxDue DmxDue2;
#endif
#ifdef DMX3
extern DmxDue DmxDue3;
#endif
#ifdef DMX4
extern DmxDue DmxDue4;
#endif
#endif
#endif // _DmxDue_