DMX512, RDM send/recv library http://mbed.org/users/okini3939/notebook/dmx512

Dependents:   dmx_test ArtNodeLED SPK-DVIMXR SPK-DMXer ... more

DMX512 send/recv library

DMX512 is protocol for lighting.

調光プロトコル DMX512 を送受信するライブラリです。

see: http://mbed.org/users/okini3939/notebook/dmx512/

LPC1114 support is thanks to Stanly Chen

Files at this revision

API Documentation at this revision

Comitter:
okini3939
Date:
Fri Jan 04 04:31:53 2013 +0000
Parent:
4:dd0544c80096
Child:
6:9e7b4eeac6ec
Commit message:
support LPC11U24

Changed in this revision

DMX.cpp Show annotated file Show diff for this revision Revisions of this file
DMX.h Show annotated file Show diff for this revision Revisions of this file
--- a/DMX.cpp	Wed Nov 21 01:44:21 2012 +0000
+++ b/DMX.cpp	Fri Jan 04 04:31:53 2013 +0000
@@ -4,14 +4,14 @@
  * Released under the MIT License: http://mbed.org/license/mit
  */
 
-/** @file DMX.cpp
+/** @file dmx.cpp
  * @brief DMX512 send/recv
  */
 
 #include "mbed.h"
 #include "DMX.h"
 
-DMX::DMX (PinName p_tx, PinName p_rx) : dmx(p_tx, p_rx) {
+DMX::DMX (PinName p_tx, PinName p_rx) : _dmx(p_tx, p_rx) {
     int i;
 
     for (i = 0; i < DMX_SIZE; i ++) {
@@ -24,6 +24,7 @@
     is_recived = 0;
     is_sent = 0;
 
+#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
     if (p_tx == p9) {
       uart_lcr = &LPC_UART3->LCR;
       uart_thr = &LPC_UART3->THR;
@@ -51,10 +52,21 @@
       uart_rbr = &LPC_UART2->RBR;
       NVIC_SetPriority(UART2_IRQn, 1);
     }
+#elif defined(TARGET_LPC11U24)
+    if (p_tx == p9) {
+      uart_lcr = &LPC_USART->LCR;
+      uart_thr = &LPC_USART->THR;
+    }
+    if (p_rx == p10) {
+      uart_lsr = &LPC_USART->LSR;
+      uart_rbr = &LPC_USART->RBR;
+      NVIC_SetPriority(UART_IRQn, 1);
+    }
+#endif
 
-    dmx.baud(250000);
-    dmx.format(8, Serial::None, 2);
-    dmx.attach(this, &DMX::int_rx, Serial::RxIrq);
+    _dmx.baud(250000);
+    _dmx.format(8, Serial::None, 2);
+    _dmx.attach(this, &DMX::int_rx, Serial::RxIrq);
 
 //    timeout01.attach_us(this, &DMX::int_timer, DMX_TIME_BETWEEN);
 }
@@ -91,11 +103,11 @@
         timeout01.detach();
         addr_tx = 0;
         mode_tx = DMX_MODE_DATA;
-        dmx.attach(this, &DMX::int_tx, Serial::TxIrq);
+        _dmx.attach(this, &DMX::int_tx, Serial::TxIrq);
 #ifdef DMX_UART_DIRECT
         *uart_thr = 0;
 #else
-        dmx.putc(0);
+        _dmx.putc(0);
 #endif
         break;
     }
@@ -108,11 +120,11 @@
 #ifdef DMX_UART_DIRECT
             *uart_thr = (uint8_t)data_tx[addr_tx];
 #else
-            dmx.putc(data_tx[addr_tx]);
+            _dmx.putc(data_tx[addr_tx]);
 #endif
             addr_tx ++;
         } else {
-            dmx.attach(0, Serial::TxIrq);
+            _dmx.attach(0, Serial::TxIrq);
             mode_tx = DMX_MODE_BEGIN;
             is_sent = 1;
             timeout01.attach_us(this, &DMX::int_timer, DMX_TIME_BETWEEN);
@@ -127,7 +139,7 @@
 #ifdef DMX_UART_DIRECT
     dat = *uart_rbr;
 #else
-    dat = dmx.getc();
+    dat = _dmx.getc();
 #endif
 
     if (flg & ((1 << 7)|(1 << 3)|(1 << 4))) {
@@ -172,7 +184,7 @@
 }
 
 void DMX::stop () {
-    dmx.attach(0, Serial::TxIrq);
+    _dmx.attach(0, Serial::TxIrq);
     timeout01.detach();
     mode_tx = DMX_MODE_STOP;
 }
--- a/DMX.h	Wed Nov 21 01:44:21 2012 +0000
+++ b/DMX.h	Fri Jan 04 04:31:53 2013 +0000
@@ -67,12 +67,19 @@
     void int_tx ();
     void int_rx ();
 
-    Serial dmx;
+    Serial _dmx;
     Timeout timeout01;
+#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
     __IO uint8_t *uart_lcr;
     __I  uint8_t *uart_lsr;
     __IO uint8_t *uart_thr;
     __I  uint8_t *uart_rbr;
+#elif defined(TARGET_LPC11U24)
+    __IO uint32_t *uart_lcr;
+    __I  uint32_t *uart_lsr;
+    __IO uint32_t *uart_thr;
+    __I  uint32_t *uart_rbr;
+#endif
     volatile DMX_MODE mode_tx, mode_rx;
     volatile int addr_tx, addr_rx;
     unsigned char data_tx[DMX_SIZE];