Written by Ayrton Leyssens DMX library, bitbang method for LPC1768

Dependents:   ArtnetDMX

Committer:
Ayrton_L
Date:
Wed Mar 16 23:57:50 2016 +0000
Revision:
3:667d8f669992
Parent:
2:5efe22304016
Child:
4:54754f9736f1
No interrupt base; Slicht adjustments still needed for optimalisation;

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 3:667d8f669992 35 t.detach();
Ayrton_L 0:55edcc97ba17 36 _pin = 0;
Ayrton_L 3:667d8f669992 37 wait_us(88);
Ayrton_L 3:667d8f669992 38 DMX::V_SendMAB();
Ayrton_L 0:55edcc97ba17 39 }
Ayrton_L 0:55edcc97ba17 40
Ayrton_L 0:55edcc97ba17 41 void DMX::V_SendMAB()
Ayrton_L 0:55edcc97ba17 42 {
Ayrton_L 3:667d8f669992 43 t.detach();
Ayrton_L 0:55edcc97ba17 44 _pin = 1;
Ayrton_L 3:667d8f669992 45 wait_us(8);
Ayrton_L 3:667d8f669992 46 DMX::V_SendSC();
Ayrton_L 0:55edcc97ba17 47 }
Ayrton_L 0:55edcc97ba17 48
Ayrton_L 0:55edcc97ba17 49 void DMX::V_SendSC()
Ayrton_L 0:55edcc97ba17 50 {
Ayrton_L 3:667d8f669992 51 t.detach();
Ayrton_L 0:55edcc97ba17 52 _pin = 0;
Ayrton_L 3:667d8f669992 53 wait_us(44);
Ayrton_L 3:667d8f669992 54 DMX::V_SendData();;
Ayrton_L 0:55edcc97ba17 55 }
Ayrton_L 0:55edcc97ba17 56
Ayrton_L 0:55edcc97ba17 57 void DMX::V_SendData()
Ayrton_L 0:55edcc97ba17 58 {
Ayrton_L 3:667d8f669992 59 t.detach();
Ayrton_L 0:55edcc97ba17 60 if(I32_m_BitCounter == 0)
Ayrton_L 0:55edcc97ba17 61 {
Ayrton_L 0:55edcc97ba17 62 _pin = 0;
Ayrton_L 0:55edcc97ba17 63 I32_m_BitCounter++;
Ayrton_L 3:667d8f669992 64 wait_us(4);
Ayrton_L 3:667d8f669992 65 DMX::V_SendData();
Ayrton_L 0:55edcc97ba17 66 }
Ayrton_L 0:55edcc97ba17 67 else if(I32_m_BitCounter == 9 )
Ayrton_L 0:55edcc97ba17 68 {
Ayrton_L 0:55edcc97ba17 69 _pin = 1;
Ayrton_L 0:55edcc97ba17 70 I32_m_BitCounter = 0;
Ayrton_L 0:55edcc97ba17 71 I32_m_ChannelCounter++;
Ayrton_L 3:667d8f669992 72 wait_us(8);
Ayrton_L 3:667d8f669992 73 DMX::V_SendData();
Ayrton_L 0:55edcc97ba17 74 }
Ayrton_L 0:55edcc97ba17 75 else
Ayrton_L 0:55edcc97ba17 76 {
Ayrton_L 1:4eb21fcb621a 77 if(I32_m_ChannelCounter < 512)
Ayrton_L 0:55edcc97ba17 78 {
Ayrton_L 0:55edcc97ba17 79 if(I8_m_Data[I32_m_ChannelCounter] & 0x01 == 0x01)
Ayrton_L 0:55edcc97ba17 80 {
Ayrton_L 0:55edcc97ba17 81 _pin = 1;
Ayrton_L 0:55edcc97ba17 82 }
Ayrton_L 0:55edcc97ba17 83 else if(I8_m_Data[I32_m_ChannelCounter] & 0x01 == 0x00)
Ayrton_L 0:55edcc97ba17 84 {
Ayrton_L 0:55edcc97ba17 85 _pin =0;
Ayrton_L 0:55edcc97ba17 86 }
Ayrton_L 0:55edcc97ba17 87 I8_m_Data[I32_m_ChannelCounter] = I8_m_Data[I32_m_ChannelCounter] >> 1;
Ayrton_L 3:667d8f669992 88 I32_m_BitCounter++;
Ayrton_L 3:667d8f669992 89 wait_us(4);
Ayrton_L 3:667d8f669992 90 DMX::V_SendData();
Ayrton_L 0:55edcc97ba17 91 }
Ayrton_L 0:55edcc97ba17 92 else
Ayrton_L 0:55edcc97ba17 93 {
Ayrton_L 3:667d8f669992 94 led = 1;
Ayrton_L 0:55edcc97ba17 95 I32_m_ChannelCounter = 0;
Ayrton_L 0:55edcc97ba17 96 I32_m_BitCounter = 0;
Ayrton_L 0:55edcc97ba17 97 }
Ayrton_L 3:667d8f669992 98
Ayrton_L 0:55edcc97ba17 99 }
Ayrton_L 0:55edcc97ba17 100 }
Ayrton_L 0:55edcc97ba17 101
Ayrton_L 0:55edcc97ba17 102 void DMX::V_SetBreak(uint32_t I32_BreakTime)
Ayrton_L 0:55edcc97ba17 103 {
Ayrton_L 0:55edcc97ba17 104 I32_m_BreakTime = I32_BreakTime;
Ayrton_L 0:55edcc97ba17 105 }
Ayrton_L 0:55edcc97ba17 106
Ayrton_L 0:55edcc97ba17 107 void DMX::V_SetMAB(uint32_t I32_MABTime)
Ayrton_L 0:55edcc97ba17 108 {
Ayrton_L 0:55edcc97ba17 109 I32_m_MABTime = I32_MABTime;
Ayrton_L 0:55edcc97ba17 110 }
Ayrton_L 0:55edcc97ba17 111
Ayrton_L 0:55edcc97ba17 112 void DMX::V_SetSC(uint32_t I32_StartCodeTime)
Ayrton_L 0:55edcc97ba17 113 {
Ayrton_L 0:55edcc97ba17 114 I32_m_StartCodeTime = I32_StartCodeTime;
Ayrton_L 0:55edcc97ba17 115 }
Ayrton_L 0:55edcc97ba17 116
Ayrton_L 0:55edcc97ba17 117 void DMX::V_SetBitTime(uint32_t I32_BitTime)
Ayrton_L 0:55edcc97ba17 118 {
Ayrton_L 0:55edcc97ba17 119 I32_m_BitTime = I32_BitTime;
Ayrton_L 0:55edcc97ba17 120 }
Ayrton_L 0:55edcc97ba17 121
Ayrton_L 0:55edcc97ba17 122 void DMX::V_SetData(uint8_t I8_Data[512])
Ayrton_L 0:55edcc97ba17 123 {
Ayrton_L 0:55edcc97ba17 124 uint32_t i;
Ayrton_L 0:55edcc97ba17 125 for(i = 0; i < 512; i++)
Ayrton_L 0:55edcc97ba17 126 {
Ayrton_L 0:55edcc97ba17 127 I8_m_Data[i] = I8_Data[i];
Ayrton_L 0:55edcc97ba17 128 }
Ayrton_L 0:55edcc97ba17 129 }