Written by Ayrton Leyssens DMX library, bitbang method for LPC1768

Dependents:   ArtnetDMX

Committer:
Ayrton_L
Date:
Fri Mar 18 00:44:16 2016 +0000
Revision:
5:256845339155
Parent:
4:54754f9736f1
Child:
6:622a294f70ab
Art-Netupdate

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ayrton_L 0:55edcc97ba17 1 #include "DMX.h"
Ayrton_L 0:55edcc97ba17 2
Ayrton_L 0:55edcc97ba17 3 DMX::DMX(PinName pin) : _pin(pin)
Ayrton_L 0:55edcc97ba17 4 {
Ayrton_L 0:55edcc97ba17 5 this->I32_m_BreakTime = 88;
Ayrton_L 0:55edcc97ba17 6 this->I32_m_MABTime = 8;
Ayrton_L 0:55edcc97ba17 7 this->I32_m_StartCodeTime = 44;
Ayrton_L 0:55edcc97ba17 8 this->I32_m_BitTime = 4;
Ayrton_L 0:55edcc97ba17 9 this->I32_m_ChannelCounter = 0;
Ayrton_L 0:55edcc97ba17 10 this->I32_m_BitCounter = 0;
Ayrton_L 0:55edcc97ba17 11 uint32_t i;
Ayrton_L 0:55edcc97ba17 12 for(i = 0; i < 512; i++)
Ayrton_L 0:55edcc97ba17 13 {
Ayrton_L 2:5efe22304016 14 this->I8_m_Data[i] = 60;
Ayrton_L 0:55edcc97ba17 15 }
Ayrton_L 0:55edcc97ba17 16 this->_pin = 0;
Ayrton_L 0:55edcc97ba17 17 return;
Ayrton_L 0:55edcc97ba17 18 }
Ayrton_L 0:55edcc97ba17 19
Ayrton_L 0:55edcc97ba17 20 DMX::~DMX()
Ayrton_L 0:55edcc97ba17 21 {
Ayrton_L 0:55edcc97ba17 22 delete[] &I32_m_BreakTime;
Ayrton_L 0:55edcc97ba17 23 delete[] &I32_m_MABTime;
Ayrton_L 0:55edcc97ba17 24 delete[] &I32_m_StartCodeTime;
Ayrton_L 0:55edcc97ba17 25 delete[] &I32_m_BitTime;
Ayrton_L 0:55edcc97ba17 26 delete[] &_pin;
Ayrton_L 0:55edcc97ba17 27 delete[] &I8_m_Data;
Ayrton_L 0:55edcc97ba17 28 return;
Ayrton_L 0:55edcc97ba17 29 }
Ayrton_L 0:55edcc97ba17 30
Ayrton_L 0:55edcc97ba17 31 void DMX::V_SendDMX()
Ayrton_L 0:55edcc97ba17 32 {
Ayrton_L 0:55edcc97ba17 33 _pin = 0;
Ayrton_L 3:667d8f669992 34 wait_us(88);
Ayrton_L 3:667d8f669992 35 DMX::V_SendMAB();
Ayrton_L 0:55edcc97ba17 36 }
Ayrton_L 0:55edcc97ba17 37
Ayrton_L 0:55edcc97ba17 38 void DMX::V_SendMAB()
Ayrton_L 0:55edcc97ba17 39 {
Ayrton_L 0:55edcc97ba17 40 _pin = 1;
Ayrton_L 3:667d8f669992 41 wait_us(8);
Ayrton_L 3:667d8f669992 42 DMX::V_SendSC();
Ayrton_L 0:55edcc97ba17 43 }
Ayrton_L 0:55edcc97ba17 44
Ayrton_L 0:55edcc97ba17 45 void DMX::V_SendSC()
Ayrton_L 0:55edcc97ba17 46 {
Ayrton_L 0:55edcc97ba17 47 _pin = 0;
Ayrton_L 3:667d8f669992 48 wait_us(44);
Ayrton_L 3:667d8f669992 49 DMX::V_SendData();;
Ayrton_L 0:55edcc97ba17 50 }
Ayrton_L 0:55edcc97ba17 51
Ayrton_L 0:55edcc97ba17 52 void DMX::V_SendData()
Ayrton_L 0:55edcc97ba17 53 {
Ayrton_L 0:55edcc97ba17 54 if(I32_m_BitCounter == 0)
Ayrton_L 0:55edcc97ba17 55 {
Ayrton_L 0:55edcc97ba17 56 _pin = 0;
Ayrton_L 0:55edcc97ba17 57 I32_m_BitCounter++;
Ayrton_L 3:667d8f669992 58 wait_us(4);
Ayrton_L 3:667d8f669992 59 DMX::V_SendData();
Ayrton_L 0:55edcc97ba17 60 }
Ayrton_L 0:55edcc97ba17 61 else if(I32_m_BitCounter == 9 )
Ayrton_L 0:55edcc97ba17 62 {
Ayrton_L 0:55edcc97ba17 63 _pin = 1;
Ayrton_L 0:55edcc97ba17 64 I32_m_BitCounter = 0;
Ayrton_L 0:55edcc97ba17 65 I32_m_ChannelCounter++;
Ayrton_L 3:667d8f669992 66 wait_us(8);
Ayrton_L 3:667d8f669992 67 DMX::V_SendData();
Ayrton_L 0:55edcc97ba17 68 }
Ayrton_L 0:55edcc97ba17 69 else
Ayrton_L 0:55edcc97ba17 70 {
Ayrton_L 1:4eb21fcb621a 71 if(I32_m_ChannelCounter < 512)
Ayrton_L 0:55edcc97ba17 72 {
Ayrton_L 0:55edcc97ba17 73 if(I8_m_Data[I32_m_ChannelCounter] & 0x01 == 0x01)
Ayrton_L 0:55edcc97ba17 74 {
Ayrton_L 0:55edcc97ba17 75 _pin = 1;
Ayrton_L 0:55edcc97ba17 76 }
Ayrton_L 0:55edcc97ba17 77 else if(I8_m_Data[I32_m_ChannelCounter] & 0x01 == 0x00)
Ayrton_L 0:55edcc97ba17 78 {
Ayrton_L 0:55edcc97ba17 79 _pin =0;
Ayrton_L 0:55edcc97ba17 80 }
Ayrton_L 0:55edcc97ba17 81 I8_m_Data[I32_m_ChannelCounter] = I8_m_Data[I32_m_ChannelCounter] >> 1;
Ayrton_L 3:667d8f669992 82 I32_m_BitCounter++;
Ayrton_L 3:667d8f669992 83 wait_us(4);
Ayrton_L 3:667d8f669992 84 DMX::V_SendData();
Ayrton_L 0:55edcc97ba17 85 }
Ayrton_L 0:55edcc97ba17 86 else
Ayrton_L 0:55edcc97ba17 87 {
Ayrton_L 0:55edcc97ba17 88 I32_m_ChannelCounter = 0;
Ayrton_L 0:55edcc97ba17 89 I32_m_BitCounter = 0;
Ayrton_L 0:55edcc97ba17 90 }
Ayrton_L 3:667d8f669992 91
Ayrton_L 0:55edcc97ba17 92 }
Ayrton_L 0:55edcc97ba17 93 }
Ayrton_L 0:55edcc97ba17 94
Ayrton_L 0:55edcc97ba17 95 void DMX::V_SetBreak(uint32_t I32_BreakTime)
Ayrton_L 0:55edcc97ba17 96 {
Ayrton_L 0:55edcc97ba17 97 I32_m_BreakTime = I32_BreakTime;
Ayrton_L 0:55edcc97ba17 98 }
Ayrton_L 0:55edcc97ba17 99
Ayrton_L 0:55edcc97ba17 100 void DMX::V_SetMAB(uint32_t I32_MABTime)
Ayrton_L 0:55edcc97ba17 101 {
Ayrton_L 0:55edcc97ba17 102 I32_m_MABTime = I32_MABTime;
Ayrton_L 0:55edcc97ba17 103 }
Ayrton_L 0:55edcc97ba17 104
Ayrton_L 0:55edcc97ba17 105 void DMX::V_SetSC(uint32_t I32_StartCodeTime)
Ayrton_L 0:55edcc97ba17 106 {
Ayrton_L 0:55edcc97ba17 107 I32_m_StartCodeTime = I32_StartCodeTime;
Ayrton_L 0:55edcc97ba17 108 }
Ayrton_L 0:55edcc97ba17 109
Ayrton_L 0:55edcc97ba17 110 void DMX::V_SetBitTime(uint32_t I32_BitTime)
Ayrton_L 0:55edcc97ba17 111 {
Ayrton_L 0:55edcc97ba17 112 I32_m_BitTime = I32_BitTime;
Ayrton_L 0:55edcc97ba17 113 }
Ayrton_L 0:55edcc97ba17 114
Ayrton_L 0:55edcc97ba17 115 void DMX::V_SetData(uint8_t I8_Data[512])
Ayrton_L 0:55edcc97ba17 116 {
Ayrton_L 0:55edcc97ba17 117 uint32_t i;
Ayrton_L 0:55edcc97ba17 118 for(i = 0; i < 512; i++)
Ayrton_L 0:55edcc97ba17 119 {
Ayrton_L 0:55edcc97ba17 120 I8_m_Data[i] = I8_Data[i];
Ayrton_L 0:55edcc97ba17 121 }
Ayrton_L 0:55edcc97ba17 122 }