Written by Ayrton Leyssens DMX library, bitbang method for LPC1768

Dependents:   ArtnetDMX

Committer:
Ayrton_L
Date:
Thu Mar 17 00:08:32 2016 +0000
Revision:
4:54754f9736f1
Parent:
3:667d8f669992
Child:
5:256845339155
Removed TimeOut

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